Skip to content

Commit e38e94f

Browse files
committed
TimedeltaIndex non-ns unit conversion (GH9011)
1 parent b0e0a06 commit e38e94f

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

pandas/tseries/tdi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def __new__(cls, data=None, unit=None,
181181

182182
# convert if not already
183183
if getattr(data,'dtype',None) != _TD_DTYPE:
184-
data = to_timedelta(data,unit=unit,box=False)
184+
data = to_timedelta(data,box=False)
185185
elif copy:
186186
data = np.array(data,copy=True)
187187

pandas/tseries/tests/test_timedeltas.py

+6
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,19 @@ def test_constructor(self):
852852
pd.offsets.Second(3)])
853853
tm.assert_index_equal(result,expected)
854854

855+
# GH9011
856+
# non-ns unit
855857
expected = TimedeltaIndex(['0 days 00:00:00', '0 days 00:00:01', '0 days 00:00:02'])
856858
tm.assert_index_equal(TimedeltaIndex(range(3), unit='s'), expected)
857859
expected = TimedeltaIndex(['0 days 00:00:00', '0 days 00:00:05', '0 days 00:00:09'])
858860
tm.assert_index_equal(TimedeltaIndex([0, 5, 9], unit='s'), expected)
859861
expected = TimedeltaIndex(['0 days 00:00:00.400', '0 days 00:00:00.450', '0 days 00:00:01.200'])
860862
tm.assert_index_equal(TimedeltaIndex([400, 450, 1200], unit='ms'), expected)
861863

864+
# no boxing
865+
expected = (np.array([400, 450, 1200])*1e6).astype('i8').astype('m8[ns]')
866+
tm.assert_numpy_array_equal(TimedeltaIndex([400, 450, 1200], unit='ms', box=False), expected)
867+
862868
def test_constructor_coverage(self):
863869
rng = timedelta_range('1 days', periods=10.5)
864870
exp = timedelta_range('1 days', periods=10)

pandas/tseries/timedeltas.py

-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def _convert_listlike(arg, box, unit):
5252
value = np.array([ _get_string_converter(r, unit=unit)() for r in arg ],dtype='m8[ns]')
5353
except:
5454
value = np.array([ _coerce_scalar_to_timedelta_type(r, unit=unit, coerce=coerce) for r in arg ])
55-
value = value.astype('timedelta64[ns]', copy=False)
5655

5756
if box:
5857
from pandas import TimedeltaIndex

0 commit comments

Comments
 (0)