Timestamp.replace should handle ambiguous DST times gracefully · Issue #25017 · pandas-dev/pandas (original) (raw)

tz = pytz.timezone('Europe/London') d = datetime.datetime(2019, 10, 27, 1, 0) d = tz.localize(d, is_dst=True) ts = pd.Timestamp(d) ts == d True pd.Timestamp(d).replace(minute=0) == d.replace(minute=0) False pd.Timestamp(d).replace(minute=0).tzinfo <DstTzInfo 'Europe/London' GMT0:00:00 STD> d.replace(minute=0).tzinfo <DstTzInfo 'Europe/London' BST+1:00:00 DST>

This is related to issue 18319 and the associated PR which makes pandas.Timestamp.replace behaviour deviate from datetime.datetime.replace when crossing DST transitions, and generally hand them more gracefully.
In cases when replacing into an ambiguous time (as above, when the clocks go back and repeat the same time in local time), the default behaviour of pandas is to normalize the datetime, using pytz's default setting is_dst=False. It would be useful to