88import pytest
99
1010from pandas ._libs import iNaT
11+ import pandas .util ._test_decorators as td
1112
1213from pandas .core .dtypes .common import is_integer
1314
@@ -534,6 +535,7 @@ def test_getitem_setitem_integer_slice_keyerrors(self):
534535 with pytest .raises (KeyError , match = r"^3$" ):
535536 df2 .loc [3 :11 ] = 0
536537
538+ @td .skip_array_manager_invalid_test # already covered in test_iloc_col_slice_view
537539 def test_fancy_getitem_slice_mixed (self , float_frame , float_string_frame ):
538540 sliced = float_string_frame .iloc [:, - 3 :]
539541 assert sliced ["D" ].dtype == np .float64
@@ -592,6 +594,7 @@ def test_getitem_fancy_scalar(self, float_frame):
592594 for idx in f .index [::5 ]:
593595 assert ix [idx , col ] == ts [idx ]
594596
597+ @td .skip_array_manager_invalid_test # TODO(ArrayManager) rewrite not using .values
595598 def test_setitem_fancy_scalar (self , float_frame ):
596599 f = float_frame
597600 expected = float_frame .copy ()
@@ -631,6 +634,7 @@ def test_getitem_fancy_boolean(self, float_frame):
631634 expected = f .reindex (index = f .index [boolvec ], columns = ["C" , "D" ])
632635 tm .assert_frame_equal (result , expected )
633636
637+ @td .skip_array_manager_invalid_test # TODO(ArrayManager) rewrite not using .values
634638 def test_setitem_fancy_boolean (self , float_frame ):
635639 # from 2d, set with booleans
636640 frame = float_frame .copy ()
@@ -990,21 +994,29 @@ def test_iloc_row(self):
990994 expected = df .loc [8 :14 ]
991995 tm .assert_frame_equal (result , expected )
992996
997+ # list of integers
998+ result = df .iloc [[1 , 2 , 4 , 6 ]]
999+ expected = df .reindex (df .index [[1 , 2 , 4 , 6 ]])
1000+ tm .assert_frame_equal (result , expected )
1001+
1002+ def test_iloc_row_slice_view (self , using_array_manager ):
1003+ df = DataFrame (np .random .randn (10 , 4 ), index = range (0 , 20 , 2 ))
1004+ original = df .copy ()
1005+
9931006 # verify slice is view
9941007 # setting it makes it raise/warn
1008+ subset = df .iloc [slice (4 , 8 )]
1009+
9951010 msg = r"\nA value is trying to be set on a copy of a slice from a DataFrame"
9961011 with pytest .raises (com .SettingWithCopyError , match = msg ):
997- result [2 ] = 0.0
1012+ subset [2 ] = 0.0
9981013
999- exp_col = df [2 ].copy ()
1000- exp_col [4 :8 ] = 0.0
1014+ exp_col = original [2 ].copy ()
1015+ # TODO(ArrayManager) verify it is expected that the original didn't change
1016+ if not using_array_manager :
1017+ exp_col [4 :8 ] = 0.0
10011018 tm .assert_series_equal (df [2 ], exp_col )
10021019
1003- # list of integers
1004- result = df .iloc [[1 , 2 , 4 , 6 ]]
1005- expected = df .reindex (df .index [[1 , 2 , 4 , 6 ]])
1006- tm .assert_frame_equal (result , expected )
1007-
10081020 def test_iloc_col (self ):
10091021
10101022 df = DataFrame (np .random .randn (4 , 10 ), columns = range (0 , 20 , 2 ))
@@ -1022,19 +1034,32 @@ def test_iloc_col(self):
10221034 expected = df .loc [:, 8 :14 ]
10231035 tm .assert_frame_equal (result , expected )
10241036
1025- # verify slice is view
1026- # and that we are setting a copy
1027- msg = r"\nA value is trying to be set on a copy of a slice from a DataFrame"
1028- with pytest .raises (com .SettingWithCopyError , match = msg ):
1029- result [8 ] = 0.0
1030-
1031- assert (df [8 ] == 0 ).all ()
1032-
10331037 # list of integers
10341038 result = df .iloc [:, [1 , 2 , 4 , 6 ]]
10351039 expected = df .reindex (columns = df .columns [[1 , 2 , 4 , 6 ]])
10361040 tm .assert_frame_equal (result , expected )
10371041
1042+ def test_iloc_col_slice_view (self , using_array_manager ):
1043+ df = DataFrame (np .random .randn (4 , 10 ), columns = range (0 , 20 , 2 ))
1044+ original = df .copy ()
1045+ subset = df .iloc [:, slice (4 , 8 )]
1046+
1047+ if not using_array_manager :
1048+ # verify slice is view
1049+ # and that we are setting a copy
1050+ msg = r"\nA value is trying to be set on a copy of a slice from a DataFrame"
1051+ with pytest .raises (com .SettingWithCopyError , match = msg ):
1052+ subset [8 ] = 0.0
1053+
1054+ assert (df [8 ] == 0 ).all ()
1055+ else :
1056+ # TODO(ArrayManager) verify this is the desired behaviour
1057+ subset [8 ] = 0.0
1058+ # subset changed
1059+ assert (subset [8 ] == 0 ).all ()
1060+ # but df itself did not change (setitem replaces full column)
1061+ tm .assert_frame_equal (df , original )
1062+
10381063 def test_loc_duplicates (self ):
10391064 # gh-17105
10401065
@@ -1218,7 +1243,7 @@ def test_setitem(self, uint64_frame):
12181243 )
12191244
12201245
1221- def test_object_casting_indexing_wraps_datetimelike ():
1246+ def test_object_casting_indexing_wraps_datetimelike (using_array_manager ):
12221247 # GH#31649, check the indexing methods all the way down the stack
12231248 df = DataFrame (
12241249 {
@@ -1240,6 +1265,10 @@ def test_object_casting_indexing_wraps_datetimelike():
12401265 assert isinstance (ser .values [1 ], Timestamp )
12411266 assert isinstance (ser .values [2 ], pd .Timedelta )
12421267
1268+ if using_array_manager :
1269+ # remainder of the test checking BlockManager internals
1270+ return
1271+
12431272 mgr = df ._mgr
12441273 mgr ._rebuild_blknos_and_blklocs ()
12451274 arr = mgr .fast_xs (0 )
0 commit comments