Skip to content

pandas.Series.apply fails with IndexError with an empty series #2815

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

Closed
lesteve opened this issue Feb 8, 2013 · 1 comment
Closed

pandas.Series.apply fails with IndexError with an empty series #2815

lesteve opened this issue Feb 8, 2013 · 1 comment
Labels
Milestone

Comments

@lesteve
Copy link
Contributor

lesteve commented Feb 8, 2013

import pandas as pd
s = pd.Series()
s.apply(lambda x: x)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-3-a33a9027c226> in <module>()
----> 1 s.apply(lambda x: x)

/usr/local/lib/python2.7/dist-packages/pandas/core/series.pyc in apply(self, func, convert_dtype, args, **kwds)
   2295 
   2296         mapped = lib.map_infer(values, f, convert=convert_dtype)
-> 2297         if isinstance(mapped[0], Series):
   2298             from pandas.core.frame import DataFrame
   2299             return DataFrame(mapped.tolist(), index=self.index)

IndexError: index out of bounds

This happens since 0.10.0 because of the new feature which upcasts the returned object to a dataframe if the function passed as the func argument returns a Series.

@changhiskhan
Copy link
Contributor

Returns new empty Series if self has len 0

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