7
7
Series ,
8
8
)
9
9
import pandas ._testing as tm
10
- from pandas .tests .indexes .common import NumericBase
11
10
12
11
13
- class TestFloatNumericIndex (NumericBase ):
14
- _index_cls = Index
15
-
12
+ class TestFloatNumericIndex :
16
13
@pytest .fixture (params = [np .float64 , np .float32 ])
17
14
def dtype (self , request ):
18
15
return request .param
19
16
20
17
@pytest .fixture
21
18
def simple_index (self , dtype ):
22
19
values = np .arange (5 , dtype = dtype )
23
- return self . _index_cls (values )
20
+ return Index (values )
24
21
25
22
@pytest .fixture (
26
23
params = [
@@ -32,15 +29,15 @@ def simple_index(self, dtype):
32
29
ids = ["mixed" , "float" , "mixed_dec" , "float_dec" ],
33
30
)
34
31
def index (self , request , dtype ):
35
- return self . _index_cls (request .param , dtype = dtype )
32
+ return Index (request .param , dtype = dtype )
36
33
37
34
@pytest .fixture
38
35
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 )
40
37
41
38
@pytest .fixture
42
39
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 )
44
41
45
42
def test_repr_roundtrip (self , index ):
46
43
tm .assert_index_equal (eval (repr (index )), index , exact = True )
@@ -49,16 +46,16 @@ def check_coerce(self, a, b, is_float_index=True):
49
46
assert a .equals (b )
50
47
tm .assert_index_equal (a , b , exact = False )
51
48
if is_float_index :
52
- assert isinstance (b , self . _index_cls )
49
+ assert isinstance (b , Index )
53
50
else :
54
51
assert type (b ) is Index
55
52
56
53
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 ])
58
55
assert index .dtype == np .float64
59
56
60
57
def test_constructor (self , dtype ):
61
- index_cls = self . _index_cls
58
+ index_cls = Index
62
59
63
60
# explicit construction
64
61
index = index_cls ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
@@ -97,7 +94,7 @@ def test_constructor(self, dtype):
97
94
assert pd .isna (result .values ).all ()
98
95
99
96
def test_constructor_invalid (self ):
100
- index_cls = self . _index_cls
97
+ index_cls = Index
101
98
cls_name = index_cls .__name__
102
99
# invalid
103
100
msg = (
@@ -131,7 +128,7 @@ def test_type_coercion_fail(self, any_int_numpy_dtype):
131
128
Index ([1 , 2 , 3.5 ], dtype = any_int_numpy_dtype )
132
129
133
130
def test_equals_numeric (self ):
134
- index_cls = self . _index_cls
131
+ index_cls = Index
135
132
136
133
idx = index_cls ([1.0 , 2.0 ])
137
134
assert idx .equals (idx )
@@ -156,7 +153,7 @@ def test_equals_numeric(self):
156
153
),
157
154
)
158
155
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 ])
160
157
assert idx .equals (other )
161
158
assert other .equals (idx )
162
159
@@ -198,13 +195,13 @@ def test_lookups_datetimelike_values(self, vals, dtype):
198
195
assert isinstance (result , type (expected )) and result == expected
199
196
200
197
def test_doesnt_contain_all_the_things (self ):
201
- idx = self . _index_cls ([np .nan ])
198
+ idx = Index ([np .nan ])
202
199
assert not idx .isin ([0 ]).item ()
203
200
assert not idx .isin ([1 ]).item ()
204
201
assert idx .isin ([np .nan ]).item ()
205
202
206
203
def test_nan_multiple_containment (self ):
207
- index_cls = self . _index_cls
204
+ index_cls = Index
208
205
209
206
idx = index_cls ([1.0 , np .nan ])
210
207
tm .assert_numpy_array_equal (idx .isin ([1.0 ]), np .array ([True , False ]))
@@ -215,7 +212,7 @@ def test_nan_multiple_containment(self):
215
212
tm .assert_numpy_array_equal (idx .isin ([np .nan ]), np .array ([False , False ]))
216
213
217
214
def test_fillna_float64 (self ):
218
- index_cls = self . _index_cls
215
+ index_cls = Index
219
216
# GH 11343
220
217
idx = Index ([1.0 , np .nan , 3.0 ], dtype = float , name = "x" )
221
218
# can't downcast
@@ -231,11 +228,17 @@ def test_fillna_float64(self):
231
228
tm .assert_index_equal (idx .fillna ("obj" ), exp , exact = True )
232
229
233
230
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 )
236
239
237
240
def test_is_monotonic (self ):
238
- index_cls = self . _index_cls
241
+ index_cls = Index
239
242
240
243
index = index_cls ([1 , 2 , 3 , 4 ])
241
244
assert index .is_monotonic_increasing is True
@@ -257,7 +260,7 @@ def test_is_monotonic(self):
257
260
assert index ._is_strictly_monotonic_decreasing is True
258
261
259
262
def test_is_strictly_monotonic (self ):
260
- index_cls = self . _index_cls
263
+ index_cls = Index
261
264
262
265
index = index_cls ([1 , 1 , 2 , 3 ])
263
266
assert index .is_monotonic_increasing is True
@@ -303,7 +306,7 @@ def test_cant_or_shouldnt_cast(self, dtype):
303
306
# can't
304
307
data = ["foo" , "bar" , "baz" ]
305
308
with pytest .raises (ValueError , match = msg ):
306
- self . _index_cls (data , dtype = dtype )
309
+ Index (data , dtype = dtype )
307
310
308
311
def test_view_index (self , simple_index ):
309
312
index = simple_index
@@ -315,27 +318,17 @@ def test_prevent_casting(self, simple_index):
315
318
assert result .dtype == np .object_
316
319
317
320
318
- class TestIntNumericIndex ( NumericInt ) :
321
+ class TestIntNumericIndex :
319
322
@pytest .fixture (params = [np .int64 , np .int32 , np .int16 , np .int8 ])
320
323
def dtype (self , request ):
321
324
return request .param
322
325
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
-
333
326
def test_constructor_from_list_no_dtype (self ):
334
- index = self . _index_cls ([1 , 2 , 3 ])
327
+ index = Index ([1 , 2 , 3 ])
335
328
assert index .dtype == np .int64
336
329
337
330
def test_constructor (self , dtype ):
338
- index_cls = self . _index_cls
331
+ index_cls = Index
339
332
340
333
# scalar raise Exception
341
334
msg = (
@@ -379,7 +372,7 @@ def test_constructor(self, dtype):
379
372
tm .assert_index_equal (idx , expected )
380
373
381
374
def test_constructor_corner (self , dtype ):
382
- index_cls = self . _index_cls
375
+ index_cls = Index
383
376
384
377
arr = np .array ([1 , 2 , 3 , 4 ], dtype = object )
385
378
@@ -426,7 +419,7 @@ def test_constructor_np_unsigned(self, any_unsigned_int_numpy_dtype):
426
419
def test_coerce_list (self ):
427
420
# coerce things
428
421
arr = Index ([1 , 2 , 3 , 4 ])
429
- assert isinstance (arr , self . _index_cls )
422
+ assert isinstance (arr , Index )
430
423
431
424
# but not if explicit dtype passed
432
425
arr = Index ([1 , 2 , 3 , 4 ], dtype = object )
@@ -436,10 +429,8 @@ def test_coerce_list(self):
436
429
class TestFloat16Index :
437
430
# float 16 indexes not supported
438
431
# GH 49535
439
- _index_cls = Index
440
-
441
432
def test_constructor (self ):
442
- index_cls = self . _index_cls
433
+ index_cls = Index
443
434
dtype = np .float16
444
435
445
436
msg = "float16 indexes are not supported"
@@ -471,27 +462,6 @@ def test_constructor(self):
471
462
index_cls (np .array ([np .nan ]), dtype = dtype )
472
463
473
464
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
-
495
465
@pytest .mark .parametrize (
496
466
"box" ,
497
467
[list , lambda x : np .array (x , dtype = object ), lambda x : Index (x , dtype = object )],
0 commit comments