Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataFrame.apply returns Series #389

Closed
craustin opened this issue Nov 18, 2011 · 5 comments
Closed

DataFrame.apply returns Series #389

craustin opened this issue Nov 18, 2011 · 5 comments
Labels
Milestone

Comments

@craustin
Copy link

from pandas import DataFrame, DateRange
dr = DateRange('2011-11-01','2011-11-15')
df = DataFrame(index=dr)
df_or_so_youd_think = df.apply(lambda x:x)
print df_or_so_youd_think

This returns an empty Series.

@wesm
Copy link
Member

wesm commented Nov 18, 2011

It's kind of unclear what to do here-- should you pass an empty Series to the passed function to see if the function is a reduction or not? I literally just tinkered with this yesterday

@craustin
Copy link
Author

I think you'd pass an empty series to the function. What option would you favor?

@wesm
Copy link
Member

wesm commented Nov 18, 2011

Seems like a reasonable route. Maybe should raise an exception if it can't figure things out

@craustin
Copy link
Author

Yeah, I haven't seen the underlying code. It just seems that if DataFrame.apply is called on an empty DataFrame and the lambda returns a Series when given an empty Series, the result should be an empty DataFrame. If the lambda returns a scalar, it would make sense the result is an empty Series. Unless I misunderstand apply.

I know this is a pretty degenerate case... and we could work around it - but thanks for thinking about it!

@wesm
Copy link
Member

wesm commented Nov 22, 2011

fixed this and added tests in the above commit

@wesm wesm closed this as completed Nov 22, 2011
dan-nadler pushed a commit to dan-nadler/pandas that referenced this issue Sep 23, 2019
Renaming libraries within a database/namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants