Skip to content

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

@ssuhre

Description

@ssuhre

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

Metadata

Metadata

Assignees

Labels

BugDatetimeDatetime data dtypeIO CSVread_csv, to_csvNon-Nanodatetime64/timedelta64 with non-nanosecond resolution

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions