Repository: pandas-dev/pandas

Issue:
fillna with datetime and value=dictlike not working on v0.13.1
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().
```



Discussion:
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]
```

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

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

welcome a PR! (its an easy fix)


Resolving patch:
diff --git a/pandas/core/internals.py b/pandas/core/internals.py
--- a/pandas/core/internals.py
+++ b/pandas/core/internals.py
@@ -374,7 +374,7 @@ def fillna(self, value, limit=None, inplace=False, downcast=None):
             else:
                 return [self.copy()]
 
-        mask = com.isnull(self.values)
+        mask = isnull(self.values)
         if limit is not None:
             if self.ndim > 2:
                 raise NotImplementedError
@@ -1306,7 +1306,7 @@ def fill_value(self):
 
     def _try_fill(self, value):
         """ if we are a NaT, return the actual fill value """
-        if isinstance(value, type(tslib.NaT)) or isnull(value):
+        if isinstance(value, type(tslib.NaT)) or np.array(isnull(value)).all():
             value = tslib.iNaT
         elif isinstance(value, np.timedelta64):
             pass
@@ -1688,7 +1688,7 @@ def fill_value(self):
 
     def _try_fill(self, value):
         """ if we are a NaT, return the actual fill value """
-        if isinstance(value, type(tslib.NaT)) or isnull(value):
+        if isinstance(value, type(tslib.NaT)) or np.array(isnull(value)).all():
             value = tslib.iNaT
         return value
 
@@ -1697,7 +1697,7 @@ def fillna(self, value, limit=None,
 
         # straight putmask here
         values = self.values if inplace else self.values.copy()
-        mask = com.isnull(self.values)
+        mask = isnull(self.values)
         value = self._try_fill(value)
         if limit is not None:
             if self.ndim > 2:


Test patch:
diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py
--- a/pandas/tests/test_frame.py
+++ b/pandas/tests/test_frame.py
@@ -7221,6 +7221,18 @@ def test_fillna(self):
         result = df.fillna(999,limit=1)
         assert_frame_equal(result, expected)
 
+        # with datelike
+        # GH 6344
+        df = DataFrame({
+            'Date':[pd.NaT, Timestamp("2014-1-1")],
+            'Date2':[ Timestamp("2013-1-1"), pd.NaT]
+            })
+
+        expected = df.copy()
+        expected['Date'] = expected['Date'].fillna(df.ix[0,'Date2'])
+        result = df.fillna(value={'Date':df['Date2']})
+        assert_frame_equal(result, expected)
+
     def test_fillna_dtype_conversion(self):
         # make sure that fillna on an empty frame works
         df = DataFrame(index=["A","B","C"], columns = [1,2,3,4,5])