Skip to content

Commit

Permalink
Backport PR pandas-dev#56294: BUG: Series(strings, dtype=ArrowDtype[t…
Browse files Browse the repository at this point in the history
…imestamp]) raising
  • Loading branch information
mroeschke committed Dec 5, 2023
1 parent 0c1a9f3 commit 93d1344
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Fixed regressions
Bug fixes
~~~~~~~~~
- Bug in :class:`Series` constructor raising DeprecationWarning when ``index`` is a list of :class:`Series` (:issue:`55228`)
- Bug in :class:`Series` when trying to cast date-like string inputs to :class:`ArrowDtype` of ``pyarrow.timestamp`` (:issue:`56266`)
- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55753`)
- Bug in :meth:`Index.__getitem__` returning wrong result for Arrow dtypes and negative stepsize (:issue:`55832`)
- Fixed bug in :func:`to_numeric` converting to extension dtype for ``string[pyarrow_numpy]`` dtype (:issue:`56179`)
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ def _box_pa_array(

try:
pa_array = pa.array(value, type=pa_type, from_pandas=True)
except pa.ArrowInvalid:
except (pa.ArrowInvalid, pa.ArrowTypeError):
# GH50430: let pyarrow infer type, then cast
pa_array = pa.array(value, from_pandas=True)

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3109,3 +3109,13 @@ def test_arrow_floordiv():
expected = pd.Series([-2], dtype="int64[pyarrow]")
result = a // b
tm.assert_series_equal(result, expected)


def test_string_to_datetime_parsing_cast():
# GH 56266
string_dates = ["2020-01-01 04:30:00", "2020-01-02 00:00:00", "2020-01-03 00:00:00"]
result = pd.Series(string_dates, dtype="timestamp[ns][pyarrow]")
expected = pd.Series(
ArrowExtensionArray(pa.array(pd.to_datetime(string_dates), from_pandas=True))
)
tm.assert_series_equal(result, expected)

0 comments on commit 93d1344

Please sign in to comment.