8
8
is_matching_na ,
9
9
)
10
10
11
- import pandas as pd
12
11
from pandas import Index
13
12
import pandas ._testing as tm
14
13
@@ -23,13 +22,13 @@ class TestGetIndexer:
23
22
)
24
23
def test_get_indexer_strings (self , method , expected ):
25
24
expected = np .array (expected , dtype = np .intp )
26
- index = Index (["b" , "c" ])
25
+ index = Index (["b" , "c" ], dtype = object )
27
26
actual = index .get_indexer (["a" , "b" , "c" , "d" ], method = method )
28
27
29
28
tm .assert_numpy_array_equal (actual , expected )
30
29
31
- def test_get_indexer_strings_raises (self , using_infer_string ):
32
- index = Index (["b" , "c" ])
30
+ def test_get_indexer_strings_raises (self ):
31
+ index = Index (["b" , "c" ], dtype = object )
33
32
34
33
msg = "|" .join (
35
34
[
@@ -74,7 +73,7 @@ def test_get_indexer_non_unique_nas(
74
73
# even though this isn't non-unique, this should still work
75
74
if using_infer_string and (nulls_fixture is None or nulls_fixture is NA ):
76
75
request .applymarker (pytest .mark .xfail (reason = "NAs are cast to NaN" ))
77
- index = Index (["a" , "b" , nulls_fixture ])
76
+ index = Index (["a" , "b" , nulls_fixture ], dtype = object )
78
77
indexer , missing = index .get_indexer_non_unique ([nulls_fixture ])
79
78
80
79
expected_indexer = np .array ([2 ], dtype = np .intp )
@@ -83,7 +82,7 @@ def test_get_indexer_non_unique_nas(
83
82
tm .assert_numpy_array_equal (missing , expected_missing )
84
83
85
84
# actually non-unique
86
- index = Index (["a" , nulls_fixture , "b" , nulls_fixture ])
85
+ index = Index (["a" , nulls_fixture , "b" , nulls_fixture ], dtype = object )
87
86
indexer , missing = index .get_indexer_non_unique ([nulls_fixture ])
88
87
89
88
expected_indexer = np .array ([1 , 3 ], dtype = np .intp )
@@ -92,10 +91,10 @@ def test_get_indexer_non_unique_nas(
92
91
93
92
# matching-but-not-identical nans
94
93
if is_matching_na (nulls_fixture , float ("NaN" )):
95
- index = Index (["a" , float ("NaN" ), "b" , float ("NaN" )])
94
+ index = Index (["a" , float ("NaN" ), "b" , float ("NaN" )], dtype = object )
96
95
match_but_not_identical = True
97
96
elif is_matching_na (nulls_fixture , Decimal ("NaN" )):
98
- index = Index (["a" , Decimal ("NaN" ), "b" , Decimal ("NaN" )])
97
+ index = Index (["a" , Decimal ("NaN" ), "b" , Decimal ("NaN" )], dtype = object )
99
98
match_but_not_identical = True
100
99
else :
101
100
match_but_not_identical = False
@@ -156,59 +155,3 @@ def test_get_indexer_non_unique_np_nats(self, np_nat_fixture, np_nat_fixture2):
156
155
expected_indexer = np .array ([1 , 3 ], dtype = np .intp )
157
156
tm .assert_numpy_array_equal (indexer , expected_indexer )
158
157
tm .assert_numpy_array_equal (missing , expected_missing )
159
-
160
-
161
- class TestSliceLocs :
162
- @pytest .mark .parametrize (
163
- "in_slice,expected" ,
164
- [
165
- # error: Slice index must be an integer or None
166
- (pd .IndexSlice [::- 1 ], "yxdcb" ),
167
- (pd .IndexSlice ["b" :"y" :- 1 ], "" ), # type: ignore[misc]
168
- (pd .IndexSlice ["b" ::- 1 ], "b" ), # type: ignore[misc]
169
- (pd .IndexSlice [:"b" :- 1 ], "yxdcb" ), # type: ignore[misc]
170
- (pd .IndexSlice [:"y" :- 1 ], "y" ), # type: ignore[misc]
171
- (pd .IndexSlice ["y" ::- 1 ], "yxdcb" ), # type: ignore[misc]
172
- (pd .IndexSlice ["y" ::- 4 ], "yb" ), # type: ignore[misc]
173
- # absent labels
174
- (pd .IndexSlice [:"a" :- 1 ], "yxdcb" ), # type: ignore[misc]
175
- (pd .IndexSlice [:"a" :- 2 ], "ydb" ), # type: ignore[misc]
176
- (pd .IndexSlice ["z" ::- 1 ], "yxdcb" ), # type: ignore[misc]
177
- (pd .IndexSlice ["z" ::- 3 ], "yc" ), # type: ignore[misc]
178
- (pd .IndexSlice ["m" ::- 1 ], "dcb" ), # type: ignore[misc]
179
- (pd .IndexSlice [:"m" :- 1 ], "yx" ), # type: ignore[misc]
180
- (pd .IndexSlice ["a" :"a" :- 1 ], "" ), # type: ignore[misc]
181
- (pd .IndexSlice ["z" :"z" :- 1 ], "" ), # type: ignore[misc]
182
- (pd .IndexSlice ["m" :"m" :- 1 ], "" ), # type: ignore[misc]
183
- ],
184
- )
185
- def test_slice_locs_negative_step (self , in_slice , expected , any_string_dtype ):
186
- index = Index (list ("bcdxy" ), dtype = any_string_dtype )
187
-
188
- s_start , s_stop = index .slice_locs (in_slice .start , in_slice .stop , in_slice .step )
189
- result = index [s_start : s_stop : in_slice .step ]
190
- expected = Index (list (expected ), dtype = any_string_dtype )
191
- tm .assert_index_equal (result , expected )
192
-
193
- def test_slice_locs_negative_step_oob (self , any_string_dtype ):
194
- index = Index (list ("bcdxy" ), dtype = any_string_dtype )
195
-
196
- result = index [- 10 :5 :1 ]
197
- tm .assert_index_equal (result , index )
198
-
199
- result = index [4 :- 10 :- 1 ]
200
- expected = Index (list ("yxdcb" ), dtype = any_string_dtype )
201
- tm .assert_index_equal (result , expected )
202
-
203
- def test_slice_locs_dup (self ):
204
- index = Index (["a" , "a" , "b" , "c" , "d" , "d" ])
205
- assert index .slice_locs ("a" , "d" ) == (0 , 6 )
206
- assert index .slice_locs (end = "d" ) == (0 , 6 )
207
- assert index .slice_locs ("a" , "c" ) == (0 , 4 )
208
- assert index .slice_locs ("b" , "d" ) == (2 , 6 )
209
-
210
- index2 = index [::- 1 ]
211
- assert index2 .slice_locs ("d" , "a" ) == (0 , 6 )
212
- assert index2 .slice_locs (end = "a" ) == (0 , 6 )
213
- assert index2 .slice_locs ("d" , "b" ) == (0 , 4 )
214
- assert index2 .slice_locs ("c" , "a" ) == (2 , 6 )
0 commit comments