Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
s = pd.Series(pd.DatetimeIndex(["2018-09-15 01:30:00"]))
print(s.dt.tz_localize("Europe/Berlin"))
print(s.dt.tz_localize(":/usr/share/zoneinfo/Europe/Berlin"))
Issue Description
While the first call to tz_localize
works, the second fails with the traceback below. I experienced this problem after setting my TZ
environment variable to :/etc/locatime
to avoid unnecessary system calls from glibc, as specified in the timezone
man page:
The second format [of the TZ environment variable] specifies that the timezone information should be read from a file: :[filespec]
Traceback (most recent call last):
File "/home/glefalher/pytztz/t.py", line 5, in <module>
print(s.dt.tz_localize(":/usr/share/zoneinfo/Europe/Berlin"))
File "/home/glefalher/pytztz/lib/python3.9/site-packages/pandas/core/accessor.py", line 96, in f
return self._delegate_method(name, *args, **kwargs)
File "/home/glefalher/pytztz/lib/python3.9/site-packages/pandas/core/indexes/accessors.py", line 123, in _delegate_method
result = method(*args, **kwargs)
File "/home/glefalher/pytztz/lib/python3.9/site-packages/pandas/core/indexes/datetimes.py", line 276, in tz_localize
arr = self._data.tz_localize(tz, ambiguous, nonexistent)
File "/home/glefalher/pytztz/lib/python3.9/site-packages/pandas/core/arrays/_mixins.py", line 86, in method
return meth(self, *args, **kwargs)
File "/home/glefalher/pytztz/lib/python3.9/site-packages/pandas/core/arrays/datetimes.py", line 1038, in tz_localize
tz = timezones.maybe_get_tz(tz)
File "pandas/_libs/tslibs/timezones.pyx", line 145, in pandas._libs.tslibs.timezones.maybe_get_tz
File "pandas/_libs/tslibs/timezones.pyx", line 170, in pandas._libs.tslibs.timezones.maybe_get_tz
File "/home/glefalher/pytztz/lib/python3.9/site-packages/pytz/__init__.py", line 188, in timezone
raise UnknownTimeZoneError(zone)
pytz.exceptions.UnknownTimeZoneError: ':/usr/share/zoneinfo/Europe/Berlin'
Expected Behavior
Both lines should produce to the same results, but honestly I'm not sure if pandas or pytz should take care of that 🤔
Installed Versions
python : 3.9.16.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-58-generic
Version : #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.5.3
numpy : 1.24.1
pytz : 2022.7.1
dateutil : 2.8.2
setuptools : 66.1.1
pip : 22.3.1
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
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
xlwt : None
zstandard : None
tzdata : 2022.7
Comment From: jbrockmendel
we definitely don't handle that on our end. if pytz handles it, I'd expect it to not like the leading ":", but that's just speculation
Comment From: jbrockmendel
pytz.timezone fails for me with the full path. if the motivation is to set the path to something other than the default, id suggest using zoneinfo. in 3.0 we tentatively plan to change the default from pytz to zoneinfo.
Comment From: phofl
Closing, please ping to reopen if this does not fix your issue