Skip to content

Commit af1f222

Browse files
committed
DEPR: add deprecate_numeric_only_none helper (warn on numeric_only=None during 2.x)\n\nAdds a centralized helper that emits a PandasFutureWarning for numeric_only=None to support a warn-first migration (GH#53098).
1 parent 7c43c70 commit af1f222

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pandas/util/_validators.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ def validate_bool_kwarg(
269269
return value
270270

271271

272+
# deprecate_numeric_only_none defined later in file
273+
274+
272275
def validate_fillna_kwargs(value, method, validate_scalar_dict_value: bool = True):
273276
"""
274277
Validate the keyword arguments to 'fillna'.
@@ -341,6 +344,31 @@ def validate_percentile(q: float | Iterable[float]) -> np.ndarray:
341344
return q_arr
342345

343346

347+
def deprecate_numeric_only_none(value: BoolishNoneT, arg_name: str) -> BoolishNoneT:
348+
"""
349+
Deprecation helper for the "numeric_only" argument when value is None.
350+
351+
If ``value`` is ``None``, emit a PandasFutureWarning indicating that
352+
passing ``None`` for ``numeric_only`` is deprecated and will be an error
353+
in a future version. Return the input value unchanged.
354+
355+
This helper allows a warn-first / error-later migration strategy during
356+
the 2.x release cycle: callers can call this to warn users for now, and
357+
later releases should enforce strict bool-only semantics.
358+
"""
359+
import warnings
360+
361+
from pandas import errors
362+
363+
if value is None:
364+
msg = (
365+
f'Passing None for "{arg_name}" is deprecated and will raise a '
366+
"ValueError in a future version; please pass True or False."
367+
)
368+
warnings.warn(msg, errors.PandasFutureWarning, stacklevel=2)
369+
return value
370+
371+
344372
@overload
345373
def validate_ascending(ascending: BoolishT) -> BoolishT: ...
346374

0 commit comments

Comments
 (0)