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

fillna with datetime and value=dictlike not working on v0.13.1 #6344

Closed
cancan101 opened this issue Feb 13, 2014 · 4 comments · Fixed by #6824
Closed

fillna with datetime and value=dictlike not working on v0.13.1 #6344

cancan101 opened this issue Feb 13, 2014 · 4 comments · Fixed by #6824
Assignees
Labels
Bug Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Timeseries
Milestone

Comments

@cancan101
Copy link
Contributor

I believe that this worked on v0.13:

df = pd.DataFrame({
              'Date':[pd.NaT, pd.Timestamp("2014-1-1")],
              'Date2':[ pd.Timestamp("2013-1-1"),pd.NaT]
              })

In [8]: df.fillna(value={'Date':df['Date2']})

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-d5273c4f5a7f> in <module>()
----> 1 df.fillna(value={'Date':df['Date2']})

/usr/lib64/python2.7/site-packages/pandas/core/generic.py in fillna(self, value, method, axis, inplace, limit, downcast)
   2172                         continue
   2173                     obj = result[k]
-> 2174                     obj.fillna(v, inplace=True)
   2175                 return result
   2176             else:

/usr/lib64/python2.7/site-packages/pandas/core/generic.py in fillna(self, value, method, axis, inplace, limit, downcast)
   2159 
   2160                 new_data = self._data.fillna(value, inplace=inplace,
-> 2161                                              downcast=downcast)
   2162 
   2163             elif isinstance(value, (dict, com.ABCSeries)):

/usr/lib64/python2.7/site-packages/pandas/core/internals.py in fillna(self, *args, **kwargs)
   2408 
   2409     def fillna(self, *args, **kwargs):
-> 2410         return self.apply('fillna', *args, **kwargs)
   2411 
   2412     def downcast(self, *args, **kwargs):

/usr/lib64/python2.7/site-packages/pandas/core/internals.py in apply(self, f, *args, **kwargs)
   2373 
   2374             else:
-> 2375                 applied = getattr(blk, f)(*args, **kwargs)
   2376 
   2377             if isinstance(applied, list):

/usr/lib64/python2.7/site-packages/pandas/core/internals.py in fillna(self, value, inplace, downcast)
   1633         values = self.values if inplace else self.values.copy()
   1634         mask = com.isnull(self.values)
-> 1635         value = self._try_fill(value)
   1636         np.putmask(values, mask, value)
   1637         return [self if inplace else

/usr/lib64/python2.7/site-packages/pandas/core/internals.py in _try_fill(self, value)
   1625     def _try_fill(self, value):
   1626         """ if we are a NaT, return the actual fill value """
-> 1627         if isinstance(value, type(tslib.NaT)) or isnull(value):
   1628             value = tslib.iNaT
   1629         return value

/usr/lib64/python2.7/site-packages/pandas/core/generic.py in __nonzero__(self)
    674         raise ValueError("The truth value of a {0} is ambiguous. "
    675                          "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
--> 676                          .format(self.__class__.__name__))
    677 
    678     __bool__ = __nonzero__

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
@jreback
Copy link
Contributor

jreback commented Feb 13, 2014

This works

In [22]: df.fillna(Timestamp('20120101'))
Out[22]: 
        Date      Date2
0 2012-01-01 2013-01-01
1 2014-01-01 2012-01-01

[2 rows x 2 columns]

@cancan101
Copy link
Contributor Author

Okay, but I only want to fill the column labeled Date with the corresponding value from the column Date2.

@cancan101
Copy link
Contributor Author

AH okay. Yes, the title of the bug is not specific enough.

@jreback jreback added this to the 0.14.0 milestone Feb 13, 2014
@jreback
Copy link
Contributor

jreback commented Feb 13, 2014

welcome a PR! (its an easy fix)

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 Timeseries
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants