8000 BUG: reindex would throw when a categorical index was empty #16770 by ri938 · Pull Request #16820 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: reindex would throw when a categorical index was empty #16770 #16820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 18 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor correction to previous submit
  • Loading branch information
ri938 committed Jul 8, 2017
commit 7acc09f226b25fd864c64a95c65cb719257e0b49
2 changes: 1 addition & 1 deletion pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def reindex(self, target, method=None, level=None, limit=None,

indexer, missing = self.get_indexer_non_unique(np.array(target))

if len(indexer):
if len(self.codes):
Copy link
Contributor

Choose a reason for hiding this comment

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

if len(indexer)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the case the target is [1] say and the categorical index is empty then indexer here will be [-1] so not empty. The error occurs when try to run take on the empty underlying index.

Copy link
Contributor

Choose a reason for hiding this comment

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

right its missing, so ok then.

new_target = self.take(indexer)
else:
new_target = target
Expand Down
0