Skip to content

Commit c354374

Browse files
committed
BUG: Fix #61222: Keep index name when resampling with pyarrow dtype
1 parent 04356be commit c354374

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
@@ -784,6 +784,7 @@ Groupby/resample/rolling
784784
- Bug in :meth:`Rolling.apply` for ``method="table"`` where column order was not being respected due to the columns getting sorted by default. (:issue:`59666`)
785785
- Bug in :meth:`Rolling.apply` where the applied function could be called on fewer than ``min_period`` periods if ``method="table"``. (:issue:`58868`)
786786
- Bug in :meth:`Series.resample` could raise when the the date range ended shortly before a non-existent time. (:issue:`58380`)
787+
- Bug in :meth:`DataFrame.resample` and `Series.resample` were not keeping the index name when the index had :class:`pyarrow` datetime dtype (:issue:`61222`)
787788

788789
Reshaping
789790
^^^^^^^^^

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)