DEPR: deprecate SparseArray sparse_index parameter, add from_indices#64808
Open
jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
Open
DEPR: deprecate SparseArray sparse_index parameter, add from_indices#64808jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
Conversation
9f33f13 to 5f095f4 Compare Deprecate the `sparse_index` parameter of `SparseArray.__init__` and add a new `SparseArray.from_indices` classmethod that allows constructing a SparseArray from sparse values and their indices without materializing a dense array. Migrates all internal callers of `sparse_index=` to use `_simple_new()` to avoid triggering the deprecation warning. closes pandas-dev#43628 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9c71b00 to 370f827 Compare Use sanitize_array in from_indices to ensure consistent int64 dtype inference, matching SparseArray.__init__ behavior. Also fix test_ufunc to use explicit int64 dtype for the expected array. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
sparse_indexparameter ofSparseArray.__init__with aPandas4WarningSparseArray.from_indicesclassmethod for constructing a SparseArray from sparse values + indices without materializing a dense arraysparse_index=to_simple_new()to avoid triggering the deprecationcloses #43628
Test plan
TestFromIndicesclass with tests for basic integer, float, bool, block kind, empty, explicit dtype, length mismatch, invalid indices, and deprecation warningsparse_index=to wrap withassert_produces_warning(Pandas4Warning)🤖 Generated with Claude Code