Skip to content

Commit f73a3da

Browse files
committed
Updated tests for resampling of empty dataframes
1 parent 082c320 commit f73a3da

File tree

4 files changed

+8
-19
lines changed

4 files changed

+8
-19
lines changed

doc/source/whatsnew/v0.20.0.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,6 @@ Groupby/Resample/Rolling
16851685
- Bug in ``.rolling()`` where ``pd.Timedelta`` or ``datetime.timedelta`` was not accepted as a ``window`` argument (:issue:`15440`)
16861686
- Bug in ``Rolling.quantile`` function that caused a segmentation fault when called with a quantile value outside of the range [0, 1] (:issue:`15463`)
16871687
- Bug in ``DataFrame.resample().median()`` if duplicate column names are present (:issue:`14233`)
1688-
- Bug in ``resample().size()``. Inconsistent return type on resample of empty DataFrame (:issue:`14962`)
16891688

16901689
Sparse
16911690
^^^^^^

doc/source/whatsnew/v0.21.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Plotting
112112

113113
Groupby/Resample/Rolling
114114
^^^^^^^^^^^^^^^^^^^^^^^^
115+
- Bug in ``resample().size()``. Inconsistent return type on resample of empty DataFrame (:issue:`14962`)
115116

116117

117118

pandas/core/resample.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pandas.core.indexes.period import PeriodIndex, period_range
1818
import pandas.core.common as com
1919
import pandas.core.algorithms as algos
20-
from pandas.types.generic import ABCDataFrame
20+
from pandas.core.dtypes.generic import ABCDataFrame
2121

2222
import pandas.compat as compat
2323
from pandas.compat.numpy import function as nv
@@ -706,7 +706,7 @@ def _downsample(self, how, **kwargs):
706706
# reset to the new freq
707707
obj = obj.copy()
708708
obj.index.freq = self.freq
709-
return self._wrap_result(obj)
709+
return obj
710710

711711
# do we have a regular frequency
712712
if ax.freq is not None or ax.inferred_freq is not None:
@@ -777,7 +777,6 @@ def _wrap_result(self, result):
777777
# convert if needed
778778
if self.kind == 'period' and not isinstance(result.index, PeriodIndex):
779779
result.index = result.index.to_period(self.freq)
780-
781780
return result
782781

783782

pandas/tests/test_resample.py

+5-15
Original file line numberDiff line numberDiff line change
@@ -773,18 +773,8 @@ def test_resample_empty_series(self):
773773
expected = s.copy()
774774
expected.index = s.index._shallow_copy(freq=freq)
775775
assert_index_equal(result.index, expected.index)
776-
777-
self.assertEqual(result.index.freq, expected.index.freq)
778-
779-
if (method == 'size' and
780-
isinstance(result.index, PeriodIndex) and
781-
freq in ['M', 'D']):
782-
# GH12871 - TODO: name should propagate, but currently
783-
# doesn't on lower / same frequency with PeriodIndex
784-
assert_series_equal(result, expected, check_dtype=False)
785-
786-
else:
787-
assert_series_equal(result, expected, check_dtype=False)
776+
assert result.index.freq == expected.index.freq
777+
assert_series_equal(result, expected, check_dtype=False)
788778

789779
def test_resample_empty_dataframe(self):
790780
# GH13212
@@ -798,16 +788,16 @@ def test_resample_empty_dataframe(self):
798788
result = getattr(f.resample(freq), method)()
799789
if method != 'size':
800790
expected = f.copy()
801-
assert_equal = assert_frame_equal
791+
assert_type_equal = assert_frame_equal
802792
else:
803793
# GH14962
804794
expected = Series([])
805-
assert_equal = assert_series_equal
795+
assert_type_equal = assert_series_equal
806796

807797
expected.index = f.index._shallow_copy(freq=freq)
808798
assert_index_equal(result.index, expected.index)
809799
assert result.index.freq == expected.index.freq
810-
assert_frame_equal(result, expected, check_dtype=False)
800+
assert_type_equal(result, expected, check_dtype=False)
811801

812802
# test size for GH13212 (currently stays as df)
813803

0 commit comments

Comments
 (0)