Skip to content

Commit f9b9cb5

Browse files
committed
FIX: timeseries asfreq would drop the name of the index, closes #9854
1 parent 9b6c774 commit f9b9cb5

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

doc/source/whatsnew/v0.16.1.txt

+2
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,5 @@ Bug Fixes
123123
- Bug in which ``SparseDataFrame`` could not take `nan` as a column name (:issue:`8822`)
124124

125125
- 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`)
126+
127+
- Bug where using DataFrames asfreq would remove the name of the index. (:issue:`9885`)

pandas/tseries/resample.py

+1
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ def asfreq(obj, freq, method=None, how=None, normalize=False):
480480
if len(obj.index) == 0:
481481
return obj.copy()
482482
dti = date_range(obj.index[0], obj.index[-1], freq=freq)
483+
dti.name = obj.index.name
483484
rs = obj.reindex(dti, method=method)
484485
if normalize:
485486
rs.index = rs.index.normalize()

pandas/tseries/tests/test_timeseries.py

+9
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,15 @@ def test_reindex_with_datetimes(self):
11311131
result = ts[list(ts.index[5:10])]
11321132
tm.assert_series_equal(result, expected)
11331133

1134+
def test_asfreq_keep_index_name(self):
1135+
# GH #9854
1136+
index_name = 'bar'
1137+
index = pd.date_range('20130101',periods=20,name=index_name)
1138+
df = pd.DataFrame([x for x in range(20)],columns=['foo'],index=index)
1139+
1140+
tm.assert_equal(index_name, df.index.name)
1141+
tm.assert_equal(index_name, df.asfreq('10D').index.name)
1142+
11341143
def test_promote_datetime_date(self):
11351144
rng = date_range('1/1/2000', periods=20)
11361145
ts = Series(np.random.randn(20), index=rng)

0 commit comments

Comments
 (0)