Skip to content

Commit 95306d5

Browse files
committed
1 parent 9b5d848 commit 95306d5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pandas/tests/tseries/test_resample.py

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

3132
bday = BDay()
@@ -836,6 +837,14 @@ def test_resample_loffset_arg_type(self):
836837
assert_frame_equal(result_agg, expected)
837838
assert_frame_equal(result_how, expected)
838839

840+
def test_resample_empty_dataframe_with_size(self):
841+
# GH 14962
842+
df1 = pd.DataFrame(dict(a=range(100)),
843+
index=pd.date_range('1/1/2000', periods=100, freq="M"))
844+
df2 = df1[df1.a < 0]
845+
result = df2.resample("Q").size()
846+
assertIsInstance(result, pd.Series)
847+
839848

840849
class TestDatetimeIndex(Base, tm.TestCase):
841850
_index_factory = lambda x: date_range

pandas/tseries/resample.py

+4
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,10 @@ def _downsample(self, how, **kwargs):
701701
if not len(ax):
702702
# reset to the new freq
703703
obj = obj.copy()
704+
if how == "size" and isinstance(obj, pd.DataFrame):
705+
obj = obj.groupby(
706+
self.grouper, axis=self.axis).aggregate(how, **kwargs)
707+
704708
obj.index.freq = self.freq
705709
return obj
706710

0 commit comments

Comments
 (0)