Skip to content

DEPR: deprecate SparseArray sparse_index parameter, add from_indices#64808

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

DEPR: deprecate SparseArray sparse_index parameter, add from_indices#64808
jbrockmendel wants to merge 4 commits intopandas-dev:mainfrom
jbrockmendel:depr-43628

Conversation

@jbrockmendel
Copy link
Member

Summary

  • Deprecate the sparse_index parameter of SparseArray.__init__ with a Pandas4Warning
  • Add SparseArray.from_indices classmethod for constructing a SparseArray from sparse values + indices without materializing a dense array
  • Migrate all internal callers of sparse_index= to _simple_new() to avoid triggering the deprecation

closes #43628

Test plan

  • Added TestFromIndices class with tests for basic integer, float, bool, block kind, empty, explicit dtype, length mismatch, invalid indices, and deprecation warning
  • Updated existing tests that pass sparse_index= to wrap with assert_produces_warning(Pandas4Warning)
  • Full sparse test suite (1603 tests) passes
  • Pre-commit hooks pass

🤖 Generated with Claude Code

@jbrockmendel jbrockmendel added the Deprecate Functionality to remove in pandas label Mar 23, 2026
@jbrockmendel jbrockmendel force-pushed the depr-43628 branch 2 times, most recently from 9f33f13 to 5f095f4 Compare March 24, 2026 17:45
@jbrockmendel jbrockmendel marked this pull request as ready for review March 24, 2026 17:47
jbrockmendel and others added 3 commits March 24, 2026 16:02
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>
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>
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

1 participant