-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
TST: Remove stacklevel checks for deprecated resample kwargs #37603
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
Conversation
9f6a5d6 to c689f88 Compare | yes we should set some reasonable stack level |
| How about using the Actually this computation should only be done if the warnings do have to be raised, so relative to actually emitting the warning I'd say the overhead is minimal. |
we don’t want the complexity just hard code some reasonable defaults (iirc that’s how this was) and call it a day |
Okay, I've reverted to how it was before ( |
| ok, going back to the original question. you want to disable the stacklevel checks because they are incorrect? or its fragile? the entire deprecation warning will be removed in 2.0 anyhow. |
Oh I made this PR because I thought you wanted to remove these tests 😮 #36629 (comment) But to answer the question directly, it's because they're fragile. Or to be precise, because the way they are satisfied is fragile, and using a more robust solution is too complex for basically just a couple of deprecation warnings. (This is the discussion we had in #36629.) |
| pls restore the actual stacklevels to what they were so iow i am not sure this PR is actually a net positive |
I've already done that! #37603 (comment)
I didn't disable all of them, juste the ones for these specific warnings.
You asked me to do exactly this in in #36629 (comment) and then again in #36369 (comment), please be clear, I'm getting very confused 😂 |
| Any updates on this @jreback? Did I misunderstand what you requested? |
| well the issue is this is changing what we have on master, which is passing now. can you explain again why this change is worth it? |
This PR removes the stacklevel requirement from resample deprecation warnings. This change is not worth it in isolation; it is only easing the way for other things to go ahead (namely, all of this started because of #36369). The initial solution was not to remove the stacklevel checks, but to implement a more robust solution for setting the correct stacklevel (#36629), but you pointed out that it was too complex to be worth it for just a few deprecation warnings. So we both agreed the simplest solution was to remove the stacklevel requirement from these specific tests. See also: |
jreback left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok merge master and ping on green
I didn't fully follow the original cause that all triggered this discussion but: yes the current checks are fragile, but they are already implemented, and are working. So why do the effort of removing them? You mention it is because of #36369. But how does improving the docs impact this? |
You are right @jorisvandenbossche that perhaps things got a bit sidetracked. To make sure we're on the same page, here's a quick summary of what happened so far, in chronological order:
So going back to #36369: while I could ditch the changes I made for In summary, I would either merge the fix #36629 (or perhaps a simpler alternative) or remove the stacklevel checks (this PR), rather than scrap the documentation changes. |
e842308 to 055f01d Compare | Thanks for the overview :)
So by adding those Series/DataFrame methods (which I think is certainly a good change to ensure proper docs for both), this increased the stacklevel by 1, causing the test failure. But so we could also simply increase the stacklevel set for the warning by 1 and be done with it? (or is it not that simple .. ?) (and yes, this "magic" number easily breaks when refactoring, as it happened for you. But that's what the tests are for, and thus after refactoring, we can then update this "magic" number, and the tests pass again. And IMO it's really not that magic, everywhere we issue a warning in the codebase, we need to set a stacklevel. The only complicating issue here is that multiple code paths could reach the same warning with a different stacklevel, in which case we could also choose one.
Or, a fourth alternative: keep the documentation improvement, and update the magic number? |
| yeah like @jorisvandenbossche 4th suggestion here. let's try to fix the docs and update to make things pass. if there is an unavoidable situation, then yes remove the stack level check. let's just do it in that other PR. |
Precisely, it's not that simple: You can reproduce this by checking out 27b16cf, modifying this pandas/pandas/core/groupby/grouper.py Line 243 in 27b16cf
to pandas/pandas/tests/resample/test_deprecated.py Lines 50 to 53 in 27b16cf
It's not "magic" in the sense of "arbitrary", but it is in the sense that it is strongly reliant on the implementation of many other things: in order to be able to set a correct stacklevel, one must determine the stacklevel for every single path that might reach the warning code—and not only that, one must be able to compute it at the point the warning is called. It just happened to be that, at the time that code was written, determining the correct stacklevel was relatively hassle-free. But in many cases, as in the example above, this won't be that trivial, and the only reliable way will be to actually inspect the stack (which seems a bit overkill for just some warnings).
Well, I would have thought it's better to spend the time discussing it now and resolving it for a long time rather than having to revisit and re-fix this every time someone refactors anything related to the But of course, the choice is yours; you're more experienced and perhaps I'm worrying about nothing.
The only way I'd see this as an alternative is if we also remove the |
Then we should simply choose the one that we find most important to have the correct stacklevel. Which in this case is clearly DataFrame/Series.resample, I think.
Luckily nobody does that ;) (and we also shouldn't care if someone did, it's not public)
The main thing I care about (and the reason I am involving myself here), is that we set correct stacklevels as much as reasonably possible, because IMO it's of big importance for usability when dealing with such warnings.
Yes, those case then be removed. |
Okay, I will go for this in the original PR then. Thanks for all your patience! |
See pandas-dev#37603 for rationale regarding this solution and the removal of some of the warning tests.
black pandasgit diff upstream/master -u -- "*.py" | flake8 --diffThis removes
stacklevelrequirements from the deprecation warnings forresampleandGrouperkwargs in an attempt to simplify the warning-handling code (see #36629 for "why"). This only changestests.resample.test_deprecated.The second commit is optional (it just extracts the deprecated argument checking code out from
Grouper.__new__to declutter the latter); I can revert it if needed.