Skip to content

Commit 92b5b2d

Browse files
committed
addressed Jeff's comments
1 parent f4605a4 commit 92b5b2d

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ Other Enhancements
183183
- :class:`Series` and :class:`DataFrame` now support :class:`Iterable` in constructor (:issue:`2193`)
184184
- :class:`DatetimeIndex` gained :attr:`DatetimeIndex.timetz` attribute. Returns local time with timezone information. (:issue:`21358`)
185185
- :class:`Resampler` now is iterable like :class:`GroupBy` (:issue:`15314`).
186-
- Added :meth:`Resampler.quantile` (:issue:`15023`).
186+
- :ref:`Series.resample` and :ref:`DataFrame.resample` have gained the :meth:`Resampler.quantile` (:issue:`15023`).
187187

188188
.. _whatsnew_0240.api_breaking:
189189

pandas/core/groupby/groupby.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,12 @@ def var(self, ddof=1, *args, **kwargs):
11681168
"""
11691169
nv.validate_groupby_func('var', args, kwargs)
11701170
if ddof == 1:
1171-
return self._cython_agg_general('var', **kwargs)
1171+
try:
1172+
return self._cython_agg_general('var', **kwargs)
1173+
except Exception:
1174+
f = lambda x: x.var(ddof=ddof, **kwargs)
1175+
with _group_selection_context(self):
1176+
return self._python_agg_general(f)
11721177
else:
11731178
f = lambda x: x.var(ddof=ddof, **kwargs)
11741179
with _group_selection_context(self):

pandas/core/resample.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -770,11 +770,17 @@ def quantile(self, q=0.5, **kwargs):
770770
"""
771771
Return value at the given quantile.
772772
773+
.. versionadded:: 0.24.0
774+
773775
Parameters
774776
----------
775777
q : float or array-like, default 0.5 (50% quantile)
776778
777-
.. versionadded:: 0.24.0
779+
See Also
780+
--------
781+
Series.quantile
782+
DataFrame.quantile
783+
DataFrameGroupBy.quantile
778784
"""
779785
return self._downsample('quantile', q=q, **kwargs)
780786

@@ -1072,7 +1078,8 @@ def _downsample(self, how, **kwargs):
10721078

10731079
if is_subperiod(ax.freq, self.freq):
10741080
# Downsampling
1075-
return self._groupby_and_aggregate(how, grouper=self.grouper)
1081+
return self._groupby_and_aggregate(how, grouper=self.grouper,
1082+
**kwargs)
10761083
elif is_superperiod(ax.freq, self.freq):
10771084
if how == 'ohlc':
10781085
# GH #13083

pandas/tests/test_resample.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,15 @@ def test_resampler_is_iterable(self):
782782
assert rk == gk
783783
assert_series_equal(rv, gv)
784784

785+
def test_resample_quantile(self):
786+
# GH 15023
787+
s = self.create_series()
788+
q = 0.75
789+
freq = 'H'
790+
result = s.resample(freq).quantile(q)
791+
expected = s.resample(freq).agg(lambda x: x.quantile(q))
792+
tm.assert_series_equal(result, expected)
793+
785794

786795
class TestDatetimeIndex(Base):
787796
_index_factory = lambda x: date_range
@@ -2176,13 +2185,6 @@ def test_resample_datetime_values(self):
21762185
res = df['timestamp'].resample('2D').first()
21772186
tm.assert_series_equal(res, exp)
21782187

2179-
def test_resample_quantile(self):
2180-
# GH 15023
2181-
s = pd.Series(range(20), index=date_range('2016-01-01', periods=20))
2182-
result = s.resample('W').quantile(0.75)
2183-
expected = s.resample('W').agg(lambda x: x.quantile(0.75))
2184-
tm.assert_series_equal(result, expected)
2185-
21862188

21872189
class TestPeriodIndex(Base):
21882190
_index_factory = lambda x: period_range

0 commit comments

Comments
 (0)