Skip to content

Series.fillna doesn't work with series input #5703

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
miketkelly opened this issue Dec 15, 2013 · 8 comments · Fixed by #5705
Closed

Series.fillna doesn't work with series input #5703

miketkelly opened this issue Dec 15, 2013 · 8 comments · Fixed by #5705
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@miketkelly
Copy link

Test code:

import pandas as pd

print pd.__version__

s1 = pd.Series([np.nan])
s2 = pd.Series([1])

s1.fillna(s2)

Results:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-28706fea97bb> in <module>()
      6 s2 = pd.Series([1])
      7 
----> 8 s1.fillna(s2)

/usr/local/anaconda/lib/python2.7/site-packages/pandas-0.13.0rc1_64_gceec8bf-py2.7-linux-x86_64.egg/pandas/core/generic.pyc in fillna(self, value, method, axis, inplace, limit, downcast)
   1917                         continue
   1918                     obj = result[k]
-> 1919                     obj.fillna(v, inplace=True)
   1920                 return result
   1921             else:

AttributeError: 'numpy.float64' object has no attribute 'fillna'

0.13.0rc1-64-gceec8bf
@jreback
Copy link
Contributor

jreback commented Dec 15, 2013

yep..should prob work

@jreback
Copy link
Contributor

jreback commented Dec 15, 2013

@mtkni see PR #5705

pls lmk what you think about the 'other' cases (which were not tested in 0.12, but are possible I guess)

doesn't seem to me that passing more than 1 fillna value makes sense for a Series/dict

@miketkelly
Copy link
Author

My use case is more like the following, which requires multiple values. It worked in 0.12, so I got used to it.

s1 = pd.Series([1, 2, 3, 4, 5, 6])

# may produce missing values
s2 = do_some_calc(s1)

# fill missing values with an alternate calculation
s2 = s2.fillna(s1 - s1.mean())

@jreback
Copy link
Contributor

jreback commented Dec 16, 2013

ok so u want to match on the index and fill if it's na
ok easy enough then

that's effectively combine_first so will do exactly that

@miketkelly
Copy link
Author

Now that I look at it, what I was doing only worked because my indexes where the same.

>>> s1 = pd.Series({'a': 1, 'b': 2})
>>> s1 = pd.Series([0, 1, 2], list('abc'))
>>> s1
a    0
b    1
c    2
dtype: int64
>>> s2 = pd.Series([0, np.nan, 2], list('bac')) 
>>> s2
b     0
a   NaN
c     2
dtype: float64
>>> s2.fillna(s1)
b    0
a    1
c    2
dtype: float64

A problem with combine_first approach is that it might expand the index.

@jreback
Copy link
Contributor

jreback commented Dec 16, 2013

It seems your example above from 0.12 is wrong. This is makes sense?

In [1]: s1 = Series([0, 1, 2], list('abc'))

In [2]: s1
Out[2]: 
a    0
b    1
c    2
dtype: int64

In [3]: s2 = Series([0, np.nan, 2], list('bac'))

In [4]: s2
Out[4]: 
b     0
a   NaN
c     2
dtype: float64

In [5]: s2.fillna(s1)
Out[5]: 
b    0
a    0
c    2
dtype: float64

@miketkelly
Copy link
Author

Yes, that is the desired outcome.

@jreback
Copy link
Contributor

jreback commented Dec 16, 2013

ok gr8....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants