Skip to content

DEPR: deprecate non-ndarray/Series/Index x in cut and qcut#64589

Open
jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
jbrockmendel:depr-cut-types
Open

DEPR: deprecate non-ndarray/Series/Index x in cut and qcut#64589
jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
jbrockmendel:depr-cut-types

Conversation

@jbrockmendel
Copy link
Member

@jbrockmendel jbrockmendel commented Mar 14, 2026

I [human] tried annotating this earlier today and the fact that we accept basically anything here while the docstring says ndarray-or-Series annoyed me. So let's deprecate it and become strict.

Summary

  • Emit Pandas4Warning when pd.cut or pd.qcut receives an x argument that is not np.ndarray, Series, or Index (e.g. lists, tuples, ranges, ExtensionArrays)
  • Update docstrings and examples to reflect the accepted types
  • Update tests to use np.array()/np.arange()/Index() instead of bare lists/ranges

Test plan

  • All 247 existing test_cut.py and test_qcut.py tests pass
  • New test_cut_qcut_x_type_deprecation verifies warning for list, range, and tuple inputs
  • Verified no warning for ndarray, Series, and Index inputs

🤖 Generated with Claude Code

jbrockmendel and others added 4 commits March 15, 2026 07:59
Passing objects other than np.ndarray, Series, or Index as the
x argument to pd.cut or pd.qcut now emits a Pandas4Warning. This
enables stricter type annotations for these functions in the future.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update doc examples and one additional test that passed lists or
ranges as the x argument to cut, triggering the new Pandas4Warning.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fix value_counts_internal to wrap values in Index before calling cut,
avoiding the new Pandas4Warning for ExtensionArray and list inputs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jbrockmendel jbrockmendel added the Deprecate Functionality to remove in pandas label Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Deprecate Functionality to remove in pandas

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant