Skip to content

Commit e32f7b0

Browse files
committed
fixup timedelta fillna
1 parent 9acacce commit e32f7b0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pandas/core/internals.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ def fillna(self, value, limit=None, inplace=False, downcast=None,
386386
# fillna, but if we cannot coerce, then try again as an ObjectBlock
387387
try:
388388
values, _, _, _ = self._try_coerce_args(self.values, value)
389-
# value may be converted to internal, thus drop
390389
blocks = self.putmask(mask, value, inplace=inplace)
391390
blocks = [b.make_block(values=self._try_coerce_result(b.values))
392391
for b in blocks]
@@ -1865,6 +1864,19 @@ class TimeDeltaBlock(DatetimeLikeBlockMixin, IntBlock):
18651864
def _box_func(self):
18661865
return lambda x: tslib.Timedelta(x, unit='ns')
18671866

1867+
def _can_hold_element(self, element):
1868+
if is_list_like(element):
1869+
element = np.array(element)
1870+
tipo = element.dtype.type
1871+
return issubclass(tipo, np.timedelta64)
1872+
return isinstance(element, (timedelta, np.timedelta64))
1873+
1874+
def _try_cast(self, element):
1875+
try:
1876+
return Timedelta(element)
1877+
except: # pragma: no cover
1878+
return element
1879+
18681880
def fillna(self, value, **kwargs):
18691881

18701882
# allow filling with integers to be
@@ -4943,6 +4955,7 @@ def _putmask_smart(v, m, n):
49434955

49444956
# change the dtype if needed
49454957
n = np.asarray(n)
4958+
49464959
dtype, _ = maybe_promote(n.dtype)
49474960

49484961
if is_extension_type(v.dtype) and is_object_dtype(dtype):

pandas/tests/series/test_missing.py

+1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def test_datetime64_fillna(self):
139139
assert_series_equal(result, expected)
140140

141141
def test_datetime64_tz_fillna(self):
142+
142143
for tz in ['US/Eastern', 'Asia/Tokyo']:
143144
# DatetimeBlock
144145
s = Series([Timestamp('2011-01-01 10:00'), pd.NaT,

0 commit comments

Comments
 (0)