-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
QST: Is there a work-around for repeated FutureWarnings? #50603
Comments
Hi, thanks for your report. This is expected. I would suggest trying to fix the deprecated stuff. We will release 2.0 soon and this will raise then |
Hi, yes I understand the warning needs to be heeded, my question was more around the why are there 3 copies of it, as the Compare the output of: import warnings
warnings.simplefilter(action='default')
for i in range (3):
warnings.warn('Warn once') and import warnings
warnings.simplefilter(action='always')
for i in range (3):
warnings.warn('Warn once') and you'll see what I mean |
You could always surround the code with (better - use a context manager)
Do you still see performance degradation doing this? |
I could, but that would give me no warnings. I want exactly one per call in my code that calls the relevant bits of pandas with context that needs a warning. |
Understood, but I'm more interested in if the performance degradation is fixed by this. Then we can improve upon it, e.g.
|
Yes, in my case the performance degradation would be fixed by emitting 0 (or 1 warnings) per called line. I thought that python warnings already had this functionality (it can cache what has already been warned and reject warnings that match the same message and code location). But it just doesn't seem to be working in this case. From https://docs.python.org/3/library/warnings.html:
and
Just wondering whether it's the fact that you haven't given a pandas/pandas/util/_exceptions.py Line 89 in 710b83b
warn_explicit you need to provide the registry:https://docs.python.org/3/library/warnings.html#warnings.warn_explicit
|
@stev-0 I tried supplying Still - I'll put up a PR to add this to the places where we use warn_explicit; thanks for finding this! |
Actually - I'm finding that But - because the OP example with this doesn't fail outright, it's not being hit anyways. |
Research
I have searched the [pandas] tag on StackOverflow for similar questions.
I have asked my usage related question on StackOverflow.
Link to question on StackOverflow
https://stackoverflow.com/questions/75029437/pandas-get-single-warning-message-per-line
Question about pandas
Is repeated warnings expected behaviour when calling the same code multiple times? This is probably more likely to be a Python bug, but to date I haven't discovered how Pandas triggers it and if there is any work-around.
Pandas 1.5.2, Python3.10
Output of
python3 -Wd::FutureWarning test.py
/home/stephen/test.py:16: FutureWarning: Passing a set as an indexer is deprecated and will raise in a future version. Use a list instead.
df[b]
/home/stephen/test.py:16: FutureWarning: Passing a set as an indexer is deprecated and will raise in a future version. Use a list instead.
df[b]
/home/stephen/test.py:16: FutureWarning: Passing a set as an indexer is deprecated and will raise in a future version. Use a list instead.
df[b]
The text was updated successfully, but these errors were encountered: