Skip to content

Commit ff435ba

Browse files
Russell Smithjreback
Russell Smith
authored andcommitted
BUG : bug in setting a slice of a Series with a np.timedelta64
closes pandas-dev#14155 closes pandas-dev#14160
1 parent 497a3bc commit ff435ba

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
@@ -1527,6 +1527,7 @@ Bug Fixes
15271527
- Bug in invalid datetime parsing in ``to_datetime`` and ``DatetimeIndex`` may raise ``TypeError`` rather than ``ValueError`` (:issue:`11169`, :issue:`11287`)
15281528
- Bug in ``Index`` created with tz-aware ``Timestamp`` and mismatched ``tz`` option incorrectly coerces timezone (:issue:`13692`)
15291529
- Bug in ``DatetimeIndex`` with nanosecond frequency does not include timestamp specified with ``end`` (:issue:`13672`)
1530+
- Bug in ```Series``` when setting a slice with a ```np.timedelta64``` (:issue:`14155`)
15301531

15311532
- Bug in ``Index`` raises ``OutOfBoundsDatetime`` if ``datetime`` exceeds ``datetime64[ns]`` bounds, rather than coercing to ``object`` dtype (:issue:`13663`)
15321533
- Bug in ``Index`` may ignore specified ``datetime64`` or ``timedelta64`` passed as ``dtype`` (:issue:`13981`)

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)