Skip to content

Enable ignoring deprecation warnings from entire module - #6334

Merged
bsipocz merged 2 commits into
astropy:masterfrom
pllim:ignore-mod-warn
Jul 6, 2017
Merged

bsipocz merged 2 commits into
astropy:masterfrom
pllim:ignore-mod-warn

Conversation

@pllim

@pllim pllim commented Jul 5, 2017 •

Copy link
Copy Markdown
Member

Fix #5917 ; Follow-up of #6223. Since I still need to add change log and then let CI run to enable merge button, I have skipped the CI for now.

See https://gist.github.com/pllim/3a76f3ea1dd0bd394a2dbe1614faae31 for how this would work.

TODO:

p.s. Took me 2 minutes to implement the code, but 2 hours to test... 😅

@pllim pllim added Affects-dev PRs and issues that do not impact an existing Astropy release testing labels Jul 5, 2017
@pllim pllim added this to the v2.0.0 milestone Jul 5, 2017
@pllim
pllim requested a review from bsipocz July 5, 2017 18:01
@astropy-bot

astropy-bot Bot commented Jul 5, 2017 •

Copy link
Copy Markdown

Hi there @pllim 👋 - thanks for the pull request! I'm just a friendly 🤖 that checks for issues related to the changelog and making sure that this pull request is milestoned and labelled correctly. This is mainly intended for the maintainers, so if you are not a maintainer you can ignore this, and a maintainer will let you know if any action is required on your part 😃.

I noticed the following issue with this pull request:

  • Changelog entry section (vNew Features) inconsistent with milestone (v2.0.0)

Would it be possible to fix this? Thanks!

@bsipocz

bsipocz commented Jul 5, 2017

Copy link
Copy Markdown
Member

@eteq @astrofrog - We can still add this to the release, right? Please :)

@astrofrog astrofrog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems sensible to me. I think it'd be fine to backport.

@bsipocz

bsipocz commented Jul 5, 2017

Copy link
Copy Markdown
Member

Except it doesn't seem to be working, but I'm about to leave so it was just a very quick test.

@pllim - could you check whether having this as your astropy version, the tests pass on reproject dev, when you do:

enable_deprecations_as_exceptions(warnings_to_ignore_entire_module=['pytest_arraydiff'])

There are a bunch of AstropyDeprecationWarnings coming from pytest arraydiff when using astropy dev, and the whole motivation was that upstream issues like this shouldn't really affect reproject tests as in most cases we can do nothing about them.

@pllim

pllim commented Jul 5, 2017

Copy link
Copy Markdown
Member Author

This only catch DeprecationWarning; AstropyDeprecationWarning is a sllightly different beast. If all you worry about is AstropyDeprecationWarning, maybe all you need is include_astropy_deprecations=False option. I check and let you know.

@pllim

pllim commented Jul 5, 2017

Copy link
Copy Markdown
Member Author

To be more specific, AstropyDeprecationWarning is not really a subclass of DeprecationWarning; I don't know why it is designed so:

class AstropyWarning(Warning):
    """
    The base warning class from which all Astropy warnings should inherit.

    Any warning inheriting from this class is handled by the Astropy logger.
    """

class AstropyDeprecationWarning(AstropyWarning):
    """
    A warning class to indicate a deprecated feature.
    """

class AstropyPendingDeprecationWarning(PendingDeprecationWarning, AstropyWarning):
    """
    A warning class to indicate a soon-to-be deprecated feature.
    """

@astrofrog

Copy link
Copy Markdown
Member

To be more specific, AstropyDeprecationWarning is not really a subclass of DeprecationWarning; I don't know why it is designed so:

@pllim - because DeprecationWarning is hidden by default and we didn't want that to be the case for Astropy deprecation warnings, by design

@pllim

pllim commented Jul 5, 2017

Copy link
Copy Markdown
Member Author

I am wary of extending this new keyword option to also include AstropyDeprecationWarning, as it might be very confusing since we already have include_astropy_deprecations keyword.

