Skip to content

BUG: Timestamp breaks DST support of ZoneInfo timezones #54462

Closed
@michelbl

Description

@michelbl

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
import pandas as pd

d = datetime(2023, 3, 25, 6, tzinfo=ZoneInfo("Europe/Paris"))
pd.Timestamp(d) + pd.Timedelta(days=1)

returns Timestamp('2023-03-26 07:00:00+0200', tz='Europe/Paris'), which is wrong

pd.Timestamp(d) + timedelta(days=1) also gives the wrong result.

Issue Description

One day after the initial timestamp, the hour count should not have changed. Even if that day has only 23 hours because of DST.

Apparently, Timestamp does not alter the timezone because pd.Timestamp(d).tz == d.tzinfo, yet it changes its behavior.

Expected Behavior

Using the same example, d + pd.Timedelta(days=1) or d + timedelta(days=1) returns the correct result : datetime.datetime(2023, 3, 26, 6, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Paris')))

Installed Versions

INSTALLED VERSIONS
------------------
commit              : 5f672dc70479de509f7f10f9f39f27539c2defa3
python              : 3.11.4.final.0
python-bits         : 64
OS                  : Linux
OS-release          : 5.19.0-50-generic
Version             : #50-Ubuntu SMP PREEMPT_DYNAMIC Mon Jul 10 18:24:29 UTC 2023
machine             : x86_64
processor           : x86_64
byteorder           : little
LC_ALL              : None
LANG                : en_US.UTF-8
LOCALE              : en_US.UTF-8

pandas              : 2.1.0.dev0+1421.g5f672dc704
numpy               : 2.0.0.dev0+766.g8627dc962
pytz                : 2023.3
dateutil            : 2.8.2
setuptools          : 67.8.0
pip                 : 23.1.2
Cython              : None
pytest              : None
hypothesis          : None
sphinx              : None
blosc               : None
feather             : None
xlsxwriter          : None
lxml.etree          : None
html5lib            : None
pymysql             : None
psycopg2            : None
jinja2              : None
IPython             : None
pandas_datareader   : None
bs4                 : None
bottleneck          : None
brotli              : None
dataframe-api-compat: None
fastparquet         : None
fsspec              : None
gcsfs               : None
matplotlib          : None
numba               : None
numexpr             : None
odfpy               : None
openpyxl            : None
pandas_gbq          : None
pyarrow             : None
pyreadstat          : None
pyxlsb              : None
s3fs                : None
scipy               : None
snappy              : None
sqlalchemy          : None
tables              : None
tabulate            : None
xarray              : None
xlrd                : None
zstandard           : None
tzdata              : 2023.3
qtpy                : None
pyqt5               : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugNeeds TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions