diff --git a/doc/source/whatsnew/v0.17.0.txt b/doc/source/whatsnew/v0.17.0.txt index d59b6120163ff..3c89bb3b78c07 100644 --- a/doc/source/whatsnew/v0.17.0.txt +++ b/doc/source/whatsnew/v0.17.0.txt @@ -348,8 +348,7 @@ Bug Fixes - Bug in ``ExcelReader`` when worksheet is empty (:issue:`6403`) - Bug in ``Table.select_column`` where name is not preserved (:issue:`10392`) - Bug in ``offsets.generate_range`` where ``start`` and ``end`` have finer precision than ``offset`` (:issue:`9907`) - - +- Bug in ``pd.rolling_*`` where ``Series.name`` would be lost in the output (:issue:`10565`) diff --git a/pandas/stats/moments.py b/pandas/stats/moments.py index 41a768783b1cb..586d507b27493 100644 --- a/pandas/stats/moments.py +++ b/pandas/stats/moments.py @@ -426,7 +426,7 @@ def _process_data_structure(arg, kill_inf=True): values = arg.values elif isinstance(arg, Series): values = arg.values - return_hook = lambda v: Series(v, arg.index) + return_hook = lambda v: Series(v, arg.index, name=arg.name) else: return_hook = lambda v: v values = arg diff --git a/pandas/stats/tests/test_moments.py b/pandas/stats/tests/test_moments.py index a0e4d5663fde9..1741676abf773 100644 --- a/pandas/stats/tests/test_moments.py +++ b/pandas/stats/tests/test_moments.py @@ -725,6 +725,14 @@ def test_ewma_halflife_arg(self): self.assertRaises(Exception, mom.ewma, self.arr, com=9.5, span=20, halflife=50) self.assertRaises(Exception, mom.ewma, self.arr) + def test_moment_preserve_series_name(self): + # GH 10565 + s = Series(np.arange(100), name='foo') + s2 = mom.rolling_mean(s, 30) + s3 = mom.rolling_sum(s, 20) + self.assertEqual(s2.name, 'foo') + self.assertEqual(s3.name, 'foo') + def test_ew_empty_arrays(self): arr = np.array([], dtype=np.float64)