-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
s = pd.Series(range(2),
index=pd.DatetimeIndex(['2021-03-28 01:30:00',
'2021-03-28 02:30:00']))
s.tz_localize('Europe/London', nonexistent=pd.Timedelta('1H'))
2021-03-28 03:30:00+01:00 0
2021-03-28 02:30:00+01:00 1
dtype: int64
Problem description
Using Timedelta with the nonexistent
flag with tz_localize
is adding 2 hours instead of 1 hour for nonexistent times in 'Europe/London' tz. DST started on 2021-03-28 when 59:59 > 02:00 so '2021-03-28 01:30:00' is nonexistent. When I run almost the same code from the docs with 'Europe/Warsaw' the bug does not occur:
s = pd.Series(range(2),
index=pd.DatetimeIndex(['2021-03-28 02:30:00',
'2021-03-28 03:30:00']))
s.tz_localize('Europe/Warsaw', nonexistent=pd.Timedelta('1H'))
2021-03-28 03:30:00+02:00 0
2021-03-28 03:30:00+02:00 1
dtype: int64
Expected Output
2021-03-28 02:30:00+01:00 0
2021-03-28 02:30:00+01:00 1
dtype: int64
Output of pd.show_versions()
INSTALLED VERSIONS
commit : f2c8480
python : 3.8.7.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252
pandas : 1.2.3
numpy : 1.19.5
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.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 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : 2.0.0
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None