Inconsistent behaviour when apply() used on categorical with NaN values

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