Skip to content

BUG: pd.Timestamp constructor fails if tzinfo is specified #31929

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

Closed
pganssle opened this issue Feb 12, 2020 · 0 comments · Fixed by #45308
Closed

BUG: pd.Timestamp constructor fails if tzinfo is specified #31929

pganssle opened this issue Feb 12, 2020 · 0 comments · Fixed by #45308
Labels
Bug Timezones Timezone data dtype
Milestone

Comments

@pganssle
Copy link
Contributor

The constructor for pd.Timestamp has both a tz= and tzinfo= argument, presumably because pd.Timestamp is trying to both support the datetime.datetime interface and its own constructor. There is evidently logic in the constructor to prevent both tz and tzinfo being specified, but it seems something has gone wrong, because constructing an aware pd.Timestamp by components and including tzinfo always raises an exception, see:

import pandas as pd
from datetime import timezone

pd.Timestamp(2020, 1, 1, tzinfo=timezone.utc)

This raises the following exception:

>>> pd.Timestamp(2020, 12, 31, tzinfo=timezone.utc)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-18-9d882de0a384> in <module>
----> 1 pd.Timestamp(2020, 12, 31, tzinfo=timezone.utc)

pandas/_libs/tslibs/timestamps.pyx in pandas._libs.tslibs.timestamps.Timestamp.__new__()

ValueError: Can provide at most one of tz, tzinfo

Despite the fact that only tzinfo was specified. This seems to only occur when you are using the "per-component" specification, as passing a datetime or epoch time as the first component allows you to specify the time zone using tzinfo:

pd.Timestamp(0, tzinfo=timezone.utc) # Works
@pganssle pganssle changed the title pd.Timestamp constructor fails if tzinfo is specified BUG: pd.Timestamp constructor fails if tzinfo is specified Feb 12, 2020
@jbrockmendel jbrockmendel added the Timezones Timezone data dtype label Jun 5, 2020
@mroeschke mroeschke added the Bug label Jul 28, 2021
@jreback jreback added this to the 1.5 milestone Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Timezones Timezone data dtype
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants