You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pd.to_datetime is being used to convert datetime columns in multiple tables, and dayfirst=True, infer_datetime_format=True and errors='coerce are used
This particular column produces unexpected behavior even though the entire column is in the same format.
I suspect dayfirst and infer_datetime_format are conflicting and converts the string into an invalid parsing and results in errors='coerce' converting the bottom three rows into NaT.
However, if using the default errors='raise', there does not appear to be an invalid parse, however that does not fit my general use case.
This could be improved to use more than just the first non-null element to infer the format, but for now, it's working as expected
As an aside, there have been many, many bug fixes to do with datetime parsing recently, I'd strongly encourage you to try out the pandas 2.0.0 release candidate to check that all works as expected
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
Problem:
No problem but does not fit use case:
Issue Description
pd.to_datetime
is being used to convert datetime columns in multiple tables, anddayfirst=True
,infer_datetime_format=True
anderrors='coerce
are usedThis particular column produces unexpected behavior even though the entire column is in the same format.
I suspect
dayfirst
andinfer_datetime_format
are conflicting and converts the string into an invalid parsing and results inerrors='coerce'
converting the bottom three rows intoNaT
.However, if using the default
errors='raise'
, there does not appear to be an invalid parse, however that does not fit my general use case.Expected Behavior
Installed Versions
pandas : 1.5.3
numpy : 1.21.2
pytz : 2021.3
dateutil : 2.8.2
setuptools : 58.0.4
pip : 21.0.1
Cython : None
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.0.1
lxml.etree : 4.6.2
html5lib : None
pymysql : 1.0.2
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.27.0
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.0.9
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : 1.3.22
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: