Skip to content

Commit f5e7b89

Browse files
jbrockmendelim-vinicius
authored and
im-vinicius
committed
DEPR: GroupBy.quantile with bool dtype (pandas-dev#53975)
1 parent bbfa28f commit f5e7b89

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

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/groupby/groupby.py

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

pandas/tests/groupby/test_function.py

+7
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,13 @@ def test_deprecate_numeric_only_series(dtype, groupby_func, request):
15891589
)
15901590
with pytest.raises(TypeError, match=msg):
15911591
method(*args, numeric_only=True)
1592+
elif dtype == bool and groupby_func == "quantile":
1593+
msg = "Allowing bool dtype in SeriesGroupBy.quantile"
1594+
with tm.assert_produces_warning(FutureWarning, match=msg):
1595+
# GH#51424
1596+
result = method(*args, numeric_only=True)
1597+
expected = method(*args, numeric_only=False)
1598+
tm.assert_series_equal(result, expected)
15921599
else:
15931600
result = method(*args, numeric_only=True)
15941601
expected = method(*args, numeric_only=False)

0 commit comments

Comments
 (0)