added check if categoricalDtype for issue #19278
Checklist for other PRs:

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