Improving function definition
- [x] closes #57305 
- [x] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
Thanks @jmarintur  Glad to help @mroeschke. Thank you for your suggestions. 