@@ -1682,16 +1682,15 @@ def exp_single_cats_value(self):
16821682 )
16831683 return exp_single_cats_value
16841684
1685- @pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc ])
1686- def test_loc_iloc_setitem_list_of_lists (self , orig , indexer ):
1685+ def test_loc_iloc_setitem_list_of_lists (self , orig , indexer_li ):
16871686 # - assign multiple rows (mixed values) -> exp_multi_row
16881687 df = orig .copy ()
16891688
16901689 key = slice (2 , 4 )
1691- if indexer is tm .loc :
1690+ if indexer_li is tm .loc :
16921691 key = slice ("j" , "k" )
16931692
1694- indexer (df )[key , :] = [["b" , 2 ], ["b" , 2 ]]
1693+ indexer_li (df )[key , :] = [["b" , 2 ], ["b" , 2 ]]
16951694
16961695 cats2 = Categorical (["a" , "a" , "b" , "b" , "a" , "a" , "a" ], categories = ["a" , "b" ])
16971696 idx2 = Index (["h" , "i" , "j" , "k" , "l" , "m" , "n" ])
@@ -1701,7 +1700,7 @@ def test_loc_iloc_setitem_list_of_lists(self, orig, indexer):
17011700
17021701 df = orig .copy ()
17031702 with pytest .raises (TypeError , match = msg1 ):
1704- indexer (df )[key , :] = [["c" , 2 ], ["c" , 2 ]]
1703+ indexer_li (df )[key , :] = [["c" , 2 ], ["c" , 2 ]]
17051704
17061705 @pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc , tm .at , tm .iat ])
17071706 def test_loc_iloc_at_iat_setitem_single_value_in_categories (
@@ -1722,32 +1721,30 @@ def test_loc_iloc_at_iat_setitem_single_value_in_categories(
17221721 with pytest .raises (TypeError , match = msg1 ):
17231722 indexer (df )[key ] = "c"
17241723
1725- @pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc ])
17261724 def test_loc_iloc_setitem_mask_single_value_in_categories (
1727- self , orig , exp_single_cats_value , indexer
1725+ self , orig , exp_single_cats_value , indexer_li
17281726 ):
17291727 # mask with single True
17301728 df = orig .copy ()
17311729
17321730 mask = df .index == "j"
17331731 key = 0
1734- if indexer is tm .loc :
1732+ if indexer_li is tm .loc :
17351733 key = df .columns [key ]
17361734
1737- indexer (df )[mask , key ] = "b"
1735+ indexer_li (df )[mask , key ] = "b"
17381736 tm .assert_frame_equal (df , exp_single_cats_value )
17391737
1740- @pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc ])
1741- def test_loc_iloc_setitem_full_row_non_categorical_rhs (self , orig , indexer ):
1738+ def test_loc_iloc_setitem_full_row_non_categorical_rhs (self , orig , indexer_li ):
17421739 # - assign a complete row (mixed values) -> exp_single_row
17431740 df = orig .copy ()
17441741
17451742 key = 2
1746- if indexer is tm .loc :
1743+ if indexer_li is tm .loc :
17471744 key = df .index [2 ]
17481745
17491746 # not categorical dtype, but "b" _is_ among the categories for df["cat"]
1750- indexer (df )[key , :] = ["b" , 2 ]
1747+ indexer_li (df )[key , :] = ["b" , 2 ]
17511748 cats1 = Categorical (["a" , "a" , "b" , "a" , "a" , "a" , "a" ], categories = ["a" , "b" ])
17521749 idx1 = Index (["h" , "i" , "j" , "k" , "l" , "m" , "n" ])
17531750 values1 = [1 , 1 , 2 , 1 , 1 , 1 , 1 ]
@@ -1756,56 +1753,54 @@ def test_loc_iloc_setitem_full_row_non_categorical_rhs(self, orig, indexer):
17561753
17571754 # "c" is not among the categories for df["cat"]
17581755 with pytest .raises (TypeError , match = msg1 ):
1759- indexer (df )[key , :] = ["c" , 2 ]
1756+ indexer_li (df )[key , :] = ["c" , 2 ]
17601757
1761- @pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc ])
17621758 def test_loc_iloc_setitem_partial_col_categorical_rhs (
1763- self , orig , exp_parts_cats_col , indexer
1759+ self , orig , exp_parts_cats_col , indexer_li
17641760 ):
17651761 # assign a part of a column with dtype == categorical ->
17661762 # exp_parts_cats_col
17671763 df = orig .copy ()
17681764
17691765 key = (slice (2 , 4 ), 0 )
1770- if indexer is tm .loc :
1766+ if indexer_li is tm .loc :
17711767 key = (slice ("j" , "k" ), df .columns [0 ])
17721768
17731769 # same categories as we currently have in df["cats"]
17741770 compat = Categorical (["b" , "b" ], categories = ["a" , "b" ])
1775- indexer (df )[key ] = compat
1771+ indexer_li (df )[key ] = compat
17761772 tm .assert_frame_equal (df , exp_parts_cats_col )
17771773
17781774 # categories do not match df["cat"]'s, but "b" is among them
17791775 semi_compat = Categorical (list ("bb" ), categories = list ("abc" ))
17801776 with pytest .raises (TypeError , match = msg2 ):
17811777 # different categories but holdable values
17821778 # -> not sure if this should fail or pass
1783- indexer (df )[key ] = semi_compat
1779+ indexer_li (df )[key ] = semi_compat
17841780
17851781 # categories do not match df["cat"]'s, and "c" is not among them
17861782 incompat = Categorical (list ("cc" ), categories = list ("abc" ))
17871783 with pytest .raises (TypeError , match = msg2 ):
17881784 # different values
1789- indexer (df )[key ] = incompat
1785+ indexer_li (df )[key ] = incompat
17901786
1791- @pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc ])
17921787 def test_loc_iloc_setitem_non_categorical_rhs (
1793- self , orig , exp_parts_cats_col , indexer
1788+ self , orig , exp_parts_cats_col , indexer_li
17941789 ):
17951790 # assign a part of a column with dtype != categorical -> exp_parts_cats_col
17961791 df = orig .copy ()
17971792
17981793 key = (slice (2 , 4 ), 0 )
1799- if indexer is tm .loc :
1794+ if indexer_li is tm .loc :
18001795 key = (slice ("j" , "k" ), df .columns [0 ])
18011796
18021797 # "b" is among the categories for df["cat"]
1803- indexer (df )[key ] = ["b" , "b" ]
1798+ indexer_li (df )[key ] = ["b" , "b" ]
18041799 tm .assert_frame_equal (df , exp_parts_cats_col )
18051800
18061801 # "c" not part of the categories
18071802 with pytest .raises (TypeError , match = msg1 ):
1808- indexer (df )[key ] = ["c" , "c" ]
1803+ indexer_li (df )[key ] = ["c" , "c" ]
18091804
18101805 @pytest .mark .parametrize ("indexer" , [tm .getitem , tm .loc , tm .iloc ])
18111806 def test_getitem_preserve_object_index_with_dates (self , indexer ):
0 commit comments