Skip to content

Commit e828347

Browse files
committed
BUG: Set frequency for empty Series
Add test to verify frequency for empty series Update 0.19.1 whatsnew doc
1 parent 096d886 commit e828347

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

doc/source/whatsnew/v0.19.1.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,7 @@ Bug Fixes
8080

8181

8282
- Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns``
83-
is not scalar and ``values`` is not specified (:issue:`14380`)
83+
is not scalar and ``values`` is not specified (:issue:`14380`)
84+
- Bug in ``pd.pivot_table`` may raise ``TypeError`` or ``ValueError`` when ``index`` or ``columns``
85+
is not scalar and ``values`` is not specified (:issue:`14380`)
86+
- Bug in ``asfreq``, where frequency wasn't set for empty Series (:issue:`14320`)

pandas/tests/frame/test_timeseries.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ def test_asfreq_datetimeindex(self):
323323
ts = df['A'].asfreq('B')
324324
tm.assertIsInstance(ts.index, DatetimeIndex)
325325

326+
def test_asfreq_datetimeindex_empty_series(self):
327+
# GH 14340
328+
empty = Series(index=pd.DatetimeIndex([])).asfreq('H')
329+
normal = Series(index=pd.DatetimeIndex(["2016-09-29 11:00"]), data=[3]).asfreq('H')
330+
self.assertEqual(empty.index.freq, normal.index.freq)
331+
326332
def test_first_last_valid(self):
327333
N = len(self.frame.index)
328334
mat = randn(N)

pandas/tseries/resample.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,10 @@ def asfreq(obj, freq, method=None, how=None, normalize=False):
13441344
return new_obj
13451345
else:
13461346
if len(obj.index) == 0:
1347-
return obj.copy()
1347+
new_index = obj.index._shallow_copy(freq=to_offset(freq))
1348+
new_obj = obj.copy()
1349+
new_obj.index = new_index
1350+
return new_obj
13481351
dti = date_range(obj.index[0], obj.index[-1], freq=freq)
13491352
dti.name = obj.index.name
13501353
rs = obj.reindex(dti, method=method)

0 commit comments

Comments
 (0)