DEPR: deprecate non-ndarray/Series/Index x in cut and qcut#64589
Open
jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
Open
DEPR: deprecate non-ndarray/Series/Index x in cut and qcut#64589jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
Conversation
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>
5d91bd6 to
8cc1db4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Pandas4Warningwhenpd.cutorpd.qcutreceives anxargument that is notnp.ndarray,Series, orIndex(e.g. lists, tuples, ranges, ExtensionArrays)np.array()/np.arange()/Index()instead of bare lists/rangesTest plan
test_cut.pyandtest_qcut.pytests passtest_cut_qcut_x_type_deprecationverifies warning for list, range, and tuple inputs🤖 Generated with Claude Code