Skip to content

Timestamp.timestamp() inconsistent with Datetime.timestamp() #22450

Closed
@patrickspry

Description

@patrickspry

Code Sample, a copy-pastable example if possible

import datetime as dt
import pandas as pd

t = dt.datetime.now()
ts1 = t.timestamp()
ts2 = pd.Timestamp(t).timestamp()

print((ts1 - ts2) / 3600)

Problem description

Pandas and Datetime evidently have different defaults when handling time objects for which tzinfo=None. This changed somewhere in between pandas 0.19 and 0.23 (upgrading broke a bunch of my tests). I think keeping consistency between these two libraries would remove some of the confusion in the bizarrely complicated area that is python time-handling.

In the example, the two timestamp floats should match. Currently, my understanding is the datetime library defaults to the current timezone whereas Pandas assumes GMT. There isn't information in the Pandas API documentation regarding how Timestamp.timestamp() handles naive Timestamps (link).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsDatetimeDatetime data dtypeDeprecateFunctionality to remove in pandasNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions