Skip to content

Commit

Permalink
Copy categorical codes if empty (fixes pandas-dev#18051)
Browse files Browse the repository at this point in the history
If `old_categories` is empty (all nan categories) then `_recode_for_categories`
should return `codes.copy()` so that the writable flag is True.
  • Loading branch information
Fariba Aalamifar committed Nov 14, 2017
1 parent ca737ac commit 5a73752
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ def _recode_for_categories(codes, old_categories, new_categories):

if len(old_categories) == 0:
# All null anyway, so just retain the nulls
return codes
return codes.copy()
indexer = coerce_indexer_dtype(new_categories.get_indexer(old_categories),
new_categories)
new_codes = take_1d(indexer, codes.copy(), fill_value=-1)
Expand Down

0 comments on commit 5a73752

Please sign in to comment.