Skip to content

Commit ba1cd18

Browse files
committed
Merge pull request pandas-dev#6824 from jreback/fillna
BUG: Regression from 0.13 with fillna and a Series on datetime-like (6344)
2 parents e2de7a3 + 4be6c58 commit ba1cd18

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ Bug Fixes
321321
- Bug with numpy < 1.7.2 when reading long strings from ``HDFStore`` (:issue:`6166`)
322322
- Bug in ``DataFrame._reduce`` where non bool-like (0/1) integers were being
323323
coverted into bools. (:issue:`6806`)
324+
- Regression from 0.13 with ``fillna`` and a Series on datetime-like (:issue:`6344`)
324325

325326
pandas 0.13.1
326327
-------------

pandas/core/internals.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def fillna(self, value, limit=None, inplace=False, downcast=None):
374374
else:
375375
return [self.copy()]
376376

377-
mask = com.isnull(self.values)
377+
mask = isnull(self.values)
378378
if limit is not None:
379379
if self.ndim > 2:
380380
raise NotImplementedError
@@ -1306,7 +1306,7 @@ def fill_value(self):
13061306

13071307
def _try_fill(self, value):
13081308
""" if we are a NaT, return the actual fill value """
1309-
if isinstance(value, type(tslib.NaT)) or isnull(value):
1309+
if isinstance(value, type(tslib.NaT)) or np.array(isnull(value)).all():
13101310
value = tslib.iNaT
13111311
elif isinstance(value, np.timedelta64):
13121312
pass
@@ -1688,7 +1688,7 @@ def fill_value(self):
16881688

16891689
def _try_fill(self, value):
16901690
""" if we are a NaT, return the actual fill value """
1691-
if isinstance(value, type(tslib.NaT)) or isnull(value):
1691+
if isinstance(value, type(tslib.NaT)) or np.array(isnull(value)).all():
16921692
value = tslib.iNaT
16931693
return value
16941694

@@ -1697,7 +1697,7 @@ def fillna(self, value, limit=None,
16971697

16981698
# straight putmask here
16991699
values = self.values if inplace else self.values.copy()
1700-
mask = com.isnull(self.values)
1700+
mask = isnull(self.values)
17011701
value = self._try_fill(value)
17021702
if limit is not None:
17031703
if self.ndim > 2:

pandas/tests/test_frame.py

+12
Original file line numberDiff line numberDiff line change
@@ -7221,6 +7221,18 @@ def test_fillna(self):
72217221
result = df.fillna(999,limit=1)
72227222
assert_frame_equal(result, expected)
72237223

7224+
# with datelike
7225+
# GH 6344
7226+
df = DataFrame({
7227+
'Date':[pd.NaT, Timestamp("2014-1-1")],
7228+
'Date2':[ Timestamp("2013-1-1"), pd.NaT]
7229+
})
7230+
7231+
expected = df.copy()
7232+
expected['Date'] = expected['Date'].fillna(df.ix[0,'Date2'])
7233+
result = df.fillna(value={'Date':df['Date2']})
7234+
assert_frame_equal(result, expected)
7235+
72247236
def test_fillna_dtype_conversion(self):
72257237
# make sure that fillna on an empty frame works
72267238
df = DataFrame(index=["A","B","C"], columns = [1,2,3,4,5])

0 commit comments

Comments
 (0)