Skip to content

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__

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