@@ -52,11 +52,9 @@ def test_droplevel(self, index):
52
52
):
53
53
index .droplevel (level )
54
54
55
- def test_constructor_non_hashable_name (self , index ):
55
+ def test_constructor_non_hashable_name (self , index_flat ):
56
56
# GH 20527
57
-
58
- if isinstance (index , MultiIndex ):
59
- pytest .skip ("multiindex handled in test_multi.py" )
57
+ index = index_flat
60
58
61
59
message = "Index.name must be a hashable type"
62
60
renamed = [["1" ]]
@@ -69,27 +67,23 @@ def test_constructor_non_hashable_name(self, index):
69
67
with pytest .raises (TypeError , match = message ):
70
68
index .set_names (names = renamed )
71
69
72
- def test_constructor_unwraps_index (self , index ):
73
- if isinstance (index , pd .MultiIndex ):
74
- raise pytest .skip ("MultiIndex has no ._data" )
75
- a = index
70
+ def test_constructor_unwraps_index (self , index_flat ):
71
+ a = index_flat
76
72
b = type (a )(a )
77
73
tm .assert_equal (a ._data , b ._data )
78
74
79
- def test_to_flat_index (self , index ):
75
+ def test_to_flat_index (self , index_flat ):
80
76
# 22866
81
- if isinstance (index , MultiIndex ):
82
- pytest .skip ("Separate expectation for MultiIndex" )
77
+ index = index_flat
83
78
84
79
result = index .to_flat_index ()
85
80
tm .assert_index_equal (result , index )
86
81
87
- def test_set_name_methods (self , index ):
82
+ def test_set_name_methods (self , index_flat ):
83
+ # MultiIndex tested separately
84
+ index = index_flat
88
85
new_name = "This is the new name for this index"
89
86
90
- # don't tests a MultiIndex here (as its tested separated)
91
- if isinstance (index , MultiIndex ):
92
- pytest .skip ("Skip check for MultiIndex" )
93
87
original_name = index .name
94
88
new_ind = index .set_names ([new_name ])
95
89
assert new_ind .name == new_name
@@ -113,11 +107,10 @@ def test_set_name_methods(self, index):
113
107
assert index .name == name
114
108
assert index .names == [name ]
115
109
116
- def test_copy_and_deepcopy (self , index ):
110
+ def test_copy_and_deepcopy (self , index_flat ):
117
111
from copy import copy , deepcopy
118
112
119
- if isinstance (index , MultiIndex ):
120
- pytest .skip ("Skip check for MultiIndex" )
113
+ index = index_flat
121
114
122
115
for func in (copy , deepcopy ):
123
116
idx_copy = func (index )
@@ -127,10 +120,9 @@ def test_copy_and_deepcopy(self, index):
127
120
new_copy = index .copy (deep = True , name = "banana" )
128
121
assert new_copy .name == "banana"
129
122
130
- def test_unique (self , index ):
123
+ def test_unique (self , index_flat ):
131
124
# don't test a MultiIndex here (as its tested separated)
132
- if isinstance (index , MultiIndex ):
133
- pytest .skip ("Skip check for MultiIndex" )
125
+ index = index_flat
134
126
135
127
# GH 17896
136
128
expected = index .drop_duplicates ()
@@ -149,9 +141,10 @@ def test_unique(self, index):
149
141
with pytest .raises (KeyError , match = msg ):
150
142
index .unique (level = "wrong" )
151
143
152
- def test_get_unique_index (self , index ):
144
+ def test_get_unique_index (self , index_flat ):
153
145
# MultiIndex tested separately
154
- if not len (index ) or isinstance (index , MultiIndex ):
146
+ index = index_flat
147
+ if not len (index ):
155
148
pytest .skip ("Skip check for empty Index and MultiIndex" )
156
149
157
150
idx = index [[0 ] * 5 ]
@@ -200,11 +193,12 @@ def test_get_unique_index(self, index):
200
193
result = i ._get_unique_index (dropna = dropna )
201
194
tm .assert_index_equal (result , expected )
202
195
203
- def test_searchsorted_monotonic (self , index ):
196
+ def test_searchsorted_monotonic (self , index_flat ):
204
197
# GH17271
198
+ index = index_flat
205
199
# not implemented for tuple searches in MultiIndex
206
200
# or Intervals searches in IntervalIndex
207
- if isinstance (index , ( MultiIndex , pd .IntervalIndex ) ):
201
+ if isinstance (index , pd .IntervalIndex ):
208
202
pytest .skip ("Skip check for MultiIndex/IntervalIndex" )
209
203
210
204
# nothing to test if the index is empty
@@ -245,9 +239,9 @@ def test_searchsorted_monotonic(self, index):
245
239
with pytest .raises (ValueError , match = msg ):
246
240
index ._searchsorted_monotonic (value , side = "left" )
247
241
248
- def test_drop_duplicates (self , index , keep ):
249
- if isinstance ( index , MultiIndex ):
250
- pytest . skip ( "MultiIndex is tested separately" )
242
+ def test_drop_duplicates (self , index_flat , keep ):
243
+ # MultiIndex is tested separately
244
+ index = index_flat
251
245
if isinstance (index , RangeIndex ):
252
246
pytest .skip (
253
247
"RangeIndex is tested in test_drop_duplicates_no_duplicates "
@@ -279,9 +273,9 @@ def test_drop_duplicates(self, index, keep):
279
273
expected_dropped = holder (pd .Series (idx ).drop_duplicates (keep = keep ))
280
274
tm .assert_index_equal (idx .drop_duplicates (keep = keep ), expected_dropped )
281
275
282
- def test_drop_duplicates_no_duplicates (self , index ):
283
- if isinstance ( index , MultiIndex ):
284
- pytest . skip ( "MultiIndex is tested separately" )
276
+ def test_drop_duplicates_no_duplicates (self , index_flat ):
277
+ # MultiIndex is tested separately
278
+ index = index_flat
285
279
286
280
# make unique index
287
281
if isinstance (index , RangeIndex ):
@@ -305,9 +299,12 @@ def test_drop_duplicates_inplace(self, index):
305
299
with pytest .raises (TypeError , match = msg ):
306
300
index .drop_duplicates (inplace = True )
307
301
308
- def test_has_duplicates (self , index ):
302
+ def test_has_duplicates (self , index_flat ):
303
+ # MultiIndex tested separately in:
304
+ # tests/indexes/multi/test_unique_and_duplicates.
305
+ index = index_flat
309
306
holder = type (index )
310
- if not len (index ) or isinstance (index , ( MultiIndex , RangeIndex ) ):
307
+ if not len (index ) or isinstance (index , RangeIndex ):
311
308
# MultiIndex tested separately in:
312
309
# tests/indexes/multi/test_unique_and_duplicates.
313
310
# RangeIndex is unique by definition.
@@ -363,29 +360,18 @@ def test_asi8_deprecation(self, index):
363
360
364
361
365
362
@pytest .mark .parametrize ("na_position" , [None , "middle" ])
366
- def test_sort_values_invalid_na_position (request , index_with_missing , na_position ):
367
- if isinstance (index_with_missing , MultiIndex ):
368
- request .node .add_marker (
369
- pytest .mark .xfail (
370
- reason = "missing value sorting order not defined for index type"
371
- )
372
- )
363
+ def test_sort_values_invalid_na_position (index_with_missing , na_position ):
373
364
374
- if na_position not in ["first" , "last" ]:
375
- with pytest .raises (ValueError , match = f"invalid na_position: { na_position } " ):
376
- index_with_missing .sort_values (na_position = na_position )
365
+ with pytest .raises (ValueError , match = f"invalid na_position: { na_position } " ):
366
+ index_with_missing .sort_values (na_position = na_position )
377
367
378
368
379
369
@pytest .mark .parametrize ("na_position" , ["first" , "last" ])
380
- def test_sort_values_with_missing (request , index_with_missing , na_position ):
370
+ def test_sort_values_with_missing (index_with_missing , na_position ):
381
371
# GH 35584. Test that sort_values works with missing values,
382
372
# sort non-missing and place missing according to na_position
383
373
384
- if isinstance (index_with_missing , MultiIndex ):
385
- request .node .add_marker (
386
- pytest .mark .xfail (reason = "missing value sorting order not implemented" )
387
- )
388
- elif isinstance (index_with_missing , CategoricalIndex ):
374
+ if isinstance (index_with_missing , CategoricalIndex ):
389
375
pytest .skip ("missing value sorting order not well-defined" )
390
376
391
377
missing_count = np .sum (index_with_missing .isna ())
0 commit comments