Skip to content

Commit 384e666

Browse files
committed
BUG: Set frequency for empty Series
Add test to verify frequency for empty series Update 0.19.1 whatsnew doc Fix linting; exceeded number of characters on one line Improve tests, add assertion for PeriodIndex as well Refactor tests and move to correct file Move changelog entry from 0.19.1 to 0.20.0
1 parent 211ecd5 commit 384e666

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+4
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ Bug Fixes
598598

599599

600600
- Bug in the display of ``.info()`` where a qualifier (+) would always be displayed with a ``MultiIndex`` that contains only non-strings (:issue:`15245`)
601+
602+
- Bug in ``DataFrame.loc`` with indexing a ``MultiIndex`` with a ``Series`` indexer (:issue:`14730`)
603+
- Bug in ``asfreq``, where frequency wasn't set for empty Series (:issue:`14320`)
604+
601605
- Bug in ``pd.read_msgpack()`` in which ``Series`` categoricals were being improperly processed (:issue:`14901`)
602606
- Bug in ``Series.ffill()`` with mixed dtypes containing tz-aware datetimes. (:issue:`14956`)
603607

pandas/tests/frame/test_timeseries.py

+8
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ def test_asfreq_fillvalue(self):
398398
actual_series = ts.asfreq(freq='1S', fill_value=9.0)
399399
assert_series_equal(expected_series, actual_series)
400400

401+
def test_asfreq_datetimeindex_empty_series(self):
402+
# GH 14340
403+
expected = Series(index=pd.DatetimeIndex(
404+
["2016-09-29 11:00"])).asfreq('H')
405+
result = Series(index=pd.DatetimeIndex(["2016-09-29 11:00"]),
406+
data=[3]).asfreq('H')
407+
self.assert_index_equal(expected.index, result.index)
408+
401409
def test_first_last_valid(self):
402410
N = len(self.frame.index)
403411
mat = randn(N)

pandas/tseries/resample.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,10 @@ def asfreq(obj, freq, method=None, how=None, normalize=False, fill_value=None):
13881388
return new_obj
13891389
else:
13901390
if len(obj.index) == 0:
1391-
return obj.copy()
1391+
new_index = obj.index._shallow_copy(freq=to_offset(freq))
1392+
new_obj = obj.copy()
1393+
new_obj.index = new_index
1394+
return new_obj
13921395
dti = date_range(obj.index[0], obj.index[-1], freq=freq)
13931396
dti.name = obj.index.name
13941397
rs = obj.reindex(dti, method=method, fill_value=fill_value)

0 commit comments

Comments
 (0)