BUG: Copy categorical codes if empty (fixes #18051)
If `old_categories` is empty (all nan categories) then `_recode_for_categories`
should return `codes.copy()` so that the writable flag is True.

- [x] closes #18051 
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry
