Skip to content
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

BUG: Fix #61222: Keep index name when resampling with pyarrow dtype #61229

Merged
merged 2 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -773,6 +773,7 @@ Groupby/resample/rolling
- Bug in :meth:`.DataFrameGroupBy.quantile` when ``interpolation="nearest"`` is inconsistent with :meth:`DataFrame.quantile` (:issue:`47942`)
- Bug in :meth:`.Resampler.interpolate` on a :class:`DataFrame` with non-uniform sampling and/or indices not aligning with the resulting resampled index would result in wrong interpolation (:issue:`21351`)
- Bug in :meth:`DataFrame.ewm` and :meth:`Series.ewm` when passed ``times`` and aggregation functions other than mean (:issue:`51695`)
- Bug in :meth:`DataFrame.resample` and :meth:`Series.resample` were not keeping the index name when the index had :class:`ArrowDtype` timestamp dtype (:issue:`61222`)
- Bug in :meth:`DataFrame.resample` changing index type to :class:`MultiIndex` when the dataframe is empty and using an upsample method (:issue:`55572`)
- Bug in :meth:`DataFrameGroupBy.agg` that raises ``AttributeError`` when there is dictionary input and duplicated columns, instead of returning a DataFrame with the aggregation of all duplicate columns. (:issue:`55041`)
- Bug in :meth:`DataFrameGroupBy.apply` and :meth:`SeriesGroupBy.apply` for empty data frame with ``group_keys=False`` still creating output index using group keys. (:issue:`60471`)
Expand Down
1 change: 1 addition & 0 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ def _wrap_result(self, result):

if self._timegrouper._arrow_dtype is not None:
result.index = result.index.astype(self._timegrouper._arrow_dtype)
result.index.name = self.obj.index.name

return result

Expand Down
10 changes: 10 additions & 0 deletions pandas/tests/resample/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,16 @@ def test_arrow_timestamp_resample(tz):
tm.assert_series_equal(result, expected)


@td.skip_if_no("pyarrow")
def test_arrow_timestamp_resample_keep_index_name():
# https://github.com/pandas-dev/pandas/issues/61222
idx = Series(date_range("2020-01-01", periods=5), dtype="timestamp[ns][pyarrow]")
expected = Series(np.arange(5, dtype=np.float64), index=idx)
expected.index.name = "index_name"
result = expected.resample("1D").mean()
tm.assert_series_equal(result, expected)


@pytest.mark.parametrize("freq", ["1A", "2A-MAR"])
def test_resample_A_raises(freq):
msg = f"Invalid frequency: {freq[1:]}"
Expand Down