Skip to content

Commit d620c51

Browse files
Fixes #29526
1 parent 5ad038f commit d620c51

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

pandas/core/indexes/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,7 +4027,7 @@ def _string_data_error(cls, data):
40274027
)
40284028

40294029
@classmethod
4030-
def _coerce_to_ndarray(cls, data):
4030+
def _coerce_to_ndarray(cls, data, dtype=None):
40314031
"""
40324032
Coerces data to ndarray.
40334033
@@ -4047,7 +4047,8 @@ def _coerce_to_ndarray(cls, data):
40474047
# other iterable of some kind
40484048
if not isinstance(data, (ABCSeries, list, tuple)):
40494049
data = list(data)
4050-
data = np.asarray(data)
4050+
4051+
data = np.asarray(data, dtype=dtype)
40514052
return data
40524053

40534054
def _coerce_scalar_to_index(self, item):

pandas/core/indexes/numeric.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None, fastpath=None):
5757
return cls._simple_new(data, name=name)
5858

5959
# is_scalar, generators handled in coerce_to_ndarray
60-
data = cls._coerce_to_ndarray(data)
60+
data = cls._coerce_to_ndarray(data, dtype=dtype)
6161

6262
if issubclass(data.dtype.type, str):
6363
cls._string_data_error(data)

0 commit comments

Comments
 (0)