Skip to content

Commit 59936dc

Browse files
authored
BUG: Series(strings, dtype=ArrowDtype[timestamp]) raising (#56294)
1 parent df7498f commit 59936dc

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

doc/source/whatsnew/v2.1.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Fixed regressions
2222
Bug fixes
2323
~~~~~~~~~
2424
- Bug in :class:`Series` constructor raising DeprecationWarning when ``index`` is a list of :class:`Series` (:issue:`55228`)
25+
- Bug in :class:`Series` when trying to cast date-like string inputs to :class:`ArrowDtype` of ``pyarrow.timestamp`` (:issue:`56266`)
2526
- Bug in :meth:`Index.__getitem__` returning wrong result for Arrow dtypes and negative stepsize (:issue:`55832`)
2627
- Fixed bug in :func:`to_numeric` converting to extension dtype for ``string[pyarrow_numpy]`` dtype (:issue:`56179`)
2728
- Fixed bug in :meth:`.DataFrameGroupBy.min` and :meth:`.DataFrameGroupBy.max` not preserving extension dtype for empty object (:issue:`55619`)

pandas/core/arrays/arrow/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ def _box_pa_array(
464464

465465
try:
466466
pa_array = pa.array(value, type=pa_type, from_pandas=True)
467-
except pa.ArrowInvalid:
467+
except (pa.ArrowInvalid, pa.ArrowTypeError):
468468
# GH50430: let pyarrow infer type, then cast
469469
pa_array = pa.array(value, from_pandas=True)
470470

pandas/tests/extension/test_arrow.py

+10
Original file line numberDiff line numberDiff line change
@@ -2994,3 +2994,13 @@ def test_arrow_floordiv():
29942994
expected = pd.Series([-2], dtype="int64[pyarrow]")
29952995
result = a // b
29962996
tm.assert_series_equal(result, expected)
2997+
2998+
2999+
def test_string_to_datetime_parsing_cast():
3000+
# GH 56266
3001+
string_dates = ["2020-01-01 04:30:00", "2020-01-02 00:00:00", "2020-01-03 00:00:00"]
3002+
result = pd.Series(string_dates, dtype="timestamp[ns][pyarrow]")
3003+
expected = pd.Series(
3004+
ArrowExtensionArray(pa.array(pd.to_datetime(string_dates), from_pandas=True))
3005+
)
3006+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)