Skip to content

BUG: Fix .dt.microsecond accessor for pyarrow-backed Series #59183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ Datetimelike
- Bug in :func:`date_range` where the last valid timestamp would sometimes not be produced (:issue:`56134`)
- Bug in :func:`date_range` where using a negative frequency value would not include all points between the start and end values (:issue:`56382`)
- Bug in :func:`tseries.api.guess_datetime_format` would fail to infer time format when "%Y" == "%H%M" (:issue:`57452`)
- Bug in :math:`Series.dt.microsecond` producing incorrect results for pyarrow backed :class:`Series`. (:issue:`59154`)
- Bug in :meth:`Dataframe.agg` with df with missing values resulting in IndexError (:issue:`58810`)
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` does not raise on Custom business days frequencies bigger then "1C" (:issue:`58664`)
- Bug in :meth:`DatetimeIndex.is_year_start` and :meth:`DatetimeIndex.is_quarter_start` returning ``False`` on double-digit frequencies (:issue:`58523`)
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -2794,7 +2794,10 @@ def _dt_days_in_month(self) -> Self:

@property
def _dt_microsecond(self) -> Self:
return type(self)(pc.microsecond(self._pa_array))
# GH 59154
us = pc.microsecond(self._pa_array)
ms_to_us = pc.multiply(pc.millisecond(self._pa_array), 1000)
return type(self)(pc.add(us, ms_to_us))

@property
def _dt_minute(self) -> Self:
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2437,13 +2437,13 @@ def test_unsupported_dt(data):
["hour", 3],
["minute", 4],
["is_leap_year", False],
["microsecond", 5],
["microsecond", 2000],
["month", 1],
["nanosecond", 6],
["quarter", 1],
["second", 7],
["date", date(2023, 1, 2)],
["time", time(3, 4, 7, 5)],
["time", time(3, 4, 7, 2000)],
],
)
def test_dt_properties(prop, expected):
Expand All @@ -2456,7 +2456,7 @@ def test_dt_properties(prop, expected):
hour=3,
minute=4,
second=7,
microsecond=5,
microsecond=2000,
nanosecond=6,
),
None,
Expand Down
Loading