Skip to content
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

Filter warnings #764

Merged
merged 16 commits into from
Jan 19, 2021
Merged

Filter warnings #764

merged 16 commits into from
Jan 19, 2021

Conversation

andLaing
Copy link
Collaborator

Suppresses expected warnings in MC writer and tests as well as tidying imports.

@andLaing andLaing requested a review from jacg December 23, 2020 18:23
Copy link
Collaborator

@jacg jacg left a comment

Choose a reason for hiding this comment

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

Please add closes #762 to the commit message of this commit.

@jacg
Copy link
Collaborator

jacg commented Dec 26, 2020

I trust that we agree that, wherever possible, rather than suppressing or ignoring the warning, the cause of the warning should be removed.

In some cases (for example, in a test that checks the behaviour of the code in precisely the situation that is being warned about) it's obvious that the warning should simply be ignored. In other cases, this isn't obvious.

Can you give some justifications of the cases where warnings are being ignored rather than their causes being removed? Ideally these would appear in the commit messages of the relevant commit (or a comment at the point of suppression).

@jacg
Copy link
Collaborator

jacg commented Dec 26, 2020

This one still shows up on Travis:

invisible_cities/reco/tbl_functions.py:92
  /home/travis/build/next-exp/IC/invisible_cities/reco/tbl_functions.py:92: DeprecationWarning: invalid escape sequence \d
    pattern = re.compile('NEXT_v\d[_\d+]+[_\w]+?_(?P<fnumber>\d+)_[_\w]+?_(?P<nevts>\d+)\..*',

I think that preceding the string with r (i.e. r'NEXT_v\d...') should do the trick.

@andLaing
Copy link
Collaborator Author

I trust that we agree that, wherever possible, rather than suppressing or ignoring the warning, the cause of the warning should be removed.

Yes, I think they are justified although in some cases there might be alternatives. The OptimizeWarning for example could maybe be fixed but since there's a random generator involved maybe it would just be fixed for certain machines. I've added to the commit messages and put comments where possible to explain the motivation.

This one still shows up on Travis:

Should be we be worried that it only shows up on Travis? Especially since it's a DeprecationWarning, doesn't that mean that we have some version differences between what Travis uses and what's downloaded by the scripts? Seem unstable.

@andLaing
Copy link
Collaborator Author

Now two new warnings hace appeared, there might be something going on behind the scenes

@jacg
Copy link
Collaborator

jacg commented Dec 29, 2020

Apologies for the silence. I am afraid that I will be unavailable for some time.

Copy link
Collaborator

@mmkekic mmkekic left a comment

Choose a reason for hiding this comment

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

Probably should also look into filterwarnings of pytest.ini file. One (import error of collections) is fixed in 06f09f9 so maybe you can just cherry-pick it.

def test_mcsensors_from_file_fast_returns_empty(ICDATADIR):
file_in = os.path.join(ICDATADIR, "nexus_new_kr83m_fast.newformat.sim.h5")
sns_gen = mcsensors_from_file([file_in], 'new', -7951)
first_evt = next(sns_gen)
with warnings.catch_warnings():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here you do expect No binning info available. so maybe you can use

with pytest.warns(UserWarning, match='No binning info available.'):
        first_evt = next(sns_gen)

@@ -109,7 +109,7 @@ def df_writer(h5out : tb.file.File ,

data_types = table.dtype
if len(arr) == 0:
warnings.warn(f'dataframe is empty', UserWarning)
warnings.warn('dataframe is empty', UserWarning)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know that this is not strictly related to this PR but I wonder if we really need this warnings. For example, in pandas to_hdf no warning is raised if dataframe is empty, so maybe we should just keep the same behavior, ie removing the warning completely. Especially since it is almost never guaranteed to have non-empty df in our flows...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Anybody care to share an opinion on this?

Does anyone ever notice or appreciate this warning appearing? Can anyone remember an instance when this warning helped them? If not, it should probably go.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Marija and I discussed it and we decided to remove it in the final version of this PR. That's why it shows as outdated above.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that it shows as outdated, because you have rebased, and the commit id has changed. In my latest checkout of the branch, I can still see the warning being raised (strangely enough, with the superfluous 'f' which was removed here!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Strange. It's changed in the first commit of the current history and I can't find anywhere in the other commits where it could have been accidentally reintroduced.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Apologies. I failed to notice that a Git LFS error prevented me from looking at the right branch. I confirm that it's gone from the current version.

@jmbenlloch jmbenlloch mentioned this pull request Jan 11, 2021
@jacg
Copy link
Collaborator

jacg commented Jan 19, 2021

@andLaing You wrote 'closes issue #762' in the commit message, but I think that the presence of 'issue' between 'closes' and '#762' interferes with the pattern that GitHub recognizes: https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword

@andLaing
Copy link
Collaborator Author

Ah, ok, it seemed more natural to specify but I should have checked the standard. My bad, I'll edit the commit message now

@jacg
Copy link
Collaborator

jacg commented Jan 19, 2021

A fresh installation on a pristine Debian 10 with both Python 3.7 and 3.8 passes all tests with zero warnings.

The latest Travis run produces this single warning:

/home/travis/miniconda/envs/IC-3.7-2020-06-16/lib/python3.7/site-packages/pandas/core/dtypes/missing.py:478
  /home/travis/miniconda/envs/IC-3.7-2020-06-16/lib/python3.7/site-packages/pandas/core/dtypes/missing.py:478: RuntimeWarning: invalid value encountered in equal
    return ((left == right) | (isna(left) & isna(right))).all()

Anyone recognize this?

(The Mac OS run fails, but we'll deal with that in a separate PR.)

@jacg
Copy link
Collaborator

jacg commented Jan 19, 2021

Some of the commit messages contain justifications/explanations of why warnings are suppressed/ignored. These should probably be added as comments in the code itself.

@jacg
Copy link
Collaborator

jacg commented Jan 19, 2021

Minor niggle: in 'Change string to r-string in tbl_functions_test' the commit message contains 'Suppress DeprecationWarning', but the warning isn't being suppressed (which would require justification) bit it's being heeded (which requires no further explanation).

@jacg
Copy link
Collaborator

jacg commented Jan 19, 2021

We should also do a review of all the skipped and xfail tests. Probably in a separate PR, unless it can be done quickly.

@jacg
Copy link
Collaborator

jacg commented Jan 19, 2021

Latest Travis run shows no warnings.

Add justifications (from commit messages) as comments to source code, and I'm ready to approve.

@jacg
Copy link
Collaborator

jacg commented Jan 19, 2021

Should be we be worried that it only shows up on Travis? Especially since it's a DeprecationWarning, doesn't that mean that we have some version differences between what Travis uses and what's downloaded by the scripts?

In theory, our manage.sh (or Nix, or whatever we choose to use) should give us identical environments on test, production and development machines. It might be something to do with the Travis test profile asking Hypothesis to produce more cases, and thus dodgy cases (which raise warnings) being found more frequently on Travis. In any case, I agree that it's probably flaky, and that we can probably live with it appearing every now and then.

Copy link
Collaborator

@jacg jacg left a comment

Choose a reason for hiding this comment

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

All stable warnings have been eliminated, either by addressing the issue they point out, or, where appropriate, ignoring them explicitly. In the latter cases, justifications have been added to both the commit messages and as comments to the code.

This eliminates the deluge of warnings that accompanied each run of the test suite, causing all warnings to be ignored by any humans looking at the test output.

We should go through a similar exercise for skipped and xfailing tests in a separate PR.

@carmenromo carmenromo merged commit 2b42efa into next-exp:master Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants