Skip to content

BUG: stacklevel from dayfirst warning incorrect #47907

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
3 tasks done
MarcoGorelli opened this issue Jul 31, 2022 · 2 comments
Closed
3 tasks done

BUG: stacklevel from dayfirst warning incorrect #47907

MarcoGorelli opened this issue Jul 31, 2022 · 2 comments
Labels
Bug Warnings Warnings that appear or should be added to pandas

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Jul 31, 2022

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 io


pd.to_datetime(['13/01/2021'])  # correct stacklevel

pd.read_csv(io.StringIO('date\n01/13/2021\n'), parse_dates=['date'], dayfirst=True)  # incorrect

Issue Description

Running the above, I get

/home/megorelli/pandas-dev/t.py:5: UserWarning: Parsing dates in DD/MM/YYYY format when dayfirst=False (the default) was specified. This may lead to inconsistently parsed dates! Specify a format to ensure consistent parsing.
  pd.to_datetime(['13/01/2021'])
/home/megorelli/pandas-dev/pandas/io/parsers/base_parser.py:1061: UserWarning: Parsing dates in MM/DD/YYYY format when dayfirst=True was specified. This may lead to inconsistently parsed dates! Specify a format to ensure consistent parsing.
  return tools.to_datetime(

Expected Behavior

Running the above, I expected to get

/home/megorelli/pandas-dev/t.py:5: UserWarning: Parsing dates in DD/MM/YYYY format when dayfirst=False (the default) was specified. This may lead to inconsistently parsed dates! Specify a format to ensure consistent parsing.
  pd.to_datetime(['13/01/2021'])
/home/megorelli/pandas-dev/t.py:7: UserWarning: Parsing dates in MM/DD/YYYY format when dayfirst=True was specified. This may lead to inconsistently parsed dates! Specify a format to ensure consistent parsing.
  return tools.to_datetime(

Installed Versions

INSTALLED VERSIONS

commit : 23c53bb
python : 3.9.2.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.114-16025-ge75506b9d98e
Version : #1 SMP PREEMPT Sat Jul 16 18:52:19 PDT 2022
machine : aarch64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.0.dev0+1212.g23c53bb6db
numpy : 1.22.4
pytz : 2022.1
dateutil : 2.8.2
setuptools : 62.1.0
pip : 22.0.4
Cython : 0.29.30
pytest : 7.1.2
hypothesis : 6.47.1
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.4.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : 2.8.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : 3.7.0
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
None

@MarcoGorelli MarcoGorelli added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 31, 2022
@MarcoGorelli MarcoGorelli added Warnings Warnings that appear or should be added to pandas and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jul 31, 2022
@tomaarsen
Copy link
Contributor

This was fixed in #47998, running the provided snippet now gives:

/workspaces/pandas/demo.py:5: UserWarning: Parsing dates in DD/MM/YYYY format when dayfirst=False (the default) was specified. This may lead to inconsistently parsed dates! Specify a format to ensure consistent parsing.
  pd.to_datetime(['13/01/2021'])  # correct stacklevel
/workspaces/pandas/demo.py:7: UserWarning: Parsing dates in MM/DD/YYYY format when dayfirst=True was specified. This may lead to inconsistently parsed dates! Specify a format to ensure consistent parsing.
  pd.read_csv(io.StringIO('date\n01/13/2021\n'), parse_dates=['date'], dayfirst=True)  # incorrect

In short, this can be closed.

@MarcoGorelli
Copy link
Member Author

Thanks @tomaarsen !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Warnings Warnings that appear or should be added to pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants