Skip to content

Commit b717b4e

Browse files
committed
BUG #14962
1 parent 0fe491d commit b717b4e

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
@@ -686,6 +686,10 @@ def _downsample(self, how, **kwargs):
686686
if not len(ax):
687687
# reset to the new freq
688688
obj = obj.copy()
689+
if how == "size" and isinstance(obj, pd.DataFrame):
690+
obj = obj.groupby(
691+
self.grouper, axis=self.axis).aggregate(how, **kwargs)
692+
689693
obj.index.freq = self.freq
690694
return obj
691695

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()
@@ -806,6 +807,14 @@ def test_resample_loffset_arg_type(self):
806807
assert_frame_equal(result_agg, expected)
807808
assert_frame_equal(result_how, expected)
808809

810+
def test_resample_empty_dataframe_with_size(self):
811+
# GH 14962
812+
df1 = pd.DataFrame(dict(a=range(100)),
813+
index=pd.date_range('1/1/2000', periods=100, freq="M"))
814+
df2 = df1[df1.a < 0]
815+
result = df2.resample("Q").size()
816+
assertIsInstance(result, pd.Series)
817+
809818

810819
class TestDatetimeIndex(Base, tm.TestCase):
811820
_multiprocess_can_split_ = True

0 commit comments

Comments
 (0)