1818class TestFloat64Index (NumericBase ):
1919 _index_cls = Float64Index
2020
21- @pytest .fixture
21+ @pytest .fixture ( params = [ np . float64 ])
2222 def dtype (self , request ):
23- return np . float64
23+ return request . param
2424
2525 @pytest .fixture (
26- params = ["int64" , "uint64" , "category" , "datetime64" ],
26+ params = ["int64" , "uint64" , "category" , "datetime64" , "object" ],
2727 )
2828 def invalid_dtype (self , request ):
2929 return request .param
@@ -42,16 +42,16 @@ def simple_index(self, dtype):
4242 ],
4343 ids = ["mixed" , "float" , "mixed_dec" , "float_dec" ],
4444 )
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 )
4747
4848 @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 )
5151
5252 @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 )
5555
5656 def test_repr_roundtrip (self , index ):
5757 tm .assert_index_equal (eval (repr (index )), index )
@@ -72,22 +72,23 @@ def test_constructor(self, dtype):
7272 index_cls = self ._index_cls
7373
7474 # explicit construction
75- index = index_cls ([1 , 2 , 3 , 4 , 5 ])
75+ index = index_cls ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
7676
7777 assert isinstance (index , index_cls )
78- assert index .dtype . type is dtype
78+ assert index .dtype == dtype
7979
8080 expected = np .array ([1 , 2 , 3 , 4 , 5 ], dtype = dtype )
8181 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 )
8384 assert isinstance (index , index_cls )
8485 assert index .dtype == dtype
8586
86- index = index_cls ([1.0 , 2 , 3 , 4 , 5 ])
87+ index = index_cls ([1.0 , 2 , 3 , 4 , 5 ], dtype = dtype )
8788 assert isinstance (index , index_cls )
8889 assert index .dtype == dtype
8990
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 )
9192 assert isinstance (index , index_cls )
9293 assert index .dtype == dtype
9394
@@ -100,13 +101,13 @@ def test_constructor(self, dtype):
100101 assert index .dtype == dtype
101102
102103 # nan handling
103- result = index_cls ([np .nan , np .nan ])
104+ result = index_cls ([np .nan , np .nan ], dtype = dtype )
104105 assert pd .isna (result .values ).all ()
105106
106- result = index_cls (np .array ([np .nan ]))
107+ result = index_cls (np .array ([np .nan ]), dtype = dtype )
107108 assert pd .isna (result .values ).all ()
108109
109- result = Index (np .array ([np .nan ]))
110+ result = Index (np .array ([np .nan ], dtype = dtype ))
110111 assert isinstance (result , index_cls )
111112 assert result .dtype == dtype
112113 assert pd .isna (result .values ).all ()
@@ -281,7 +282,7 @@ class NumericInt(NumericBase):
281282 def test_view (self , dtype ):
282283 index_cls = self ._index_cls
283284
284- idx = index_cls ([], name = "Foo" )
285+ idx = index_cls ([], dtype = dtype , name = "Foo" )
285286 idx_view = idx .view ()
286287 assert idx_view .name == "Foo"
287288
@@ -382,12 +383,12 @@ def test_prevent_casting(self, simple_index):
382383class TestInt64Index (NumericInt ):
383384 _index_cls = Int64Index
384385
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
388389
389390 @pytest .fixture (
390- params = ["uint64" , "float64" , "category" , "datetime64" ],
391+ params = ["uint64" , "float64" , "category" , "datetime64" , "object" ],
391392 )
392393 def invalid_dtype (self , request ):
393394 return request .param
@@ -399,14 +400,14 @@ def simple_index(self, dtype):
399400 @pytest .fixture (
400401 params = [range (0 , 20 , 2 ), range (19 , - 1 , - 1 )], ids = ["index_inc" , "index_dec" ]
401402 )
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 )
404405
405406 def test_constructor (self , dtype ):
406407 index_cls = self ._index_cls
407408
408409 # pass list, coerce fine
409- index = index_cls ([- 5 , 0 , 1 , 2 ])
410+ index = index_cls ([- 5 , 0 , 1 , 2 ], dtype = dtype )
410411 expected = Index ([- 5 , 0 , 1 , 2 ], dtype = dtype )
411412 tm .assert_index_equal (index , expected )
412413
@@ -486,7 +487,7 @@ def dtype(self):
486487 return np .uint64
487488
488489 @pytest .fixture (
489- params = ["int64" , "float64" , "category" , "datetime64" ],
490+ params = ["int64" , "float64" , "category" , "datetime64" , "object" ],
490491 )
491492 def invalid_dtype (self , request ):
492493 return request .param
0 commit comments