@@ -1682,16 +1682,15 @@ def exp_single_cats_value(self):
1682
1682
)
1683
1683
return exp_single_cats_value
1684
1684
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 ):
1687
1686
# - assign multiple rows (mixed values) -> exp_multi_row
1688
1687
df = orig .copy ()
1689
1688
1690
1689
key = slice (2 , 4 )
1691
- if indexer is tm .loc :
1690
+ if indexer_li is tm .loc :
1692
1691
key = slice ("j" , "k" )
1693
1692
1694
- indexer (df )[key , :] = [["b" , 2 ], ["b" , 2 ]]
1693
+ indexer_li (df )[key , :] = [["b" , 2 ], ["b" , 2 ]]
1695
1694
1696
1695
cats2 = Categorical (["a" , "a" , "b" , "b" , "a" , "a" , "a" ], categories = ["a" , "b" ])
1697
1696
idx2 = Index (["h" , "i" , "j" , "k" , "l" , "m" , "n" ])
@@ -1701,7 +1700,7 @@ def test_loc_iloc_setitem_list_of_lists(self, orig, indexer):
1701
1700
1702
1701
df = orig .copy ()
1703
1702
with pytest .raises (TypeError , match = msg1 ):
1704
- indexer (df )[key , :] = [["c" , 2 ], ["c" , 2 ]]
1703
+ indexer_li (df )[key , :] = [["c" , 2 ], ["c" , 2 ]]
1705
1704
1706
1705
@pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc , tm .at , tm .iat ])
1707
1706
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(
1722
1721
with pytest .raises (TypeError , match = msg1 ):
1723
1722
indexer (df )[key ] = "c"
1724
1723
1725
- @pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc ])
1726
1724
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
1728
1726
):
1729
1727
# mask with single True
1730
1728
df = orig .copy ()
1731
1729
1732
1730
mask = df .index == "j"
1733
1731
key = 0
1734
- if indexer is tm .loc :
1732
+ if indexer_li is tm .loc :
1735
1733
key = df .columns [key ]
1736
1734
1737
- indexer (df )[mask , key ] = "b"
1735
+ indexer_li (df )[mask , key ] = "b"
1738
1736
tm .assert_frame_equal (df , exp_single_cats_value )
1739
1737
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 ):
1742
1739
# - assign a complete row (mixed values) -> exp_single_row
1743
1740
df = orig .copy ()
1744
1741
1745
1742
key = 2
1746
- if indexer is tm .loc :
1743
+ if indexer_li is tm .loc :
1747
1744
key = df .index [2 ]
1748
1745
1749
1746
# 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 ]
1751
1748
cats1 = Categorical (["a" , "a" , "b" , "a" , "a" , "a" , "a" ], categories = ["a" , "b" ])
1752
1749
idx1 = Index (["h" , "i" , "j" , "k" , "l" , "m" , "n" ])
1753
1750
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):
1756
1753
1757
1754
# "c" is not among the categories for df["cat"]
1758
1755
with pytest .raises (TypeError , match = msg1 ):
1759
- indexer (df )[key , :] = ["c" , 2 ]
1756
+ indexer_li (df )[key , :] = ["c" , 2 ]
1760
1757
1761
- @pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc ])
1762
1758
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
1764
1760
):
1765
1761
# assign a part of a column with dtype == categorical ->
1766
1762
# exp_parts_cats_col
1767
1763
df = orig .copy ()
1768
1764
1769
1765
key = (slice (2 , 4 ), 0 )
1770
- if indexer is tm .loc :
1766
+ if indexer_li is tm .loc :
1771
1767
key = (slice ("j" , "k" ), df .columns [0 ])
1772
1768
1773
1769
# same categories as we currently have in df["cats"]
1774
1770
compat = Categorical (["b" , "b" ], categories = ["a" , "b" ])
1775
- indexer (df )[key ] = compat
1771
+ indexer_li (df )[key ] = compat
1776
1772
tm .assert_frame_equal (df , exp_parts_cats_col )
1777
1773
1778
1774
# categories do not match df["cat"]'s, but "b" is among them
1779
1775
semi_compat = Categorical (list ("bb" ), categories = list ("abc" ))
1780
1776
with pytest .raises (TypeError , match = msg2 ):
1781
1777
# different categories but holdable values
1782
1778
# -> not sure if this should fail or pass
1783
- indexer (df )[key ] = semi_compat
1779
+ indexer_li (df )[key ] = semi_compat
1784
1780
1785
1781
# categories do not match df["cat"]'s, and "c" is not among them
1786
1782
incompat = Categorical (list ("cc" ), categories = list ("abc" ))
1787
1783
with pytest .raises (TypeError , match = msg2 ):
1788
1784
# different values
1789
- indexer (df )[key ] = incompat
1785
+ indexer_li (df )[key ] = incompat
1790
1786
1791
- @pytest .mark .parametrize ("indexer" , [tm .loc , tm .iloc ])
1792
1787
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
1794
1789
):
1795
1790
# assign a part of a column with dtype != categorical -> exp_parts_cats_col
1796
1791
df = orig .copy ()
1797
1792
1798
1793
key = (slice (2 , 4 ), 0 )
1799
- if indexer is tm .loc :
1794
+ if indexer_li is tm .loc :
1800
1795
key = (slice ("j" , "k" ), df .columns [0 ])
1801
1796
1802
1797
# "b" is among the categories for df["cat"]
1803
- indexer (df )[key ] = ["b" , "b" ]
1798
+ indexer_li (df )[key ] = ["b" , "b" ]
1804
1799
tm .assert_frame_equal (df , exp_parts_cats_col )
1805
1800
1806
1801
# "c" not part of the categories
1807
1802
with pytest .raises (TypeError , match = msg1 ):
1808
- indexer (df )[key ] = ["c" , "c" ]
1803
+ indexer_li (df )[key ] = ["c" , "c" ]
1809
1804
1810
1805
@pytest .mark .parametrize ("indexer" , [tm .getitem , tm .loc , tm .iloc ])
1811
1806
def test_getitem_preserve_object_index_with_dates (self , indexer ):
0 commit comments