@@ -59,30 +59,6 @@ def test_isin_cats():
59
59
tm .assert_numpy_array_equal (expected , result )
60
60
61
61
62
- @pytest .mark .parametrize (
63
- "to_replace, value, result, expected_error_msg" ,
64
- [
65
- ("b" , "c" , ["a" , "c" ], "Categorical.categories are different" ),
66
- ("c" , "d" , ["a" , "b" ], None ),
67
- # https://github.com/pandas-dev/pandas/issues/33288
68
- ("a" , "a" , ["a" , "b" ], None ),
69
- ("b" , None , ["a" , None ], "Categorical.categories length are different" ),
70
- ],
71
- )
72
- def test_replace (to_replace , value , result , expected_error_msg ):
73
- # GH 26988
74
- cat = pd .Categorical (["a" , "b" ])
75
- expected = pd .Categorical (result )
76
- result = cat .replace (to_replace , value )
77
- tm .assert_categorical_equal (result , expected )
78
- if to_replace == "b" : # the "c" test is supposed to be unchanged
79
- with pytest .raises (AssertionError , match = expected_error_msg ):
80
- # ensure non-inplace call does not affect original
81
- tm .assert_categorical_equal (cat , expected )
82
- cat .replace (to_replace , value , inplace = True )
83
- tm .assert_categorical_equal (cat , expected )
84
-
85
-
86
62
@pytest .mark .parametrize ("empty" , [[], pd .Series (dtype = object ), np .array ([])])
87
63
def test_isin_empty (empty ):
88
64
s = pd .Categorical (["a" , "b" ])
@@ -105,94 +81,3 @@ def test_diff():
105
81
result = df .diff ()
106
82
107
83
tm .assert_frame_equal (result , expected )
108
-
109
-
110
- class TestTake :
111
- # https://github.com/pandas-dev/pandas/issues/20664
112
-
113
- def test_take_default_allow_fill (self ):
114
- cat = pd .Categorical (["a" , "b" ])
115
- with tm .assert_produces_warning (None ):
116
- result = cat .take ([0 , - 1 ])
117
-
118
- assert result .equals (cat )
119
-
120
- def test_take_positive_no_warning (self ):
121
- cat = pd .Categorical (["a" , "b" ])
122
- with tm .assert_produces_warning (None ):
123
- cat .take ([0 , 0 ])
124
-
125
- def test_take_bounds (self , allow_fill ):
126
- # https://github.com/pandas-dev/pandas/issues/20664
127
- cat = pd .Categorical (["a" , "b" , "a" ])
128
- if allow_fill :
129
- msg = "indices are out-of-bounds"
130
- else :
131
- msg = "index 4 is out of bounds for( axis 0 with)? size 3"
132
- with pytest .raises (IndexError , match = msg ):
133
- cat .take ([4 , 5 ], allow_fill = allow_fill )
134
-
135
- def test_take_empty (self , allow_fill ):
136
- # https://github.com/pandas-dev/pandas/issues/20664
137
- cat = pd .Categorical ([], categories = ["a" , "b" ])
138
- if allow_fill :
139
- msg = "indices are out-of-bounds"
140
- else :
141
- msg = "cannot do a non-empty take from an empty axes"
142
- with pytest .raises (IndexError , match = msg ):
143
- cat .take ([0 ], allow_fill = allow_fill )
144
-
145
- def test_positional_take (self , ordered ):
146
- cat = pd .Categorical (
147
- ["a" , "a" , "b" , "b" ], categories = ["b" , "a" ], ordered = ordered
148
- )
149
- result = cat .take ([0 , 1 , 2 ], allow_fill = False )
150
- expected = pd .Categorical (
151
- ["a" , "a" , "b" ], categories = cat .categories , ordered = ordered
152
- )
153
- tm .assert_categorical_equal (result , expected )
154
-
155
- def test_positional_take_unobserved (self , ordered ):
156
- cat = pd .Categorical (["a" , "b" ], categories = ["a" , "b" , "c" ], ordered = ordered )
157
- result = cat .take ([1 , 0 ], allow_fill = False )
158
- expected = pd .Categorical (
159
- ["b" , "a" ], categories = cat .categories , ordered = ordered
160
- )
161
- tm .assert_categorical_equal (result , expected )
162
-
163
- def test_take_allow_fill (self ):
164
- # https://github.com/pandas-dev/pandas/issues/23296
165
- cat = pd .Categorical (["a" , "a" , "b" ])
166
- result = cat .take ([0 , - 1 , - 1 ], allow_fill = True )
167
- expected = pd .Categorical (["a" , np .nan , np .nan ], categories = ["a" , "b" ])
168
- tm .assert_categorical_equal (result , expected )
169
-
170
- def test_take_fill_with_negative_one (self ):
171
- # -1 was a category
172
- cat = pd .Categorical ([- 1 , 0 , 1 ])
173
- result = cat .take ([0 , - 1 , 1 ], allow_fill = True , fill_value = - 1 )
174
- expected = pd .Categorical ([- 1 , - 1 , 0 ], categories = [- 1 , 0 , 1 ])
175
- tm .assert_categorical_equal (result , expected )
176
-
177
- def test_take_fill_value (self ):
178
- # https://github.com/pandas-dev/pandas/issues/23296
179
- cat = pd .Categorical (["a" , "b" , "c" ])
180
- result = cat .take ([0 , 1 , - 1 ], fill_value = "a" , allow_fill = True )
181
- expected = pd .Categorical (["a" , "b" , "a" ], categories = ["a" , "b" , "c" ])
182
- tm .assert_categorical_equal (result , expected )
183
-
184
- def test_take_fill_value_new_raises (self ):
185
- # https://github.com/pandas-dev/pandas/issues/23296
186
- cat = pd .Categorical (["a" , "b" , "c" ])
187
- xpr = r"'fill_value=d' is not present in this Categorical's categories"
188
- with pytest .raises (ValueError , match = xpr ):
189
- cat .take ([0 , 1 , - 1 ], fill_value = "d" , allow_fill = True )
190
-
191
- def test_take_nd_deprecated (self ):
192
- cat = pd .Categorical (["a" , "b" , "c" ])
193
- with tm .assert_produces_warning (FutureWarning ):
194
- cat .take_nd ([0 , 1 ])
195
-
196
- ci = pd .Index (cat )
197
- with tm .assert_produces_warning (FutureWarning ):
198
- ci .take_nd ([0 , 1 ])
0 commit comments