A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/31929 below:

pd.Timestamp constructor fails if tzinfo is specified · Issue #31929 · pandas-dev/pandas · GitHub

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4