REG: dont call func on empty input
- [x] closes #31760
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Could use confirmation from OP that this does in fact close #31760.
thanks @jbrockmendel 