BUG Fix: pd.apply returns a dataframe when empty dataframe instead of a series
- [ ] closes #39111
- [ ] [Tests added and passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#writing-tests) if fixing a bug or adding a new feature
- [ ] All [code checks passed](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit).
- [ ] Added an entry in the latest `doc/source/whatsnew/vX.X.X.rst` file if fixing a bug or adding a new feature.

The test looks good, but you're applying the fix in the wrong location. Maybe debugging the test code helps you identify where the empty `DataFrame` is created. Thanks @weikhor 