Skip to content

Commit 458c25e

Browse files
Move string check into Index._coerce_to_ndarray
1 parent 68fe304 commit 458c25e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pandas/core/indexes/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4046,6 +4046,9 @@ def _coerce_to_ndarray(cls, data, dtype=None):
40464046
if is_scalar(data):
40474047
raise cls._scalar_data_error(data)
40484048

4049+
if lib.infer_dtype(data) == 'string':
4050+
raise cls._string_data_error(data)
4051+
40494052
# other iterable of some kind
40504053
if not isinstance(data, (ABCSeries, list, tuple)):
40514054
data = list(data)

pandas/core/indexes/numeric.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,9 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None, fastpath=None):
5656
if fastpath:
5757
return cls._simple_new(data, name=name)
5858

59-
# is_scalar, generators handled in coerce_to_ndarray
59+
# is_scalar, generators and strings are handled in coerce_to_ndarray
6060
data = cls._coerce_to_ndarray(data, dtype=cls._default_dtype)
6161

62-
if issubclass(data.dtype.type, str):
63-
cls._string_data_error(data)
64-
6562
if copy or not is_dtype_equal(data.dtype, cls._default_dtype):
6663
subarr = np.array(data, dtype=cls._default_dtype, copy=copy)
6764
cls._assert_safe_casting(data, subarr)

0 commit comments

Comments
 (0)