@eteq

eteq commented Jul 5, 2017 •

Copy link
Copy Markdown
Member

@pllim - I think the idea was that @bsipocz wants the fine-grained control this implemented but for the astropy deprecation warnings? If I'm interpreting this right, then I think the idea is that include_astropy_deprecations=True and warnings_to_ignore_entire_module=['somemod'] would mean ignore both regular and astropy deprecation warnings for somemod?

(And just to be clear, I'm 👍 to this idea, but think it's much more useful if it applies to the Astropy deprecation machinery)

@pllim

pllim commented Jul 5, 2017

Copy link
Copy Markdown
Member Author

@eteq , if you set include_astropy_deprecations=False (not True as you wrote), this code below will be skipped:

    if _include_astropy_deprecations:
        warnings.filterwarnings("error", ".*", AstropyDeprecationWarning)
        warnings.filterwarnings("error", ".*", AstropyPendingDeprecationWarning)

Therefore, just by setting include_astropy_deprecations=False, AstropyDeprecationWarning will no longer be treated as error, which makes warnings_to_ignore_entire_module (if we change it to only handle AstropyDeprecationWarning) redundant.

@pllim

pllim commented Jul 5, 2017

Copy link
Copy Markdown
Member Author

@eteq , oh wait... Maybe I misunderstood you in my comment above... 🤔

@eteq

eteq commented Jul 5, 2017 •

Copy link
Copy Markdown
Member

