Skip to content

Commit a73b25a

Browse files
jbrockmendelTLouf
authored andcommitted
CLN: remove try/except in _prep_ndarray (pandas-dev#41519)
1 parent a4f1a23 commit a73b25a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

pandas/core/internals/construction.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
)
5858
from pandas.core.arrays import (
5959
Categorical,
60+
DatetimeArray,
6061
ExtensionArray,
6162
TimedeltaArray,
6263
)
@@ -515,7 +516,9 @@ def treat_as_nested(data) -> bool:
515516

516517

517518
def _prep_ndarray(values, copy: bool = True) -> np.ndarray:
518-
if isinstance(values, TimedeltaArray):
519+
if isinstance(values, TimedeltaArray) or (
520+
isinstance(values, DatetimeArray) and values.tz is None
521+
):
519522
# On older numpy, np.asarray below apparently does not call __array__,
520523
# so nanoseconds get dropped.
521524
values = values._ndarray
@@ -541,15 +544,12 @@ def convert(v):
541544
# we could have a 1-dim or 2-dim list here
542545
# this is equiv of np.asarray, but does object conversion
543546
# and platform dtype preservation
544-
try:
545-
if is_list_like(values[0]):
546-
values = np.array([convert(v) for v in values])
547-
elif isinstance(values[0], np.ndarray) and values[0].ndim == 0:
548-
# GH#21861
549-
values = np.array([convert(v) for v in values])
550-
else:
551-
values = convert(values)
552-
except (ValueError, TypeError):
547+
if is_list_like(values[0]):
548+
values = np.array([convert(v) for v in values])
549+
elif isinstance(values[0], np.ndarray) and values[0].ndim == 0:
550+
# GH#21861
551+
values = np.array([convert(v) for v in values])
552+
else:
553553
values = convert(values)
554554

555555
else:

0 commit comments

Comments
 (0)