Skip to content

Commit ea978b0

Browse files
committed
update test
1 parent 1bffe76 commit ea978b0

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

pandas/tests/indexes/test_base.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import datetime, timedelta
66

77
import pandas.util.testing as tm
8+
from pandas.core.dtypes.common import is_unsigned_integer_dtype
89
from pandas.core.indexes.api import Index, MultiIndex
910
from pandas.tests.indexes.common import Base
1011

@@ -201,25 +202,20 @@ def __array__(self, dtype=None):
201202
result = pd.Index(ArrayLike(array))
202203
tm.assert_index_equal(result, expected)
203204

204-
def test_constructor_int_dtype_float(self):
205+
@pytest.mark.parametrize('dtype', [
206+
int, 'int64', 'int32', 'int16', 'int8', 'uint64', 'uint32',
207+
'uint16', 'uint8'])
208+
def test_constructor_int_dtype_float(self, dtype):
205209
# GH 18400
206-
data = [0., 1., 2., 3.]
207-
208-
expected = Int64Index([0, 1, 2, 3])
209-
result = Index(data, dtype='int64')
210-
tm.assert_index_equal(result, expected)
210+
if is_unsigned_integer_dtype(dtype):
211+
index_type = UInt64Index
212+
else:
213+
index_type = Int64Index
211214

212-
expected = UInt64Index([0, 1, 2, 3])
213-
result = Index(data, dtype='uint64')
215+
expected = index_type([0, 1, 2, 3])
216+
result = Index([0., 1., 2., 3.], dtype=dtype)
214217
tm.assert_index_equal(result, expected)
215218

216-
# fall back to Float64Index
217-
data = [0.0, 1.1, 2.2, 3.3]
218-
expected = Float64Index(data)
219-
for dtype in ('int64', 'uint64'):
220-
result = Index(data, dtype=dtype)
221-
tm.assert_index_equal(result, expected)
222-
223219
def test_constructor_int_dtype_nan(self):
224220
# see gh-15187
225221
data = [np.nan]

0 commit comments

Comments
 (0)