18
18
class TestFloat64Index (NumericBase ):
19
19
_index_cls = Float64Index
20
20
21
- @pytest .fixture
21
+ @pytest .fixture ( params = [ np . float64 ])
22
22
def dtype (self , request ):
23
- return np . float64
23
+ return request . param
24
24
25
25
@pytest .fixture (
26
- params = ["int64" , "uint64" , "category" , "datetime64" ],
26
+ params = ["int64" , "uint64" , "category" , "datetime64" , "object" ],
27
27
)
28
28
def invalid_dtype (self , request ):
29
29
return request .param
@@ -42,16 +42,16 @@ def simple_index(self, dtype):
42
42
],
43
43
ids = ["mixed" , "float" , "mixed_dec" , "float_dec" ],
44
44
)
45
- def index (self , request ):
46
- return self ._index_cls (request .param )
45
+ def index (self , request , dtype ):
46
+ return self ._index_cls (request .param , dtype = dtype )
47
47
48
48
@pytest .fixture
49
- def mixed_index (self ):
50
- return self ._index_cls ([1.5 , 2 , 3 , 4 , 5 ])
49
+ def mixed_index (self , dtype ):
50
+ return self ._index_cls ([1.5 , 2 , 3 , 4 , 5 ], dtype = dtype )
51
51
52
52
@pytest .fixture
53
- def float_index (self ):
54
- return self ._index_cls ([0.0 , 2.5 , 5.0 , 7.5 , 10.0 ])
53
+ def float_index (self , dtype ):
54
+ return self ._index_cls ([0.0 , 2.5 , 5.0 , 7.5 , 10.0 ], dtype = dtype )
55
55
56
56
def test_repr_roundtrip (self , index ):
57
57
tm .assert_index_equal (eval (repr (index )), index )
@@ -72,22 +72,23 @@ def test_constructor(self, dtype):
72
72
index_cls = self ._index_cls
73
73
74
74
# explicit construction
75
- index = index_cls ([1 , 2 , 3 , 4 , 5 ])
75
+ index = index_cls ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
76
76
77
77
assert isinstance (index , index_cls )
78
- assert index .dtype . type is dtype
78
+ assert index .dtype == dtype
79
79
80
80
expected = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
81
81
tm .assert_numpy_array_equal (index .values , expected )
82
- index = index_cls (np .array ([1 , 2 , 3 , 4 , 5 ]))
82
+
83
+ index = index_cls (np .array ([1 , 2 , 3 , 4 , 5 ]), dtype = dtype )
83
84
assert isinstance (index , index_cls )
84
85
assert index .dtype == dtype
85
86
86
- index = index_cls ([1.0 , 2 , 3 , 4 , 5 ])
87
+ index = index_cls ([1.0 , 2 , 3 , 4 , 5 ], dtype = dtype )
87
88
assert isinstance (index , index_cls )
88
89
assert index .dtype == dtype
89
90
90
- index = index_cls (np .array ([1.0 , 2 , 3 , 4 , 5 ]))
91
+ index = index_cls (np .array ([1.0 , 2 , 3 , 4 , 5 ]), dtype = dtype )
91
92
assert isinstance (index , index_cls )
92
93
assert index .dtype == dtype
93
94
@@ -100,13 +101,13 @@ def test_constructor(self, dtype):
100
101
assert index .dtype == dtype
101
102
102
103
# nan handling
103
- result = index_cls ([np .nan , np .nan ])
104
+ result = index_cls ([np .nan , np .nan ], dtype = dtype )
104
105
assert pd .isna (result .values ).all ()
105
106
106
- result = index_cls (np .array ([np .nan ]))
107
+ result = index_cls (np .array ([np .nan ]), dtype = dtype )
107
108
assert pd .isna (result .values ).all ()
108
109
109
- result = Index (np .array ([np .nan ]))
110
+ result = Index (np .array ([np .nan ], dtype = dtype ))
110
111
assert isinstance (result , index_cls )
111
112
assert result .dtype == dtype
112
113
assert pd .isna (result .values ).all ()
@@ -281,7 +282,7 @@ class NumericInt(NumericBase):
281
282
def test_view (self , dtype ):
282
283
index_cls = self ._index_cls
283
284
284
- idx = index_cls ([], name = "Foo" )
285
+ idx = index_cls ([], dtype = dtype , name = "Foo" )
285
286
idx_view = idx .view ()
286
287
assert idx_view .name == "Foo"
287
288
@@ -382,12 +383,12 @@ def test_prevent_casting(self, simple_index):
382
383
class TestInt64Index (NumericInt ):
383
384
_index_cls = Int64Index
384
385
385
- @pytest .fixture
386
- def dtype (self ):
387
- return np . int64
386
+ @pytest .fixture ( params = [ np . int64 ])
387
+ def dtype (self , request ):
388
+ return request . param
388
389
389
390
@pytest .fixture (
390
- params = ["uint64" , "float64" , "category" , "datetime64" ],
391
+ params = ["uint64" , "float64" , "category" , "datetime64" , "object" ],
391
392
)
392
393
def invalid_dtype (self , request ):
393
394
return request .param
@@ -399,14 +400,14 @@ def simple_index(self, dtype):
399
400
@pytest .fixture (
400
401
params = [range (0 , 20 , 2 ), range (19 , - 1 , - 1 )], ids = ["index_inc" , "index_dec" ]
401
402
)
402
- def index (self , request ):
403
- return self ._index_cls (request .param )
403
+ def index (self , request , dtype ):
404
+ return self ._index_cls (request .param , dtype = dtype )
404
405
405
406
def test_constructor (self , dtype ):
406
407
index_cls = self ._index_cls
407
408
408
409
# pass list, coerce fine
409
- index = index_cls ([- 5 , 0 , 1 , 2 ])
410
+ index = index_cls ([- 5 , 0 , 1 , 2 ], dtype = dtype )
410
411
expected = Index ([- 5 , 0 , 1 , 2 ], dtype = dtype )
411
412
tm .assert_index_equal (index , expected )
412
413
@@ -486,7 +487,7 @@ def dtype(self):
486
487
return np .uint64
487
488
488
489
@pytest .fixture (
489
- params = ["int64" , "float64" , "category" , "datetime64" ],
490
+ params = ["int64" , "float64" , "category" , "datetime64" , "object" ],
490
491
)
491
492
def invalid_dtype (self , request ):
492
493
return request .param
0 commit comments