Skip to content

FIX: timeseries asfreq would drop the name of the index, closes #9854 #9884

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v0.16.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
1 change: 1 addition & 0 deletions pandas/tseries/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down