Skip to content

Commit 0ec76a2

Browse files
authored
Merge branch 'main' into modify-function-signature
2 parents 2894694 + 6cb37b6 commit 0ec76a2

File tree

10 files changed

+332
-43
lines changed

10 files changed

+332
-43
lines changed

ci/code_checks.sh

-19
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
110110
pandas_object \
111111
pandas.api.interchange.from_dataframe \
112112
pandas.DatetimeIndex.snap \
113-
pandas.core.window.rolling.Rolling.max \
114-
pandas.core.window.rolling.Rolling.cov \
115-
pandas.core.window.rolling.Rolling.skew \
116-
pandas.core.window.rolling.Rolling.apply \
117-
pandas.core.window.rolling.Window.mean \
118-
pandas.core.window.rolling.Window.sum \
119-
pandas.core.window.rolling.Window.var \
120-
pandas.core.window.rolling.Window.std \
121-
pandas.core.window.expanding.Expanding.count \
122-
pandas.core.window.expanding.Expanding.sum \
123-
pandas.core.window.expanding.Expanding.mean \
124-
pandas.core.window.expanding.Expanding.median \
125-
pandas.core.window.expanding.Expanding.min \
126-
pandas.core.window.expanding.Expanding.max \
127-
pandas.core.window.expanding.Expanding.corr \
128-
pandas.core.window.expanding.Expanding.cov \
129-
pandas.core.window.expanding.Expanding.skew \
130-
pandas.core.window.expanding.Expanding.apply \
131-
pandas.core.window.expanding.Expanding.quantile \
132113
pandas.core.window.ewm.ExponentialMovingWindow.mean \
133114
pandas.core.window.ewm.ExponentialMovingWindow.sum \
134115
pandas.core.window.ewm.ExponentialMovingWindow.std \

doc/source/whatsnew/v2.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ Deprecations
296296
- Deprecated :meth:`Series.interpolate` and :meth:`DataFrame.interpolate` for object-dtype (:issue:`53631`)
297297
- Deprecated :meth:`Series.last` and :meth:`DataFrame.last` (please create a mask and filter using ``.loc`` instead) (:issue:`53692`)
298298
- Deprecated allowing arbitrary ``fill_value`` in :class:`SparseDtype`, in a future version the ``fill_value`` will need to be compatible with the ``dtype.subtype``, either a scalar that can be held by that subtype or ``NaN`` for integer or bool subtypes (:issue:`23124`)
299+
- Deprecated allowing bool dtype in :meth:`DataFrameGroupBy.quantile` and :meth:`SeriesGroupBy.quantile`, consistent with the :meth:`Series.quantile` and :meth:`DataFrame.quantile` behavior (:issue:`51424`)
299300
- Deprecated behavior of :func:`assert_series_equal` and :func:`assert_frame_equal` considering NA-like values (e.g. ``NaN`` vs ``None`` as equivalent) (:issue:`52081`)
300301
- Deprecated bytes input to :func:`read_excel`. To read a file path, use a string or path-like object. (:issue:`53767`)
301302
- Deprecated constructing :class:`SparseArray` from scalar data, pass a sequence instead (:issue:`53039`)

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def _data(self):
506506
warnings.warn(
507507
f"{type(self).__name__}._data is deprecated and will be removed in "
508508
"a future version. Use public APIs instead.",
509-
FutureWarning,
509+
DeprecationWarning,
510510
stacklevel=find_stack_level(),
511511
)
512512
return self._mgr

pandas/core/groupby/groupby.py

+11
Original file line numberDiff line numberDiff line change
@@ -4165,6 +4165,17 @@ def pre_processor(vals: ArrayLike) -> tuple[np.ndarray, DtypeObj | None]:
41654165
inference = np.dtype(np.int64)
41664166
elif is_bool_dtype(vals.dtype) and isinstance(vals, ExtensionArray):
41674167
out = vals.to_numpy(dtype=float, na_value=np.nan)
4168+
elif is_bool_dtype(vals.dtype):
4169+
# GH#51424 deprecate to match Series/DataFrame behavior
4170+
warnings.warn(
4171+
f"Allowing bool dtype in {type(self).__name__}.quantile is "
4172+
"deprecated and will raise in a future version, matching "
4173+
"the Series/DataFrame behavior. Cast to uint8 dtype before "
4174+
"calling quantile instead.",
4175+
FutureWarning,
4176+
stacklevel=find_stack_level(),
4177+
)
4178+
out = np.asarray(vals)
41684179
elif needs_i8_conversion(vals.dtype):
41694180
inference = vals.dtype
41704181
# In this case we need to delay the casting until after the

