Skip to content

Commit bfe6895

Browse files
committed
add cleanups
1 parent 3630fc7 commit bfe6895

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

pandas/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
RangeIndex,
7777
Float64Index,
7878
MultiIndex,
79-
NumericIndex,
8079
IntervalIndex,
8180
TimedeltaIndex,
8281
DatetimeIndex,

pandas/core/indexes/numeric.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ def _ensure_array(cls, data, dtype, copy: bool):
166166
dtype = cls._ensure_dtype(dtype)
167167

168168
if copy or not is_dtype_equal(data.dtype, dtype):
169-
subarr = np.array(data, dtype=dtype, copy=copy)
170-
if not is_numeric_dtype(subarr.dtype):
171-
# hack to raise correctly
172-
subarr = np.array(data, dtype="float64", copy=copy)
169+
try:
170+
subarr = np.array(data, dtype=dtype, copy=copy)
171+
cls._validate_dtype(subarr.dtype)
172+
except (TypeError, ValueError):
173+
raise ValueError(f"data is not compatible with {cls.__name__}")
173174
cls._assert_safe_casting(data, subarr)
174175
else:
175176
subarr = data

pandas/tests/indexes/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
isna,
3434
)
3535
import pandas._testing as tm
36+
from pandas.core.api import NumericIndex
3637
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
37-
from pandas.core.indexes.numeric import NumericIndex
3838

3939

4040
class Base:

pandas/tests/indexes/numeric/test_numeric.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,8 @@ def test_constructor_invalid(self):
128128
with pytest.raises((TypeError, ValueError), match=msg):
129129
index_cls(["a", "b", 0.0])
130130

131-
msg = (
132-
r"float\(\) argument must be a string or a( real)? number, not 'Timestamp'"
133-
)
134-
with pytest.raises(TypeError, match=msg):
131+
msg = f"data is not compatible with {index_cls.__name__}"
132+
with pytest.raises(ValueError, match=msg):
135133
index_cls([Timestamp("20130101")])
136134

137135
def test_constructor_coerce(self, mixed_index, float_index):

pandas/tests/indexes/test_numpy_compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
TimedeltaIndex,
1010
)
1111
import pandas._testing as tm
12+
from pandas.core.api import NumericIndex
1213
from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
13-
from pandas.core.indexes.numeric import NumericIndex
1414

1515

1616
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)