@pllim - yeah, I meant that if you do choose True, I think @bsipocz wanted (in #5917) to have the filter that you've added here to also apply to the AstropyDeprecationWarning and AstropyPendingDeprecationWarning...

Although I'm mostly channeling @bsipocz here, so she might know better what she meant 😉

Comment thread astropy/tests/helper.py Outdated
# This ignores all deprecation warnings from given module(s),
# not just on import, for use of Astropy affiliated packages.
for m in _warnings_to_ignore_entire_module:
warnings.filterwarnings('ignore', category=DeprecationWarning,

@eteq eteq Jul 5, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it work to just add below here:

if _include_astropy_deprecations:
    warnings.filterwarnings('ignore', category= AstropyDeprecationWarning, module=m)
    warnings.filterwarnings('ignore', category= AstropyPendingDeprecationWarning, module=m)

to address #6334 (comment) ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense. I'll add that and see if it works.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pllim
pllim force-pushed the ignore-mod-warn branch from 831b772 to 8b6deab Compare July 5, 2017 20:16
@pllim

pllim commented Jul 5, 2017

Copy link
Copy Markdown
Member Author

"Changelog entry present but Affects-dev label set" -- o_O so strict... How do I make astropy-bot happy and still have correct label and modified change log?

@pllim

pllim commented Jul 5, 2017

Copy link
Copy Markdown
Member Author
  1. I added a commit as @eteq suggested but I don't have time to test it against reproject until tomorrow. I will do that until you get to it first in Europe while I am still sleeping tonight.
  2. Is the change log refactor going into 2.0? Should I rebase?
  3. I updated my Gist to include Scenario 6 with Brigitta's use case.

@eteq

eteq commented Jul 5, 2017

Copy link
Copy Markdown
Member

@pllim - I think @bsipocz wanted this for 2.0, so that's the target! (we're probably delaying the release one more day for the package maintainers to catch up)

Also, agreed that @astropy-bot is being a bit strict here. A workaround would be to drop affects-dev, merge, and then put the label back on? But I also reated astropy/astropy-bot#8 ...

@bsipocz bsipocz removed the Affects-dev PRs and issues that do not impact an existing Astropy release label Jul 5, 2017
@astrofrog

Copy link
Copy Markdown
Member

Technically speaking the astropy-bot status check is non-blocking, so you can merge anyway even if it fails - thus, no need to play around with removing/adding labels.

@bsipocz

bsipocz commented Jul 5, 2017

Copy link
Copy Markdown
Member

I've dropped Affects-dev, as it's mostly means that no changelog entry needed because the issue doesn't affect a release and thus users.

@bsipocz

bsipocz commented Jul 5, 2017

Copy link
Copy Markdown
Member

So, what I really wanted originally is to filter both DeprecationWarnings and AstropyDeprecationWarnings if they are triggered by the module/package that is listed. E.g. we list pytest-arraydiff as it triggers AstropyDeprectionWarnings from astropy(*) as it hasn't been updated to use the latest astropy kwarg names.
Turning off include_astropy_deprecations=False I think backfires, as it turns off everything, even if it's triggered by reproject code, or by another affiliates that subclassed this warning and that reproject may use.

(*) actually this can be tricky, as the warnings are actually coming from astropy itself, but the problematic code is in pytest-arraydiff.

@bsipocz

bsipocz commented Jul 5, 2017

Copy link
Copy Markdown
Member

OK. I can confirm that this now works with reproject if:

enable_deprecations_as_exceptions(warnings_to_ignore_entire_module=['pytest_arraydiff', 'astropy'])

But not when

enable_deprecations_as_exceptions(warnings_to_ignore_entire_module=['pytest_arraydiff'])

@pllim

pllim commented Jul 5, 2017

Copy link
Copy Markdown
Member Author

Hmm. Adding "astropy" to that list will theoretically ignore all warnings from Astropy, which is basically same as "include_astropy_deprecations=False", no?

@bsipocz

bsipocz commented Jul 5, 2017

Copy link
Copy Markdown
Member

Actually setting "include_astropy_deprecations=False" means that all AstropyDeprecationWarning gets ignored independently of where they were raised.

So listing packages in warnings_to_ignore_entire_module is much better, gives a better control. So while this PR is still not what I had in mind (which may be a nonsense anyway), it's definitely a huge improvement.

@bsipocz
bsipocz force-pushed the ignore-mod-warn branch from 8b6deab to 2310c3f Compare July 5, 2017 23:36
@bsipocz

bsipocz commented Jul 5, 2017

Copy link
Copy Markdown
Member

Rebased to resolve CHANGELOG conflict.

@astrofrog - the bot doesn't like the new changelog format....

@astrofrog

Copy link
Copy Markdown
Member

@bsipocz - will fix the bot tomorrow, now that I can parse the rst normally this should be easy to do in a general way (can't simply replace '-----' by '=====' since some changelogs use '-----' for the version headers...)

@bsipocz

bsipocz commented Jul 6, 2017

Copy link
Copy Markdown
Member

I've tried to look into this more, but cannot find a solution. Even though the deprecated usage happens in pytest-arraydiff, the actual warning is coming from astropy, and I didn't find any way to get the name of the module from the second to last step of the traceback.

Thus I think we should merge this once CI passed as it still provides a valuable improvement.

@bsipocz bsipocz added the zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now. label Jul 6, 2017
@bsipocz
bsipocz merged commit 7e6fbc0 into astropy:master Jul 6, 2017
@bsipocz

bsipocz commented Jul 6, 2017

Copy link
Copy Markdown
Member

Thanks @pllim!

@pllim

pllim commented Jul 6, 2017

Copy link
Copy Markdown
Member Author

Would it be better if there's a way to include specific message to ignore, as an addition to this? I see that this already merged, so any improvement can be for 2.0.1 or 3.0, if desired. Sorry it's not the ideal solution you were looking for.

@pllim
pllim deleted the ignore-mod-warn branch July 6, 2017 00:45
@bsipocz

bsipocz commented Jul 6, 2017

Copy link
Copy Markdown
Member

@pllim - I'm not sure the solution I was looking for actually exists, and this is definitely an improvement.

bsipocz added a commit that referenced this pull request Jul 6, 2017
Enable ignoring deprecation warnings from entire module
@MSeifert04 MSeifert04 removed the zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now. label Oct 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants