diff --git a/doc/source/whatsnew/v0.20.0.txt b/doc/source/whatsnew/v0.20.0.txt index dca4f890e496b..90125714fba76 100644 --- a/doc/source/whatsnew/v0.20.0.txt +++ b/doc/source/whatsnew/v0.20.0.txt @@ -598,6 +598,10 @@ Bug Fixes - Bug in the display of ``.info()`` where a qualifier (+) would always be displayed with a ``MultiIndex`` that contains only non-strings (:issue:`15245`) + +- Bug in ``DataFrame.loc`` with indexing a ``MultiIndex`` with a ``Series`` indexer (:issue:`14730`) +- Bug in ``asfreq``, where frequency wasn't set for empty Series (:issue:`14320`) + - Bug in ``pd.read_msgpack()`` in which ``Series`` categoricals were being improperly processed (:issue:`14901`) - Bug in ``Series.ffill()`` with mixed dtypes containing tz-aware datetimes. (:issue:`14956`) diff --git a/pandas/tests/frame/test_timeseries.py b/pandas/tests/frame/test_timeseries.py index 862f76b4ecc05..27b427f7a22de 100644 --- a/pandas/tests/frame/test_timeseries.py +++ b/pandas/tests/frame/test_timeseries.py @@ -398,6 +398,14 @@ def test_asfreq_fillvalue(self): actual_series = ts.asfreq(freq='1S', fill_value=9.0) assert_series_equal(expected_series, actual_series) + def test_asfreq_datetimeindex_empty_series(self): + # GH 14340 + expected = Series(index=pd.DatetimeIndex( + ["2016-09-29 11:00"])).asfreq('H') + result = Series(index=pd.DatetimeIndex(["2016-09-29 11:00"]), + data=[3]).asfreq('H') + self.assert_index_equal(expected.index, result.index) + def test_first_last_valid(self): N = len(self.frame.index) mat = randn(N) diff --git a/pandas/tseries/resample.py b/pandas/tseries/resample.py index 75e550a065fd2..41511550c0949 100755 --- a/pandas/tseries/resample.py +++ b/pandas/tseries/resample.py @@ -1388,7 +1388,10 @@ def asfreq(obj, freq, method=None, how=None, normalize=False, fill_value=None): return new_obj else: if len(obj.index) == 0: - return obj.copy() + new_index = obj.index._shallow_copy(freq=to_offset(freq)) + new_obj = obj.copy() + new_obj.index = new_index + return new_obj dti = date_range(obj.index[0], obj.index[-1], freq=freq) dti.name = obj.index.name rs = obj.reindex(dti, method=method, fill_value=fill_value)