@@ -1662,25 +1662,6 @@ def orig(self):
1662
1662
orig = DataFrame ({"cats" : cats , "values" : values }, index = idx )
1663
1663
return orig
1664
1664
1665
- @pytest .fixture
1666
- def exp_single_row (self ):
1667
- # The expected values if we change a single row
1668
- cats1 = Categorical (["a" , "a" , "b" , "a" , "a" , "a" , "a" ], categories = ["a" , "b" ])
1669
- idx1 = Index (["h" , "i" , "j" , "k" , "l" , "m" , "n" ])
1670
- values1 = [1 , 1 , 2 , 1 , 1 , 1 , 1 ]
1671
- exp_single_row = DataFrame ({"cats" : cats1 , "values" : values1 }, index = idx1 )
1672
- return exp_single_row
1673
-
1674
- @pytest .fixture
1675
- def exp_multi_row (self ):
1676
- # assign multiple rows (mixed values) (-> array) -> exp_multi_row
1677
- # changed multiple rows
1678
- cats2 = Categorical (["a" , "a" , "b" , "b" , "a" , "a" , "a" ], categories = ["a" , "b" ])
1679
- idx2 = Index (["h" , "i" , "j" , "k" , "l" , "m" , "n" ])
1680
- values2 = [1 , 1 , 2 , 2 , 1 , 1 , 1 ]
1681
- exp_multi_row = DataFrame ({"cats" : cats2 , "values" : values2 }, index = idx2 )
1682
- return exp_multi_row
1683
-
1684
1665
@pytest .fixture
1685
1666
def exp_parts_cats_col (self ):
1686
1667
# changed part of the cats column
@@ -1702,7 +1683,7 @@ def exp_single_cats_value(self):
1702
1683
return exp_single_cats_value
1703
1684
1704
1685
@pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc ])
1705
- def test_loc_iloc_setitem_list_of_lists (self , orig , exp_multi_row , indexer ):
1686
+ def test_loc_iloc_setitem_list_of_lists (self , orig , indexer ):
1706
1687
# - assign multiple rows (mixed values) -> exp_multi_row
1707
1688
df = orig .copy ()
1708
1689
@@ -1711,6 +1692,11 @@ def test_loc_iloc_setitem_list_of_lists(self, orig, exp_multi_row, indexer):
1711
1692
key = slice ("j" , "k" )
1712
1693
1713
1694
indexer (df )[key , :] = [["b" , 2 ], ["b" , 2 ]]
1695
+
1696
+ cats2 = Categorical (["a" , "a" , "b" , "b" , "a" , "a" , "a" ], categories = ["a" , "b" ])
1697
+ idx2 = Index (["h" , "i" , "j" , "k" , "l" , "m" , "n" ])
1698
+ values2 = [1 , 1 , 2 , 2 , 1 , 1 , 1 ]
1699
+ exp_multi_row = DataFrame ({"cats" : cats2 , "values" : values2 }, index = idx2 )
1714
1700
tm .assert_frame_equal (df , exp_multi_row )
1715
1701
1716
1702
df = orig .copy ()
@@ -1752,9 +1738,7 @@ def test_loc_iloc_setitem_mask_single_value_in_categories(
1752
1738
tm .assert_frame_equal (df , exp_single_cats_value )
1753
1739
1754
1740
@pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc ])
1755
- def test_loc_iloc_setitem_full_row_non_categorical_rhs (
1756
- self , orig , exp_single_row , indexer
1757
- ):
1741
+ def test_loc_iloc_setitem_full_row_non_categorical_rhs (self , orig , indexer ):
1758
1742
# - assign a complete row (mixed values) -> exp_single_row
1759
1743
df = orig .copy ()
1760
1744
@@ -1764,6 +1748,10 @@ def test_loc_iloc_setitem_full_row_non_categorical_rhs(
1764
1748
1765
1749
# not categorical dtype, but "b" _is_ among the categories for df["cat"]
1766
1750
indexer (df )[key , :] = ["b" , 2 ]
1751
+ cats1 = Categorical (["a" , "a" , "b" , "a" , "a" , "a" , "a" ], categories = ["a" , "b" ])
1752
+ idx1 = Index (["h" , "i" , "j" , "k" , "l" , "m" , "n" ])
1753
+ values1 = [1 , 1 , 2 , 1 , 1 , 1 , 1 ]
1754
+ exp_single_row = DataFrame ({"cats" : cats1 , "values" : values1 }, index = idx1 )
1767
1755
tm .assert_frame_equal (df , exp_single_row )
1768
1756
1769
1757
# "c" is not among the categories for df["cat"]
0 commit comments