Skip to content

Commit 93d1344

Browse files
committed
Backport PR pandas-dev#56294: BUG: Series(strings, dtype=ArrowDtype[timestamp]) raising
1 parent 0c1a9f3 commit 93d1344

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:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55753`)
2627
- Bug in :meth:`Index.__getitem__` returning wrong result for Arrow dtypes and negative stepsize (:issue:`55832`)
2728
- Fixed bug in :func:`to_numeric` converting to extension dtype for ``string[pyarrow_numpy]`` dtype (:issue:`56179`)

pandas/core/arrays/arrow/array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def _box_pa_array(
463463

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

pandas/tests/extension/test_arrow.py

+10
Original file line numberDiff line numberDiff line change
@@ -3109,3 +3109,13 @@ def test_arrow_floordiv():
31093109
expected = pd.Series([-2], dtype="int64[pyarrow]")
31103110
result = a // b
31113111
tm.assert_series_equal(result, expected)
3112+
3113+
3114+
def test_string_to_datetime_parsing_cast():
3115+
# GH 56266
3116+
string_dates = ["2020-01-01 04:30:00", "2020-01-02 00:00:00", "2020-01-03 00:00:00"]
3117+
result = pd.Series(string_dates, dtype="timestamp[ns][pyarrow]")
3118+
expected = pd.Series(
3119+
ArrowExtensionArray(pa.array(pd.to_datetime(string_dates), from_pandas=True))
3120+
)
3121+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)