Skip to content

BUG: Timestamp.__new__ doesnt preserve nanosecond #7610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2014

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Jun 29, 2014

When Timestamp.__new__ accepts a timestamp with nanosecond, nanosecond is not preserved properly.

# create Timestamp with ns (OK)
t = pd.Timestamp('2011-01-01') + pd.offsets.Nano(5)
t, t.value
# (Timestamp('2011-01-01 00:00:00.000000005'), 1293840000000000005)

# If it is passed to Timestamp.__init__, ns is not displayed even though internal value includes it. (NG)
t = pd.Timestamp(t)
t, t.value
# (Timestamp('2011-01-01 00:00:00'), 1293840000000000005)

# If offset is added to above result, ns is displayed properly (OK)
t = t + pd.offsets.Nano(5)
t, t.value
# (Timestamp('2011-01-01 00:00:00.000000010'), 1293840000000000010)

NOTE: Unrelated to this issue, test_tslib had test_timedelta_ns_arithmetic method duplicatelly. Thus renamed.

@jreback jreback added this to the 0.14.1 milestone Jun 29, 2014
@sinhrks sinhrks changed the title BUG: Timestamp.__init__ doesnt preserve nanosecond BUG: Timestamp.__new__ doesnt preserve nanosecond Jun 30, 2014
@sinhrks
Copy link
Member Author

sinhrks commented Jun 30, 2014

Modified the subject. The problem is not __init__ , but __new__

@@ -956,6 +956,7 @@ cdef convert_to_tsobject(object ts, object tz, object unit):

if is_timestamp(ts):
obj.value += ts.nanosecond
obj.dts.ps = ts.nanosecond * 1000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a repr issue (and not a calc issue). as these tests all pass (for .value), but only Timestamp(t) doesn't have the correcvt repr (but the right value)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__repr__ refers to nanosecond, not value.
https://github.com/pydata/pandas/blob/master/pandas/tslib.pyx#L252
And nanosecond set from dst.ps, not value. Thus dst.ps must be set properly before setting nanosecond.
https://github.com/pydata/pandas/blob/master/pandas/tslib.pyx#L213

t = pd.Timestamp('2011-01-01') + pd.offsets.Nano(5)
t = pd.Timestamp(t)
t.nanosecond
# 0 (NG)

@jreback
Copy link
Contributor

jreback commented Jun 30, 2014

ok then...thanks

jreback added a commit that referenced this pull request Jun 30, 2014
BUG: Timestamp.__new__ doesnt preserve nanosecond
@jreback jreback merged commit 08ae4f7 into pandas-dev:master Jun 30, 2014
@sinhrks sinhrks deleted the nanots branch July 2, 2014 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants