diff --git a/doc/source/whatsnew/v0.16.1.txt b/doc/source/whatsnew/v0.16.1.txt index 3f510ce3d44c0..e8097f45fe483 100644 --- a/doc/source/whatsnew/v0.16.1.txt +++ b/doc/source/whatsnew/v0.16.1.txt @@ -132,3 +132,5 @@ Bug Fixes - Bug in unequal comparisons between a ``Series`` of dtype `"category"` and a scalar (e.g. ``Series(Categorical(list("abc"), categories=list("cba"), ordered=True)) > "b"``, which wouldn't use the order of the categories but use the lexicographical order. (:issue:`9848`) - Bug in unequal comparisons between categorical data and a scalar, which was not in the categories (e.g. ``Series(Categorical(list("abc"), ordered=True)) > "d"``. This returned ``False`` for all elements, but now raises a ``TypeError``. Equality comparisons also now return ``False`` for ``==`` and ``True`` for ``!=``. (:issue:`9848`) + +- Bug where using DataFrames asfreq would remove the name of the index. (:issue:`9885`) diff --git a/pandas/tseries/resample.py b/pandas/tseries/resample.py index 7607bef0f1d71..1de525ee9c876 100644 --- a/pandas/tseries/resample.py +++ b/pandas/tseries/resample.py @@ -480,6 +480,7 @@ def asfreq(obj, freq, method=None, how=None, normalize=False): if len(obj.index) == 0: return obj.copy() dti = date_range(obj.index[0], obj.index[-1], freq=freq) + dti.name = obj.index.name rs = obj.reindex(dti, method=method) if normalize: rs.index = rs.index.normalize() diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 436a976c72e7e..964e8634bc1ef 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -1131,6 +1131,15 @@ def test_reindex_with_datetimes(self): result = ts[list(ts.index[5:10])] tm.assert_series_equal(result, expected) + def test_asfreq_keep_index_name(self): + # GH #9854 + index_name = 'bar' + index = pd.date_range('20130101',periods=20,name=index_name) + df = pd.DataFrame([x for x in range(20)],columns=['foo'],index=index) + + tm.assert_equal(index_name, df.index.name) + tm.assert_equal(index_name, df.asfreq('10D').index.name) + def test_promote_datetime_date(self): rng = date_range('1/1/2000', periods=20) ts = Series(np.random.randn(20), index=rng)