@@ -64,6 +64,10 @@ def check_coerce(self, a, b, is_float_index=True):
64
64
else :
65
65
self .check_is_index (b )
66
66
67
+ def test_constructor_from_list_no_dtype (self ):
68
+ index = self ._index_cls ([1.5 , 2.5 , 3.5 ])
69
+ assert index .dtype == np .float64
70
+
67
71
def test_constructor (self , dtype ):
68
72
index_cls = self ._index_cls
69
73
@@ -115,17 +119,10 @@ def test_constructor_invalid(self):
115
119
with pytest .raises (TypeError , match = msg ):
116
120
index_cls (0.0 )
117
121
118
- # 2021-02-1 we get ValueError in numpy 1.20, but not on all builds
119
- msg = "|" .join (
120
- [
121
- "String dtype not supported, you may need to explicitly cast " ,
122
- "could not convert string to float: 'a'" ,
123
- ]
124
- )
125
- with pytest .raises ((TypeError , ValueError ), match = msg ):
122
+ msg = f"data is not compatible with { index_cls .__name__ } "
123
+ with pytest .raises (ValueError , match = msg ):
126
124
index_cls (["a" , "b" , 0.0 ])
127
125
128
- msg = f"data is not compatible with { index_cls .__name__ } "
129
126
with pytest .raises (ValueError , match = msg ):
130
127
index_cls ([Timestamp ("20130101" )])
131
128
@@ -327,18 +324,16 @@ def test_identical(self, simple_index, dtype):
327
324
assert not index .astype (dtype = object ).identical (index .astype (dtype = dtype ))
328
325
329
326
def test_cant_or_shouldnt_cast (self ):
330
- msg = (
331
- "String dtype not supported, "
332
- "you may need to explicitly cast to a numeric type"
333
- )
327
+ msg = f"data is not compatible with { self ._index_cls .__name__ } "
328
+
334
329
# can't
335
330
data = ["foo" , "bar" , "baz" ]
336
- with pytest .raises (TypeError , match = msg ):
331
+ with pytest .raises (ValueError , match = msg ):
337
332
self ._index_cls (data )
338
333
339
334
# shouldn't
340
335
data = ["0" , "1" , "2" ]
341
- with pytest .raises (TypeError , match = msg ):
336
+ with pytest .raises (ValueError , match = msg ):
342
337
self ._index_cls (data )
343
338
344
339
def test_view_index (self , simple_index ):
@@ -372,6 +367,10 @@ def simple_index(self, dtype):
372
367
def index (self , request , dtype ):
373
368
return self ._index_cls (request .param , dtype = dtype )
374
369
370
+ def test_constructor_from_list_no_dtype (self ):
371
+ index = self ._index_cls ([1 , 2 , 3 ])
372
+ assert index .dtype == np .int64
373
+
375
374
def test_constructor (self , dtype ):
376
375
index_cls = self ._index_cls
377
376
0 commit comments