Skip to content

Commit 9df1430

Browse files
mthiboustmroeschke
andauthored
BUG: Fix #61222: Keep index name when resampling with pyarrow dtype (#61229)
* BUG: Fix #61222: Keep index name when resampling with pyarrow dtype * Update doc/source/whatsnew/v3.0.0.rst --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent 961931a commit 9df1430

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ Groupby/resample/rolling
773773
- Bug in :meth:`.DataFrameGroupBy.quantile` when ``interpolation="nearest"`` is inconsistent with :meth:`DataFrame.quantile` (:issue:`47942`)
774774
- 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`)
775775
- Bug in :meth:`DataFrame.ewm` and :meth:`Series.ewm` when passed ``times`` and aggregation functions other than mean (:issue:`51695`)
776+
- 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`)
776777
- Bug in :meth:`DataFrame.resample` changing index type to :class:`MultiIndex` when the dataframe is empty and using an upsample method (:issue:`55572`)
777778
- 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`)
778779
- 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`)

pandas/core/resample.py

+1
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ def _wrap_result(self, result):
518518

519519
if self._timegrouper._arrow_dtype is not None:
520520
result.index = result.index.astype(self._timegrouper._arrow_dtype)
521+
result.index.name = self.obj.index.name
521522

522523
return result
523524

pandas/tests/resample/test_datetime_index.py

+10
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,16 @@ def test_arrow_timestamp_resample(tz):
21552155
tm.assert_series_equal(result, expected)
21562156

21572157

2158+
@td.skip_if_no("pyarrow")
2159+
def test_arrow_timestamp_resample_keep_index_name():
2160+
# https://github.com/pandas-dev/pandas/issues/61222
2161+
idx = Series(date_range("2020-01-01", periods=5), dtype="timestamp[ns][pyarrow]")
2162+
expected = Series(np.arange(5, dtype=np.float64), index=idx)
2163+
expected.index.name = "index_name"
2164+
result = expected.resample("1D").mean()
2165+
tm.assert_series_equal(result, expected)
2166+
2167+
21582168
@pytest.mark.parametrize("freq", ["1A", "2A-MAR"])
21592169
def test_resample_A_raises(freq):
21602170
msg = f"Invalid frequency: {freq[1:]}"

0 commit comments

Comments
 (0)