BUG: pd.DataFrame.transform recursively loops in some cases #34224
- [x] closes #34224 
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry

Error handling within try/except in aggregate function of frame.py file