pandas/core/window/expanding.py

+149-12
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,19 @@ def aggregate(self, func, *args, **kwargs):
183183
create_section_header("Returns"),
184184
template_returns,
185185
create_section_header("See Also"),
186-
template_see_also[:-1],
186+
template_see_also,
187+
create_section_header("Examples"),
188+
dedent(
189+
"""\
190+
>>> ser = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
191+
>>> ser.expanding().count()
192+
a 1.0
193+
b 2.0
194+
c 3.0
195+
d 4.0
196+
dtype: float64
197+
"""
198+
),
187199
window_method="expanding",
188200
aggregation_description="count of non NaN observations",
189201
agg_method="count",
@@ -198,7 +210,19 @@ def count(self, numeric_only: bool = False):
198210
create_section_header("Returns"),
199211
template_returns,
200212
create_section_header("See Also"),
201-
template_see_also[:-1],
213+
template_see_also,
214+
create_section_header("Examples"),
215+
dedent(
216+
"""\
217+
>>> ser = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
218+
>>> ser.expanding().apply(lambda s: s.max() - 2 * s.min())
219+
a -1.0
220+
b 0.0
221+
c 1.0
222+
d 2.0
223+
dtype: float64
224+
"""
225+
),
202226
window_method="expanding",
203227
aggregation_description="custom aggregation function",
204228
agg_method="apply",
@@ -231,7 +255,19 @@ def apply(
231255
create_section_header("See Also"),
232256
template_see_also,
233257
create_section_header("Notes"),
234-
numba_notes[:-1],
258+
numba_notes,
259+
create_section_header("Examples"),
260+
dedent(
261+
"""\
262+
>>> ser = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
263+
>>> ser.expanding().sum()
264+
a 1.0
265+
b 3.0
266+
c 6.0
267+
d 10.0
268+
dtype: float64
269+
"""
270+
),
235271
window_method="expanding",
236272
aggregation_description="sum",
237273
agg_method="sum",
@@ -258,7 +294,19 @@ def sum(
258294
create_section_header("See Also"),
259295
template_see_also,
260296
create_section_header("Notes"),
261-
numba_notes[:-1],
297+
numba_notes,
298+
create_section_header("Examples"),
299+
dedent(
300+
"""\
301+
>>> ser = pd.Series([3, 2, 1, 4], index=['a', 'b', 'c', 'd'])
302+
>>> ser.expanding().max()
303+
a 3.0
304+
b 3.0
305+
c 3.0
306+
d 4.0
307+
dtype: float64
308+
"""
309+
),
262310
window_method="expanding",
263311
aggregation_description="maximum",
264312
agg_method="max",
@@ -285,7 +333,19 @@ def max(
285333
create_section_header("See Also"),
286334
template_see_also,
287335
create_section_header("Notes"),
288-
numba_notes[:-1],
336+
numba_notes,
337+
create_section_header("Examples"),
338+
dedent(
339+
"""\
340+
>>> ser = pd.Series([2, 3, 4, 1], index=['a', 'b', 'c', 'd'])
341+
>>> ser.expanding().min()
342+
a 2.0
343+
b 2.0
344+
c 2.0
345+
d 1.0
346+
dtype: float64
347+
"""
348+
),
289349
window_method="expanding",
290350
aggregation_description="minimum",
291351
agg_method="min",
@@ -312,7 +372,19 @@ def min(
312372
create_section_header("See Also"),
313373
template_see_also,
314374
create_section_header("Notes"),
315-
numba_notes[:-1],
375+
numba_notes,
376+
create_section_header("Examples"),
377+
dedent(
378+
"""\
379+
>>> ser = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
380+
>>> ser.expanding().mean()
381+
a 1.0
382+
b 1.5
383+
c 2.0
384+
d 2.5
385+
dtype: float64
386+
"""
387+
),
316388
window_method="expanding",
317389
aggregation_description="mean",
318390
agg_method="mean",
@@ -339,7 +411,19 @@ def mean(
339411
create_section_header("See Also"),
340412
template_see_also,
341413
create_section_header("Notes"),
342-
numba_notes[:-1],
414+
numba_notes,
415+
create_section_header("Examples"),
416+
dedent(
417+
"""\
418+
>>> ser = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
419+
>>> ser.expanding().median()
420+
a 1.0
421+
b 1.5
422+
c 2.0
423+
d 2.5
424+
dtype: float64
425+
"""
426+
),
343427
window_method="expanding",
344428
aggregation_description="median",
345429
agg_method="median",
@@ -523,7 +607,20 @@ def sem(self, ddof: int = 1, numeric_only: bool = False):
523607
"scipy.stats.skew : Third moment of a probability density.\n",
524608
template_see_also,
525609
create_section_header("Notes"),
526-
"A minimum of three periods is required for the rolling calculation.\n",
610+
"A minimum of three periods is required for the rolling calculation.\n\n",
611+
create_section_header("Examples"),
612+
dedent(
613+
"""\
614+
>>> ser = pd.Series([-1, 0, 2, -1, 2], index=['a', 'b', 'c', 'd', 'e'])
615+
>>> ser.expanding().skew()
616+
a NaN
617+
b NaN
618+
c 0.935220
619+
d 1.414214
620+
e 0.315356
621+
dtype: float64
622+
"""
623+
),
527624
window_method="expanding",
528625
aggregation_description="unbiased skewness",
529626
agg_method="skew",
@@ -597,7 +694,21 @@ def kurt(self, numeric_only: bool = False):
597694
create_section_header("Returns"),
598695
template_returns,
599696
create_section_header("See Also"),
600-
template_see_also[:-1],
697+
template_see_also,
698+
create_section_header("Examples"),
699+
dedent(
700+
"""\
701+
>>> ser = pd.Series([1, 2, 3, 4, 5, 6], index=['a', 'b', 'c', 'd', 'e', 'f'])
702+
>>> ser.expanding(min_periods=4).quantile(.25)
703+
a NaN
704+
b NaN
705+
c NaN
706+
d 1.75
707+
e 2.00
708+
f 2.25
709+
dtype: float64
710+
"""
711+
),
601712
window_method="expanding",
602713
aggregation_description="quantile",
603714
agg_method="quantile",
@@ -714,7 +825,20 @@ def rank(
714825
create_section_header("Returns"),
715826
template_returns,
716827
create_section_header("See Also"),
717-
template_see_also[:-1],
828+
template_see_also,
829+
create_section_header("Examples"),
830+
dedent(
831+
"""\
832+
>>> ser1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
833+
>>> ser2 = pd.Series([10, 11, 13, 16], index=['a', 'b', 'c', 'd'])
834+
>>> ser1.expanding().cov(ser2)
835+
a NaN
836+
b 0.500000
837+
c 1.500000
838+
d 3.333333
839+
dtype: float64
840+
"""
841+
),
718842
window_method="expanding",
719843
aggregation_description="sample covariance",
720844
agg_method="cov",
@@ -782,9 +906,22 @@ def cov(
782906
columns on the second level.
783907
784908
In the case of missing elements, only complete pairwise observations
785-
will be used.
909+
will be used.\n
786910
"""
787-
).replace("\n", "", 1),
911+
),
912+
create_section_header("Examples"),
913+
dedent(
914+
"""\
915+
>>> ser1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
916+
>>> ser2 = pd.Series([10, 11, 13, 16], index=['a', 'b', 'c', 'd'])
917+
>>> ser1.expanding().corr(ser2)
918+
a NaN
919+
b 1.000000
920+
c 0.981981
921+
d 0.975900
922+
dtype: float64
923+
"""
924+
),
788925
window_method="expanding",
789926
aggregation_description="correlation",
790927
agg_method="corr",

0 commit comments

Comments
 (0)