Skip to content

Commit

Permalink
BUG: Series(strings, dtype=ArrowDtype[timestamp]) raising
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke committed Dec 2, 2023
1 parent 2a0e253 commit 76ba0cc
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:`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`)
- Fixed bug in :meth:`DataFrame.__setitem__` casting :class:`Index` with object-dtype to PyArrow backed strings when ``infer_string`` option is set (:issue:`55638`)
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 @@ -2959,3 +2959,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 76ba0cc

Please sign in to comment.