Skip to content

Commit

Permalink
CLN: Enforce deprecation of groupby.quantile supporting bool dtype (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rhshadrach authored Mar 7, 2024
1 parent fe2ef37 commit c71244a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ Removal of prior version deprecations/changes
- In :meth:`DataFrame.stack`, the default value of ``future_stack`` is now ``True``; specifying ``False`` will raise a ``FutureWarning`` (:issue:`55448`)
- Methods ``apply``, ``agg``, and ``transform`` will no longer replace NumPy functions (e.g. ``np.sum``) and built-in functions (e.g. ``min``) with the equivalent pandas implementation; use string aliases (e.g. ``"sum"`` and ``"min"``) if you desire to use the pandas implementation (:issue:`53974`)
- Passing both ``freq`` and ``fill_value`` in :meth:`DataFrame.shift` and :meth:`Series.shift` and :meth:`.DataFrameGroupBy.shift` now raises a ``ValueError`` (:issue:`54818`)
- Removed :meth:`.DataFrameGroupBy.quantile` and :meth:`.SeriesGroupBy.quantile` supporting bool dtype (:issue:`53975`)
- Removed :meth:`DateOffset.is_anchored` and :meth:`offsets.Tick.is_anchored` (:issue:`56594`)
- Removed ``DataFrame.applymap``, ``Styler.applymap`` and ``Styler.applymap_index`` (:issue:`52364`)
- Removed ``DataFrame.bool`` and ``Series.bool`` (:issue:`51756`)
Expand Down
12 changes: 2 additions & 10 deletions pandas/core/groupby/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -4279,16 +4279,8 @@ def pre_processor(vals: ArrayLike) -> tuple[np.ndarray, DtypeObj | None]:
elif is_bool_dtype(vals.dtype) and isinstance(vals, ExtensionArray):
out = vals.to_numpy(dtype=float, na_value=np.nan)
elif is_bool_dtype(vals.dtype):
# GH#51424 deprecate to match Series/DataFrame behavior
warnings.warn(
f"Allowing bool dtype in {type(self).__name__}.quantile is "
"deprecated and will raise in a future version, matching "
"the Series/DataFrame behavior. Cast to uint8 dtype before "
"calling quantile instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
out = np.asarray(vals)
# GH#51424 remove to match Series/DataFrame behavior
raise TypeError("Cannot use quantile with bool dtype")
elif needs_i8_conversion(vals.dtype):
inference = vals.dtype
# In this case we need to delay the casting until after the
Expand Down
23 changes: 7 additions & 16 deletions pandas/tests/groupby/test_numeric_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,11 @@ def test_deprecate_numeric_only_series(dtype, groupby_func, request):
msg = "cannot be performed against 'object' dtypes"
else:
msg = "is not supported for object dtype"
warn = FutureWarning if groupby_func == "fillna" else None
warn_msg = "DataFrameGroupBy.fillna is deprecated"
with tm.assert_produces_warning(warn, match=warn_msg):
with pytest.raises(TypeError, match=msg):
method(*args)
with pytest.raises(TypeError, match=msg):
method(*args)
elif dtype is object:
warn = FutureWarning if groupby_func == "fillna" else None
warn_msg = "SeriesGroupBy.fillna is deprecated"
with tm.assert_produces_warning(warn, match=warn_msg):
result = method(*args)
with tm.assert_produces_warning(warn, match=warn_msg):
expected = expected_method(*args)
result = method(*args)
expected = expected_method(*args)
if groupby_func in obj_result:
expected = expected.astype(object)
tm.assert_series_equal(result, expected)
Expand Down Expand Up @@ -419,12 +412,10 @@ def test_deprecate_numeric_only_series(dtype, groupby_func, request):
with pytest.raises(TypeError, match=msg):
method(*args, numeric_only=True)
elif dtype == bool and groupby_func == "quantile":
msg = "Allowing bool dtype in SeriesGroupBy.quantile"
with tm.assert_produces_warning(FutureWarning, match=msg):
msg = "Cannot use quantile with bool dtype"
with pytest.raises(TypeError, match=msg):
# GH#51424
result = method(*args, numeric_only=True)
expected = method(*args, numeric_only=False)
tm.assert_series_equal(result, expected)
method(*args, numeric_only=False)
else:
result = method(*args, numeric_only=True)
expected = method(*args, numeric_only=False)
Expand Down

0 comments on commit c71244a

Please sign in to comment.