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

can you merge master and update @manuhortet do you still want to take this on? @jreback if we don't hear back I will take this @manuhortet or @alimcmaster1 if interested pls merge master merge master and update closing as stale if you want to continue working, please ping.