Skip to content

BUG: Pandas to_datetime parsing error with "May" month #62084

@kochlisGit

Description

@kochlisGit

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
dates = ['May 12, 2025', 'May 13, 2025', 'May 14, 2025', 'May 15, 2025', 'May 16, 2025', 'May 17, 2025', 'May 18, 2025', 'May 19, 2025', 'May 20, 2025', 'May 21, 2025', 'May 22, 2025', 'May 23, 2025', 'May 24, 2025', 'May 25, 2025', 'May 26, 2025', 'May 27, 2025', 'May 28, 2025', 'May 29, 2025', 'May 30, 2025', 'May 31, 2025', 'Jun 1, 2025', 'Jun 2, 2025', 'Jun 3, 2025', 'Jun 4, 2025', 'Jun 5, 2025', 'Jun 6, 2025', 'Jun 7, 2025', 'Jun 8, 2025', 'Jun 9, 2025', 'Jun 10, 2025', 'Jun 11, 2025', 'Jun 12, 2025', 'Jun 13, 2025', 'Jun 14, 2025', 'Jun 15, 2025', 'Jun 16, 2025', 'Jun 17, 2025', 'Jun 18, 2025', 'Jun 19, 2025', 'Jun 20, 2025', 'Jun 21, 2025', 'Jun 22, 2025', 'Jun 23, 2025', 'Jun 24, 2025', 'Jun 25, 2025', 'Jun 26, 2025', 'Jun 27, 2025', 'Jun 28, 2025', 'Jun 29, 2025', 'Jun 30, 2025', 'Jul 1, 2025', 'Jul 2, 2025', 'Jul 3, 2025', 'Jul 4, 2025', 'Jul 5, 2025', 'Jul 6, 2025', 'Jul 7, 2025', 'Jul 8, 2025', 'Jul 9, 2025', 'Jul 10, 2025', 'Jul 11, 2025', 'Jul 12, 2025', 'Jul 13, 2025', 'Jul 14, 2025', 'Jul 15, 2025', 'Jul 16, 2025', 'Jul 17, 2025', 'Jul 18, 2025', 'Jul 19, 2025', 'Jul 20, 2025', 'Jul 21, 2025', 'Jul 22, 2025', 'Jul 23, 2025', 'Jul 24, 2025', 'Jul 25, 2025', 'Jul 26, 2025', 'Jul 27, 2025', 'Jul 28, 2025', 'Jul 29, 2025', 'Jul 30, 2025', 'Jul 31, 2025', 'Aug 1, 2025', 'Aug 2, 2025', 'Aug 3, 2025', 'Aug 4, 2025', 'Aug 5, 2025', 'Aug 6, 2025', 'Aug 7, 2025', 'Aug 8, 2025', 'Aug 9, 2025', 'Aug 10, 2025']

# Trying to parse these dates will raises an error, as it assumes that month followss "%B" format.
pd_dates = pd.to_datetime(dates)

Issue Description

I use pd.to_datetime function to automaatically convert a list of String dates to timestamps, no matter the format. In my application, I assume that the provided date format is unknown. However, there is an issue with pandas to_datetime when:

  1. The format is "%b %d, %Y"
  2. The first month in the list is "May"

In this case, the pandas parses the first date and it assumes that all months follow %B format. However, "May" month could also be described by %b format. To address this issue I have to use "mixed" format to parse each date individually, but it is slower.

Expected Behavior

The expected behavior is to parse the dates. For instance, if you replace May in the first row with Aug, the parsing of the entire list is successful

Installed Versions

INSTALLED VERSIONS

commit : fd3f571
python : 3.11.7.final.0
python-bits : 64
OS : Linux
OS-release : 6.6.87.2-microsoft-standard-WSL2
Version : #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.0
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 69.0.3
pip : 24.0
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 5.1.0
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.3
IPython : 8.21.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2024.2.0
gcsfs : None
matplotlib : 3.8.2
numba : 0.59.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.12.0
sqlalchemy : 2.0.41
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None

Metadata

Metadata

Assignees

Labels

BugDatetimeDatetime data dtypeDuplicate ReportDuplicate issue or pull requestNeeds TriageIssue that has not been reviewed by a pandas team member

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions