Description
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
In pandas 1.5.1:
import pandas as pd
from pandas import *
import sys
import datetime as dt
print(dt.datetime.strptime('2020-01-01 00:00:00UTC', '%Y-%m-%d %H:%M:%S%Z')) # works!
to_datetime('2020-01-01 00:00:00UTC', format='%Y-%m-%d %H:%M:%S%Z') # crashes!
Issue Description
The ISO8601 fastpath in
has no way to deal with '%Z'
formatted-strings. They shouldn't get there in the first place.
Hence, '%Z'
should be excluded from
pandas/pandas/_libs/tslibs/parsing.pyx
Lines 886 to 903 in 634196a
Expected Behavior
In [1]: to_datetime('2020-01-01 00:00:00UTC', format='%Y-%m-%d %H:%M:%S%Z')
Out[1]: Timestamp('2020-01-01 00:00:00+0000', tz='UTC')
Installed Versions
INSTALLED VERSIONS
commit : 91111fd
python : 3.10.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.102.1-microsoft-standard-WSL2
Version : #1 SMP Wed Mar 2 00:30:59 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8
pandas : 1.5.1
numpy : 1.23.3
pytz : 2022.2.1
dateutil : 2.8.1
setuptools : 65.3.0
pip : 22.2.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.1
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.5.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli : None
fastparquet : None
fsspec : 2022.10.0
gcsfs : None
matplotlib : 3.6.1
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : 2022.10.0
scipy : 1.9.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
None