Skip to content

Commit

Permalink
Backport PR #52330 on branch 2.0.x (ENH: Implement .dt.year for Arrow…
Browse files Browse the repository at this point in the history
…ExtensionArray) (#52359)

* Backport PR #52330: ENH: Implement .dt.year for ArrowExtensionArray

* Update array.py

---------

Co-authored-by: Matthew Roeschke <10647082+mroeschke@users.noreply.github.com>
Co-authored-by: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 2, 2023
1 parent 7c56e05 commit 9bf45db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,10 @@ def _str_wrap(self, width, **kwargs):
"str.wrap not supported with pd.ArrowDtype(pa.string())."
)

@property
def _dt_year(self):
return type(self)(pc.year(self._data))

@property
def _dt_day(self):
return type(self)(pc.day(self._data))
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,7 @@ def test_unsupported_dt(data):
@pytest.mark.parametrize(
"prop, expected",
[
["year", 2023],
["day", 2],
["day_of_week", 0],
["dayofweek", 0],
Expand Down

0 comments on commit 9bf45db

Please sign in to comment.