Skip to content

Commit 5a73752

Browse files
author
Fariba Aalamifar
committed
Copy categorical codes if empty (fixes pandas-dev#18051)
If `old_categories` is empty (all nan categories) then `_recode_for_categories` should return `codes.copy()` so that the writable flag is True.
1 parent ca737ac commit 5a73752

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pandas/core/categorical.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ def _recode_for_categories(codes, old_categories, new_categories):
22792279

22802280
if len(old_categories) == 0:
22812281
# All null anyway, so just retain the nulls
2282-
return codes
2282+
return codes.copy()
22832283
indexer = coerce_indexer_dtype(new_categories.get_indexer(old_categories),
22842284
new_categories)
22852285
new_codes = take_1d(indexer, codes.copy(), fill_value=-1)

0 commit comments

Comments
 (0)