Skip to content

BUG: applymap on empty DataFrame returns Series #8222

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
ojdo opened this issue Sep 9, 2014 · 5 comments · Fixed by #14977
Closed

BUG: applymap on empty DataFrame returns Series #8222

ojdo opened this issue Sep 9, 2014 · 5 comments · Fixed by #14977
Labels
API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@ojdo
Copy link
Contributor

ojdo commented Sep 9, 2014

I'm unsure about a corner case I encountered:

>>> pd.DataFrame([]).applymap(round)
Series([], dtype: float64)

full example

In [1]: df = pandas.DataFrame({ 'x' : [], 'y' : [], 'z' : []})

In [2]: df
Out[2]: 
Empty DataFrame
Columns: [x, y, z]
Index: []

In [3]: df.applymap(lambda x: x)
Out[3]: 
x   NaN
y   NaN
z   NaN
dtype: float64

In [4]: df = pandas.DataFrame({ 'x' : [1], 'y' : [1], 'z' : [1]})

In [5]: df.applymap(lambda x: x)
Out[5]: 
   x  y  z
0  1  1  1

I would have expected to get the empty DataFrame back.

@jreback
Copy link
Contributor

jreback commented Sep 9, 2014

the test for reduction is on an empty Series (e.g. round(Series([])))

so maybe not that sophisticated.

pull-request welcome to fix (though maybe tricky).

@jreback jreback added API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Sep 9, 2014
@jreback jreback added this to the 0.15.1 milestone Sep 9, 2014
@stringfellow
Copy link

This is an API change from 0.12 and is not documented!

0.12:

In [1]: import pandas as pd

In [2]: df = pd.DataFrame()

In [3]: df
/Users/spike/.virtualenvs/pd_0_12/lib/python2.7/site-packages/pandas/core/config.py:570: DeprecationWarning: height has been deprecated.

  warnings.warn(d.msg, DeprecationWarning)

Out[3]:
Empty DataFrame
Columns: []
Index: []

In [4]: df.applymap(lambda x: 1)
Out[4]:
Empty DataFrame
Columns: []
Index: []

0.15:

In [1]: import pandas as pd

In [2]: df = pd.DataFrame()

In [3]: df
Out[3]:
Empty DataFrame
Columns: []
Index: []

In [4]: df.applymap(lambda x: 1)
Out[4]: Series([], dtype: float64)

@jreback
Copy link
Contributor

jreback commented Nov 7, 2014

@stringfellow well I suspect it actually changed in 0.13. Since their wasn't a test, a regression like this is very hard to detect. As I said above a pull-request to restore this behavior would be welcome.

@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 6, 2015
@ghost
Copy link

ghost commented Mar 30, 2016

I just checked this with 0.18.0 and I still get a Series back. Is this supposed to be fixed in the near future?

@jreback
Copy link
Contributor

jreback commented Mar 30, 2016

this issue is still open, pull-requests are welcome

@jreback jreback changed the title BUG: applymap on empty DataFrame returns Series - intentional? BUG: applymap on empty DataFrame returns Series Jul 25, 2016
mroeschke added a commit to mroeschke/pandas that referenced this issue Dec 24, 2016
mroeschke added a commit to mroeschke/pandas that referenced this issue Dec 24, 2016
mroeschke added a commit to mroeschke/pandas that referenced this issue Dec 24, 2016
fix whatsnew file

Adjust whatsnew to API change and add test with data
@jreback jreback modified the milestones: 0.20.0, Next Major Release Dec 24, 2016
jreback pushed a commit that referenced this issue Dec 24, 2016
fix whatsnew file

Adjust whatsnew to API change and add test with data
ShaharBental pushed a commit to ShaharBental/pandas that referenced this issue Dec 26, 2016
…ndas-dev#14977)

fix whatsnew file

Adjust whatsnew to API change and add test with data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants