Skip to content

BUG: fix sort_index with level keyword on single-level RangeIndex#64387

Open
jQuinRivero wants to merge 3 commits intopandas-dev:mainfrom
jQuinRivero:fix/sort-index-rangeindex-level-64383
Open

BUG: fix sort_index with level keyword on single-level RangeIndex#64387
jQuinRivero wants to merge 3 commits intopandas-dev:mainfrom
jQuinRivero:fix/sort-index-rangeindex-level-64383

Conversation

@jQuinRivero
Copy link
Contributor

DataFrame.sort_index and Series.sort_index raise an AssertionError when
called with the level keyword on a single-level RangeIndex. This happens
because RangeIndex.sort_values(return_indexer=True) returns a RangeIndex as
the indexer instead of a NumPy array, which then fails an assertion in
BlockManager.reindex_indexer.

The fix converts the indexer to a NumPy array in get_indexer_indexer when
sortlevel returns a RangeIndex.

na_position=na_position,
)
if isinstance(indexer, ABCRangeIndex):
indexer = indexer._data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a fastpath available if we know the indexer is a RangeIndex?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: DataFrame.sort_index does fails with AssertionError

3 participants