Skip to content

Commit c1d7dd6

Browse files
committed
1 parent be3f2ae commit c1d7dd6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pandas/tseries/resample.py

+4
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,10 @@ def _downsample(self, how, **kwargs):
699699
if not len(ax):
700700
# reset to the new freq
701701
obj = obj.copy()
702+
if how == "size" and isinstance(obj, pd.DataFrame):
703+
obj = obj.groupby(
704+
self.grouper, axis=self.axis).aggregate(how, **kwargs)
705+
702706
obj.index.freq = self.freq
703707
return obj
704708

pandas/tseries/tests/test_resample.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
DatetimeIndexResampler)
2727
from pandas.tseries.tdi import timedelta_range, TimedeltaIndex
2828
from pandas.util.testing import (assert_series_equal, assert_almost_equal,
29-
assert_frame_equal, assert_index_equal)
29+
assert_frame_equal, assert_index_equal,
30+
assertIsInstance)
3031
from pandas._period import IncompatibleFrequency
3132

3233
bday = BDay()
@@ -824,6 +825,14 @@ def test_resample_loffset_arg_type(self):
824825
assert_frame_equal(result_agg, expected)
825826
assert_frame_equal(result_how, expected)
826827

828+
def test_resample_empty_dataframe_with_size(self):
829+
# GH 14962
830+
df1 = pd.DataFrame(dict(a=range(100)),
831+
index=pd.date_range('1/1/2000', periods=100, freq="M"))
832+
df2 = df1[df1.a < 0]
833+
result = df2.resample("Q").size()
834+
assertIsInstance(result, pd.Series)
835+
827836

828837
class TestDatetimeIndex(Base, tm.TestCase):
829838
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)