18
18
timedelta_range ,
19
19
)
20
20
import pandas ._testing as tm
21
- from pandas .api .types import is_unsigned_integer_dtype
22
- from pandas .core .api import (
23
- Float64Index ,
24
- Int64Index ,
25
- UInt64Index ,
21
+ from pandas .api .types import (
22
+ is_float_dtype ,
23
+ is_signed_integer_dtype ,
24
+ is_unsigned_integer_dtype ,
26
25
)
26
+ from pandas .core .api import NumericIndex
27
27
from pandas .core .arrays import IntervalArray
28
28
import pandas .core .common as com
29
29
@@ -50,9 +50,17 @@ def _skip_test_constructor(self, dtype):
50
50
[
51
51
[3 , 14 , 15 , 92 , 653 ],
52
52
np .arange (10 , dtype = "int64" ),
53
- Int64Index (range (- 10 , 11 )),
54
- UInt64Index (range (10 , 31 )),
55
- Float64Index (np .arange (20 , 30 , 0.5 )),
53
+ NumericIndex (range (- 10 , 11 ), dtype = np .int64 ),
54
+ NumericIndex (range (- 10 , 11 ), dtype = np .int32 ),
55
+ NumericIndex (range (- 10 , 11 ), dtype = np .int16 ),
56
+ NumericIndex (range (- 10 , 11 ), dtype = np .int8 ),
57
+ NumericIndex (range (10 , 31 ), dtype = np .uint64 ),
58
+ NumericIndex (range (10 , 31 ), dtype = np .uint32 ),
59
+ NumericIndex (range (10 , 31 ), dtype = np .uint16 ),
60
+ NumericIndex (range (10 , 31 ), dtype = np .uint8 ),
61
+ NumericIndex (np .arange (20 , 30 , 0.5 ), dtype = np .float64 ),
62
+ NumericIndex (np .arange (20 , 30 , 0.5 ), dtype = np .float32 ),
63
+ NumericIndex (np .arange (20 , 30 , 0.5 ), dtype = np .float16 ),
56
64
date_range ("20180101" , periods = 10 ),
57
65
date_range ("20180101" , periods = 10 , tz = "US/Eastern" ),
58
66
timedelta_range ("1 day" , periods = 10 ),
@@ -81,10 +89,10 @@ def test_constructor(self, constructor, breaks, closed, name, use_dtype):
81
89
@pytest .mark .parametrize (
82
90
"breaks, subtype" ,
83
91
[
84
- (Int64Index ([0 , 1 , 2 , 3 , 4 ]), "float64" ),
85
- (Int64Index ([0 , 1 , 2 , 3 , 4 ]), "datetime64[ns]" ),
86
- (Int64Index ([0 , 1 , 2 , 3 , 4 ]), "timedelta64[ns]" ),
87
- (Float64Index ([0 , 1 , 2 , 3 , 4 ]), "int64" ),
92
+ (Index ([0 , 1 , 2 , 3 , 4 ]), "float64" ),
93
+ (Index ([0 , 1 , 2 , 3 , 4 ]), "datetime64[ns]" ),
94
+ (Index ([0 , 1 , 2 , 3 , 4 ]), "timedelta64[ns]" ),
95
+ (Index ([0 , 1 , 2 , 3 , 4 ], dtype = np . float64 ), "int64" ),
88
96
(date_range ("2017-01-01" , periods = 5 ), "int64" ),
89
97
(timedelta_range ("1 day" , periods = 5 ), "int64" ),
90
98
],
@@ -103,9 +111,18 @@ def test_constructor_dtype(self, constructor, breaks, subtype):
103
111
@pytest .mark .parametrize (
104
112
"breaks" ,
105
113
[
106
- Int64Index ([0 , 1 , 2 , 3 , 4 ]),
107
- UInt64Index ([0 , 1 , 2 , 3 , 4 ]),
108
- Float64Index ([0 , 1 , 2 , 3 , 4 ]),
114
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .int64 ),
115
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .int32 ),
116
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .int32 ),
117
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .int16 ),
118
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .int8 ),
119
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .uint64 ),
120
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .uint32 ),
121
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .uint16 ),
122
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .uint8 ),
123
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .float64 ),
124
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .float32 ),
125
+ NumericIndex ([0 , 1 , 2 , 3 , 4 ], dtype = np .float16 ),
109
126
date_range ("2017-01-01" , periods = 5 ),
110
127
timedelta_range ("1 day" , periods = 5 ),
111
128
],
@@ -262,8 +279,8 @@ def test_mixed_float_int(self, left_subtype, right_subtype):
262
279
right = np .arange (1 , 10 , dtype = right_subtype )
263
280
result = IntervalIndex .from_arrays (left , right )
264
281
265
- expected_left = Float64Index (left )
266
- expected_right = Float64Index (right )
282
+ expected_left = Index (left , dtype = np . float64 )
283
+ expected_right = Index (right , dtype = np . float64 )
267
284
expected_subtype = np .float64
268
285
269
286
tm .assert_index_equal (result .left , expected_left )
@@ -313,8 +330,13 @@ class TestFromTuples(ConstructorTests):
313
330
"""Tests specific to IntervalIndex.from_tuples"""
314
331
315
332
def _skip_test_constructor (self , dtype ):
316
- if is_unsigned_integer_dtype (dtype ):
317
- return True , "tuples don't have a dtype"
333
+ msg = f"tuples don't have a dtype, so constructor won't see dtype { dtype } "
334
+ if is_signed_integer_dtype (dtype ) and dtype != "int64" :
335
+ return True , msg
336
+ elif is_float_dtype (dtype ) and dtype != "float64" :
337
+ return True , msg
338
+ elif is_unsigned_integer_dtype (dtype ):
339
+ return True , msg
318
340
else :
319
341
return False , ""
320
342
@@ -366,10 +388,13 @@ class TestClassConstructors(ConstructorTests):
366
388
"""Tests specific to the IntervalIndex/Index constructors"""
367
389
368
390
def _skip_test_constructor (self , dtype ):
369
- # get_kwargs_from_breaks in TestFromTuples and TestClassconstructors just return
370
- # tuples of ints, so IntervalIndex can't know the original dtype
371
- if is_unsigned_integer_dtype (dtype ):
372
- return True , "tuples don't have a dtype"
391
+ msg = f"tuples don't have a dtype, so constructor won't see dtype { dtype } "
392
+ if is_signed_integer_dtype (dtype ) and dtype != "int64" :
393
+ return True , msg
394
+ elif is_float_dtype (dtype ) and dtype != "float64" :
395
+ return True , msg
396
+ elif is_unsigned_integer_dtype (dtype ):
397
+ return True , msg
373
398
else :
374
399
return False , ""
375
400
0 commit comments