-
-
Notifications
You must be signed in to change notification settings - Fork 19.1k
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
import pandas as pd
pd.to_datetime("2024-53-1", format="%G-%V-%u")
Issue Description
When using python format codes to resolve an isoweek notation ("%G-%V-%u") back to an iso date, to_datetime() incorrectly works with non-existing weeks. In the example below the third call should not return a valid date, as no week 53 exists in the isoclander year 2024 (the first lines are non-isoclandar, the last line is the first week in isocalendar 2025, which are all correct).
This behavior can be seen in others years with 52 isoweeks as well, e.g. pd.to_datetime("2023-53-1", format="%G-%V-%u") also returns the date of the first isoweek of 2024.
The python standard library correctly raises an error when the same thing is tried:
Expected Behavior
Raise an error for misformatted date string.
Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.12.6
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.26100
machine : AMD64
processor : AMD64 Family 23 Model 113 Stepping 0, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : en
LOCALE : English_Germany.1252
pandas : 2.2.3
numpy : 2.1.2
pytz : 2024.1
dateutil : 2.9.0
pip : 24.2
Cython : None
sphinx : 8.0.2
IPython : 8.28.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : 1.1
hypothesis : None
gcsfs : None
jinja2 : 3.1.4
lxml.etree : None
matplotlib : 3.9.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.5
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : 18.1.0
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.1
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
xlsxwriter : None
zstandard : 0.23.0
tzdata : 2024.2
qtpy : 2.4.1
pyqt5 : None