Skip to content

Commit 93b7197

Browse files
committed
BUG: close #30050
enable to_datetime to convert Series with an IntegerArray underlyin datatype
1 parent f4667b5 commit 93b7197

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pandas/core/tools/datetimes.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from pandas._typing import ArrayLike
4040
from pandas.core import algorithms
4141
from pandas.core.algorithms import unique
42+
from pandas.arrays import IntegerArray
4243

4344
# ---------------------------------------------------------------------
4445
# types used in annotations
@@ -316,7 +317,16 @@ def _convert_listlike_datetimes(
316317
if format is not None:
317318
raise ValueError("cannot specify both format and unit")
318319
arg = getattr(arg, "values", arg)
319-
result, tz_parsed = tslib.array_with_unit_to_datetime(arg, unit, errors=errors)
320+
# GH 30050 pass an ndarray to tslib.array_with_unit_to_datetime
321+
# because it expects an ndarray argument
322+
if isinstance(arg, IntegerArray):
323+
arg_np = np.array(arg[np.logical_not(arg._mask)],dtype=type(arg[0]))
324+
result_np, tz_parsed = tslib.array_with_unit_to_datetime(arg_np, unit, errors=errors)
325+
result = np.empty(arg.shape[0],dtype='datetime64[' + unit + ']')
326+
result[arg._mask] = np.datetime64('nat')
327+
result[np.logical_not(arg._mask)] = result_np
328+
else:
329+
result, tz_parsed = tslib.array_with_unit_to_datetime(arg, unit, errors=errors)
320330
if errors == "ignore":
321331
from pandas import Index
322332

0 commit comments

Comments
 (0)