Skip to content

BUG: read_csv silently ignores out of bounds errors when parsing date columns #61447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 of 3 tasks
ssuhre opened this issue May 16, 2025 · 3 comments
Closed
2 of 3 tasks
Assignees
Labels
Bug Datetime Datetime data dtype IO CSV read_csv, to_csv Non-Nano datetime64/timedelta64 with non-nanosecond resolution

Comments

@ssuhre
Copy link

ssuhre commented May 16, 2025

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
import tempfile as tmp

with tmp.TemporaryFile(mode='r+') as csv_file:
    pd.DataFrame({
        'over_and_under': [
            '2262-04-12',
            '1677-09-20',
        ]
    }).to_csv(csv_file, index=False)
    csv_file.seek(0)
    df = pd.read_csv(csv_file, parse_dates=['over_and_under'], date_format='%Y-%m-%d')
    print(df.info())
    pd.to_datetime(df['over_and_under'], format='%Y-%m-%d')

Issue Description

pandas 2.2.3 read_csv does not raise an Exception when parsing a date column with specified date_format if values are out of bounds and silently keeps the column as object dtype.
An explicit call of to_datetime on the column reveals the out of bounds problem which I expected to get from read_csv

Expected Behavior

read_csv should propagate or raise an OutOfBoundsDatetime exception like to_datetime.

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.12.9
python-bits : 64
OS : Darwin
OS-release : 24.4.0
Version : Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.3
numpy : 2.2.5
pytz : 2025.2
dateutil : 2.9.0.post0
pip : 24.3.1
Cython : None
sphinx : None
IPython : 9.2.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2025.2
qtpy : None
pyqt5 : None

@ssuhre ssuhre added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels May 16, 2025
@Farsidetfs
Copy link
Contributor

take

@asishm
Copy link
Contributor

asishm commented May 17, 2025

This is fixed on main. The dtype of the column is now datetime64[s]

@rhshadrach
Copy link
Member

Thanks for the report, and thanks @asishm. Closing.

@rhshadrach rhshadrach added Datetime Datetime data dtype IO CSV read_csv, to_csv Non-Nano datetime64/timedelta64 with non-nanosecond resolution and removed Needs Triage Issue that has not been reviewed by a pandas team member labels May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Datetime Datetime data dtype IO CSV read_csv, to_csv Non-Nano datetime64/timedelta64 with non-nanosecond resolution
Projects
None yet
Development

No branches or pull requests

4 participants