Skip to content

Commit dce11f0

Browse files
author
Russell Smith
committed
BUG : fix for GH14155
1 parent 3110a72 commit dce11f0

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

doc/source/whatsnew/v0.19.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1478,3 +1478,4 @@ Bug Fixes
14781478

14791479
- Bug in ``eval()`` where the ``resolvers`` argument would not accept a list (:issue:`14095`)
14801480
- Bugs in ``stack``, ``get_dummies``, ``make_axis_dummies`` which don't preserve categorical dtypes in (multi)indexes (:issue:`13854`)
1481+
- Bug in ```Series``` of ```np.timedelta64``` when setting a slice using an indexer (:issue:`14155`)

pandas/core/internals.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,7 @@ def _try_coerce_args(self, values, other):
16961696
other = other.value
16971697
elif isinstance(other, np.timedelta64):
16981698
other_mask = isnull(other)
1699-
other = other.view('i8')
1699+
other = Timedelta(other).value
17001700
elif isinstance(other, timedelta):
17011701
other = Timedelta(other).value
17021702
elif isinstance(other, np.ndarray):

pandas/tests/series/test_indexing.py

+7
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,13 @@ def test_timedelta_assignment(self):
13241324
s.loc['A'] = timedelta(1)
13251325
tm.assert_series_equal(s, expected)
13261326

1327+
# GH 14155
1328+
s = Series(10 * [np.timedelta64(10, 'm')])
1329+
s.loc[[1, 2, 3]] = np.timedelta64(20, 'm')
1330+
expected = pd.Series(10 * [np.timedelta64(10, 'm')])
1331+
expected.loc[[1, 2, 3]] = pd.Timedelta(np.timedelta64(20, 'm'))
1332+
tm.assert_series_equal(s, expected)
1333+
13271334
def test_underlying_data_conversion(self):
13281335

13291336
# GH 4080

0 commit comments

Comments
 (0)