Skip to content

Commit 0c2f2d0

Browse files
changhiskhanwesm
authored andcommitted
BUG: loses nano precision when converting Timestamp objects #2252
1 parent bda1f73 commit 0c2f2d0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pandas/src/datetime.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,9 @@ cpdef convert_to_tsobject(object ts, object tz=None):
605605
if obj.tzinfo is not None and not _is_utc(obj.tzinfo):
606606
offset = _get_utcoffset(obj.tzinfo, ts)
607607
obj.value -= _delta_to_nanoseconds(offset)
608+
609+
if isinstance(ts, _Timestamp):
610+
obj.value += ts.nanosecond
608611
_check_dts_bounds(obj.value, &obj.dts)
609612
return obj
610613
elif PyDate_Check(ts):
@@ -795,6 +798,8 @@ def array_to_datetime(ndarray[object] values, raise_=False, dayfirst=False,
795798
'utc=True')
796799
else:
797800
iresult[i] = _pydatetime_to_dts(val, &dts)
801+
if isinstance(val, _Timestamp):
802+
iresult[i] += val.nanosecond
798803
_check_dts_bounds(iresult[i], &dts)
799804
elif PyDate_Check(val):
800805
iresult[i] = _date_to_datetime64(val, &dts)

pandas/tseries/tests/test_timeseries.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,14 @@ def test_to_period_nofreq(self):
13331333
freq='infer')
13341334
idx.to_period()
13351335

1336+
def test_000constructor_resolution(self):
1337+
#2252
1338+
t1 = Timestamp((1352934390*1000000000)+1000000+1000+1)
1339+
idx = DatetimeIndex([t1])
1340+
1341+
self.assert_(idx.nanosecond[0] == t1.nanosecond)
1342+
1343+
13361344
def test_constructor_coverage(self):
13371345
rng = date_range('1/1/2000', periods=10.5)
13381346
exp = date_range('1/1/2000', periods=10)

0 commit comments

Comments
 (0)