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

Comments

@craustin
Copy link

commented Nov 18, 2011

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

commented Nov 18, 2011

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

@wesm

This comment has been minimized.

Copy link
Member

commented Nov 18, 2011

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

@craustin

This comment has been minimized.

Copy link
Author

commented Nov 18, 2011

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

This comment has been minimized.

Copy link
Member

commented Nov 22, 2011

fixed this and added tests in the above commit

@wesm wesm closed this Nov 22, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.