-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: to_datetime ignores "AM" and "PM" unless format is explicitly set #53147
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
Comments
Hi @juli4nb4dillo, I am new here so apologies if I misunderstand the bug you have raised. Using the format parameter would get the desired result I recreated your code with the format parameter and returned the following: import pandas as pd 0 4/21/2023 11:06:35 AM 0 2023-04-21 11:06:35 |
@Rainman33 That's correct, it's not a big deal if I manually set the format. However it used to work (without format parameter) with pandas 1.5.3, hence it triggered a few hidden bugs in our software once we upgraded to pandas 2.x. |
Hi @juli4nb4dillo, If I pass in
which I think is what you expected. It's strange that the parsing didn't throw an error, though. cc @MarcoGorelli who probably knows whether this is a bug or not. |
thanks @juli4nb4dillo for the report (and @lithomas1 for the ping!) this looks like a bug: we have In [2]: guess_datetime_format('4/21/2023 11:06:35 AM')
Out[2]: '%m/%d/%Y %H:%M:%S %p' and it looks like this should instead have been '%m/%d/%Y %I:%M:%S %p' ? |
This is the part of the code which would need changing pandas/_libs/tslibs/parsing.pyx Not sure whether to suggest special-casing ' |
If AM/PM is in the guessing string, then switching to |
so something like
Anyone fancy making a PR? |
@MarcoGorelli #53244 |
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
Issue Description
to_datetime
ignores theAM
andPM
particles, hence parsing both as 24H format.Expected Behavior
Installed Versions
INSTALLED VERSIONS
commit : 37ea63d
python : 3.10.4.final.0
python-bits : 64
OS : Darwin
OS-release : 21.6.0
Version : Darwin Kernel Version 21.6.0: Thu Mar 9 20:12:21 PST 2023; root:xnu-8020.240.18.700.8~1/RELEASE_ARM64_T6000
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.1
numpy : 1.24.2
pytz : 2023.3
dateutil : 2.8.2
setuptools : 67.4.0
pip : 23.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.9
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : 2.9.5
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : None
tables : None
tabulate : 0.9.0
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: