77 Series ,
88)
99import pandas ._testing as tm
10- from pandas .tests .indexes .common import NumericBase
1110
1211
13- class TestFloatNumericIndex (NumericBase ):
14- _index_cls = Index
15-
12+ class TestFloatNumericIndex :
1613 @pytest .fixture (params = [np .float64 , np .float32 ])
1714 def dtype (self , request ):
1815 return request .param
1916
2017 @pytest .fixture
2118 def simple_index (self , dtype ):
2219 values = np .arange (5 , dtype = dtype )
23- return self . _index_cls (values )
20+ return Index (values )
2421
2522 @pytest .fixture (
2623 params = [
@@ -32,15 +29,15 @@ def simple_index(self, dtype):
3229 ids = ["mixed" , "float" , "mixed_dec" , "float_dec" ],
3330 )
3431 def index (self , request , dtype ):
35- return self . _index_cls (request .param , dtype = dtype )
32+ return Index (request .param , dtype = dtype )
3633
3734 @pytest .fixture
3835 def mixed_index (self , dtype ):
39- return self . _index_cls ([1.5 , 2 , 3 , 4 , 5 ], dtype = dtype )
36+ return Index ([1.5 , 2 , 3 , 4 , 5 ], dtype = dtype )
4037
4138 @pytest .fixture
4239 def float_index (self , dtype ):
43- return self . _index_cls ([0.0 , 2.5 , 5.0 , 7.5 , 10.0 ], dtype = dtype )
40+ return Index ([0.0 , 2.5 , 5.0 , 7.5 , 10.0 ], dtype = dtype )
4441
4542 def test_repr_roundtrip (self , index ):
4643 tm .assert_index_equal (eval (repr (index )), index , exact = True )
@@ -49,16 +46,16 @@ def check_coerce(self, a, b, is_float_index=True):
4946 assert a .equals (b )
5047 tm .assert_index_equal (a , b , exact = False )
5148 if is_float_index :
52- assert isinstance (b , self . _index_cls )
49+ assert isinstance (b , Index )
5350 else :
5451 assert type (b ) is Index
5552
5653 def test_constructor_from_list_no_dtype (self ):
57- index = self . _index_cls ([1.5 , 2.5 , 3.5 ])
54+ index = Index ([1.5 , 2.5 , 3.5 ])
5855 assert index .dtype == np .float64
5956
6057 def test_constructor (self , dtype ):
61- index_cls = self . _index_cls
58+ index_cls = Index
6259
6360 # explicit construction
6461 index = index_cls ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
@@ -97,7 +94,7 @@ def test_constructor(self, dtype):
9794 assert pd .isna (result .values ).all ()
9895
9996 def test_constructor_invalid (self ):
100- index_cls = self . _index_cls
97+ index_cls = Index
10198 cls_name = index_cls .__name__
10299 # invalid
103100 msg = (
@@ -131,7 +128,7 @@ def test_type_coercion_fail(self, any_int_numpy_dtype):
131128 Index ([1 , 2 , 3.5 ], dtype = any_int_numpy_dtype )
132129
133130 def test_equals_numeric (self ):
134- index_cls = self . _index_cls
131+ index_cls = Index
135132
136133 idx = index_cls ([1.0 , 2.0 ])
137134 assert idx .equals (idx )
@@ -156,7 +153,7 @@ def test_equals_numeric(self):
156153 ),
157154 )
158155 def test_equals_numeric_other_index_type (self , other ):
159- idx = self . _index_cls ([1.0 , 2.0 ])
156+ idx = Index ([1.0 , 2.0 ])
160157 assert idx .equals (other )
161158 assert other .equals (idx )
162159
@@ -198,13 +195,13 @@ def test_lookups_datetimelike_values(self, vals, dtype):
198195 assert isinstance (result , type (expected )) and result == expected
199196
200197 def test_doesnt_contain_all_the_things (self ):
201- idx = self . _index_cls ([np .nan ])
198+ idx = Index ([np .nan ])
202199 assert not idx .isin ([0 ]).item ()
203200 assert not idx .isin ([1 ]).item ()
204201 assert idx .isin ([np .nan ]).item ()
205202
206203 def test_nan_multiple_containment (self ):
207- index_cls = self . _index_cls
204+ index_cls = Index
208205
209206 idx = index_cls ([1.0 , np .nan ])
210207 tm .assert_numpy_array_equal (idx .isin ([1.0 ]), np .array ([True , False ]))
@@ -215,7 +212,7 @@ def test_nan_multiple_containment(self):
215212 tm .assert_numpy_array_equal (idx .isin ([np .nan ]), np .array ([False , False ]))
216213
217214 def test_fillna_float64 (self ):
218- index_cls = self . _index_cls
215+ index_cls = Index
219216 # GH 11343
220217 idx = Index ([1.0 , np .nan , 3.0 ], dtype = float , name = "x" )
221218 # can't downcast
@@ -231,11 +228,17 @@ def test_fillna_float64(self):
231228 tm .assert_index_equal (idx .fillna ("obj" ), exp , exact = True )
232229
233230
234- class NumericInt (NumericBase ):
235- _index_cls = Index
231+ class TestNumericInt :
232+ @pytest .fixture (params = [np .int64 , np .int32 , np .int16 , np .int8 , np .uint64 ])
233+ def dtype (self , request ):
234+ return request .param
235+
236+ @pytest .fixture
237+ def simple_index (self , dtype ):
238+ return Index (range (0 , 20 , 2 ), dtype = dtype )
236239
237240 def test_is_monotonic (self ):
238- index_cls = self . _index_cls
241+ index_cls = Index
239242
240243 index = index_cls ([1 , 2 , 3 , 4 ])
241244 assert index .is_monotonic_increasing is True
@@ -257,7 +260,7 @@ def test_is_monotonic(self):
257260 assert index ._is_strictly_monotonic_decreasing is True
258261
259262 def test_is_strictly_monotonic (self ):
260- index_cls = self . _index_cls
263+ index_cls = Index
261264
262265 index = index_cls ([1 , 1 , 2 , 3 ])
263266 assert index .is_monotonic_increasing is True
@@ -303,7 +306,7 @@ def test_cant_or_shouldnt_cast(self, dtype):
303306 # can't
304307 data = ["foo" , "bar" , "baz" ]
305308 with pytest .raises (ValueError , match = msg ):
306- self . _index_cls (data , dtype = dtype )
309+ Index (data , dtype = dtype )
307310
308311 def test_view_index (self , simple_index ):
309312 index = simple_index
@@ -315,27 +318,17 @@ def test_prevent_casting(self, simple_index):
315318 assert result .dtype == np .object_
316319
317320
318- class TestIntNumericIndex ( NumericInt ) :
321+ class TestIntNumericIndex :
319322 @pytest .fixture (params = [np .int64 , np .int32 , np .int16 , np .int8 ])
320323 def dtype (self , request ):
321324 return request .param
322325
323- @pytest .fixture
324- def simple_index (self , dtype ):
325- return self ._index_cls (range (0 , 20 , 2 ), dtype = dtype )
326-
327- @pytest .fixture (
328- params = [range (0 , 20 , 2 ), range (19 , - 1 , - 1 )], ids = ["index_inc" , "index_dec" ]
329- )
330- def index (self , request , dtype ):
331- return self ._index_cls (request .param , dtype = dtype )
332-
333326 def test_constructor_from_list_no_dtype (self ):
334- index = self . _index_cls ([1 , 2 , 3 ])
327+ index = Index ([1 , 2 , 3 ])
335328 assert index .dtype == np .int64
336329
337330 def test_constructor (self , dtype ):
338- index_cls = self . _index_cls
331+ index_cls = Index
339332
340333 # scalar raise Exception
341334 msg = (
@@ -379,7 +372,7 @@ def test_constructor(self, dtype):
379372 tm .assert_index_equal (idx , expected )
380373
381374 def test_constructor_corner (self , dtype ):
382- index_cls = self . _index_cls
375+ index_cls = Index
383376
384377 arr = np .array ([1 , 2 , 3 , 4 ], dtype = object )
385378
@@ -426,7 +419,7 @@ def test_constructor_np_unsigned(self, any_unsigned_int_numpy_dtype):
426419 def test_coerce_list (self ):
427420 # coerce things
428421 arr = Index ([1 , 2 , 3 , 4 ])
429- assert isinstance (arr , self . _index_cls )
422+ assert isinstance (arr , Index )
430423
431424 # but not if explicit dtype passed
432425 arr = Index ([1 , 2 , 3 , 4 ], dtype = object )
@@ -436,10 +429,8 @@ def test_coerce_list(self):
436429class TestFloat16Index :
437430 # float 16 indexes not supported
438431 # GH 49535
439- _index_cls = Index
440-
441432 def test_constructor (self ):
442- index_cls = self . _index_cls
433+ index_cls = Index
443434 dtype = np .float16
444435
445436 msg = "float16 indexes are not supported"
@@ -471,27 +462,6 @@ def test_constructor(self):
471462 index_cls (np .array ([np .nan ]), dtype = dtype )
472463
473464
474- class TestUIntNumericIndex (NumericInt ):
475- @pytest .fixture (params = [np .uint64 ])
476- def dtype (self , request ):
477- return request .param
478-
479- @pytest .fixture
480- def simple_index (self , dtype ):
481- # compat with shared Int64/Float64 tests
482- return self ._index_cls (np .arange (5 , dtype = dtype ))
483-
484- @pytest .fixture (
485- params = [
486- [2 ** 63 , 2 ** 63 + 10 , 2 ** 63 + 15 , 2 ** 63 + 20 , 2 ** 63 + 25 ],
487- [2 ** 63 + 25 , 2 ** 63 + 20 , 2 ** 63 + 15 , 2 ** 63 + 10 , 2 ** 63 ],
488- ],
489- ids = ["index_inc" , "index_dec" ],
490- )
491- def index (self , request ):
492- return self ._index_cls (request .param , dtype = np .uint64 )
493-
494-
495465@pytest .mark .parametrize (
496466 "box" ,
497467 [list , lambda x : np .array (x , dtype = object ), lambda x : Index (x , dtype = object )],
0 commit comments