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

Treat warnings as errors in tests #1182

Merged
merged 47 commits into from
Oct 24, 2023
Merged

Treat warnings as errors in tests #1182

merged 47 commits into from
Oct 24, 2023

Conversation

flying-sheep
Copy link
Member

@flying-sheep flying-sheep commented Oct 10, 2023

Huh, this was surprisingly low pain.

Deprecation/change fixes:

Bugfixes

  • write_h5ad’s as_dense failed to add IOSpec attrs
  • ExperimentalFeatureWarning
    1. got silenced after the first occurrence even in tests. Now it’s only silenced in non-test code after the first occurrence.
    2. one reason why it got raised so much in the first place is that we initialize AnnData objects in functions and methods like concat, copy, or read_*. All these places now suppress the warning.
  • re_raise_error made the traceback harder to understand, so I replaced it with add_key_note, which doesn’t raise the error. Raising it from inside the except block using plain raise works as expected.

Deferred

  • adata.uns[key] = ak.Array(...) didn’t raise a warning and doesn’t do so now.

@codecov
Copy link

codecov bot commented Oct 10, 2023

Codecov Report

Merging #1182 (4a0792d) into main (8ffe21e) will decrease coverage by 2.35%.
Report is 1 commits behind head on main.
The diff coverage is 90.90%.

❗ Current head 4a0792d differs from pull request most recent head 37f5a03. Consider uploading reports for the commit 37f5a03 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1182      +/-   ##
==========================================
- Coverage   85.03%   82.68%   -2.35%     
==========================================
  Files          36       36              
  Lines        5385     5407      +22     
==========================================
- Hits         4579     4471     -108     
- Misses        806      936     +130     
Flag Coverage Δ
gpu-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
anndata/_core/aligned_mapping.py 91.47% <100.00%> (-0.04%) ⬇️
anndata/_core/anndata.py 83.49% <100.00%> (+0.02%) ⬆️
anndata/_io/read.py 80.72% <100.00%> (ø)
anndata/_io/utils.py 76.66% <100.00%> (ø)
anndata/_io/zarr.py 82.92% <100.00%> (ø)
anndata/compat/__init__.py 77.67% <100.00%> (-1.40%) ⬇️
anndata/experimental/merge.py 91.28% <ø> (ø)
anndata/experimental/multi_files/_anncollection.py 70.68% <100.00%> (ø)
anndata/_core/merge.py 82.70% <93.75%> (-11.77%) ⬇️
anndata/utils.py 83.76% <82.75%> (-0.85%) ⬇️

... and 6 files with indirect coverage changes

@flying-sheep flying-sheep marked this pull request as ready for review October 10, 2023 10:41
@flying-sheep flying-sheep added this to the 0.10.2 milestone Oct 10, 2023
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Comment on lines 65 to 77
# TODO: fix all the exceptions here
# replacing “:initializing view as actual” and “:Transforming to str index”
# with “::anndata._warnings.ImplicitModificationWarning” breaks,
# because we’re neither using editable installs nor a src/ layout
- script: >
pytest
-W error
-W 'default:initializing view as actual:UserWarning'
-W 'default:Transforming to str index:UserWarning'
-W 'default:Observation names are not unique. To make them unique:UserWarning'
-W 'default:Variable names are not unique. To make them unique:UserWarning'
-W 'default::scipy.sparse._base.SparseEfficiencyWarning'
-W 'default::dask.array.core.PerformanceWarning'
Copy link
Member Author

@flying-sheep flying-sheep Oct 10, 2023

Choose a reason for hiding this comment

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

These are follow-up issues:

  • our ImplicitModificationWarning and names are not unique warnings should be fixed in lib code and caught in test code so we can be sure none of our functions/methods invoke them, only user/test code.
  • scipy SparseEfficiencyWarning and dask PerformanceWarning should be fixed, they probably indicate real performance issues

If these were in filterwarnings and we wouldn’t have to deal with ImportPathMismatchErrors, these would be

filterwarnings = [
    'error',
    'default::anndata._warnings.ImplicitModificationWarning',
    'default:.*names are not unique. To make them unique:UserWarning',
    'default::scipy.sparse._base.SparseEfficiencyWarning',
    'default::dask.array.core.PerformanceWarning',
]

All of them have at least like 60 instances (sure, some are parametrized tests) and would therefore need a bit of work to be fixed.

Not in this PR.

@flying-sheep flying-sheep requested a review from ivirshup October 10, 2023 16:25
@flying-sheep
Copy link
Member Author

only the two checkmarks in the original comment left.

Copy link
Member

@ivirshup ivirshup left a comment

Choose a reason for hiding this comment

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

awkward.to_categorical was deprecated in favor of awkward.str.to_categorical, which depends on pyarrow. Is making pyarrow a test dep OK or should we ignore/circuvent this?

Totally fine


write_h5ad’s as_dense failed to add IOSpec attrs

Good catch!


ExperimentalFeatureWarning

  • got silenced after the first occurrence even in tests. Now it’s only silenced in non-test code after the first occurrence.
  • one reason why it got raised so much in the first place is that we initialize AnnData objects in functions and methods like concat, copy, or read_*. All these places now suppress the warning.

Aren't these two points in conflict? If it was being silenced in tests, why do we see it raised so many times in the tests? Even from the same location:

Locations of ExperimentalFeatureWarning from `test_concatenate.py` on main
anndata/_core/aligned_mapping.py:64: 8 warnings
anndata/tests/test_base.py: 3 warnings
anndata/tests/test_concatenate.py: 53 warnings
anndata/tests/test_awkward.py: 39 warnings
anndata/tests/test_hdf5_backing.py: 98 warnings
anndata/tests/test_inplace_subset.py: 70 warnings
anndata/tests/test_io_elementwise.py: 10 warnings
anndata/tests/test_io_conversion.py: 17 warnings
anndata/tests/test_helpers.py: 4 warnings
anndata/tests/test_readwrite.py: 15 warnings
anndata/tests/test_io_dispatched.py: 3 warnings
anndata/tests/test_views.py: 245 warnings
anndata/tests/test_transpose.py: 13 warnings
anndata/tests/test_x.py: 7 warnings
  /Users/isaac/github/anndata/anndata/_core/aligned_mapping.py:64: ExperimentalFeatureWarning: Support for Awkward Arrays is currently experimental. Behavior may change in the future. Please report any issues you may encounter!
    warnings.warn(

This makes me think pytest was reseting the warnings filter by itself, so we don't need to.

Also, I think we shouldn't be catching this warning so many places in the library code. These all seem like places we may want to actually throw this class of warning. I'm fine with larger changes with lots of catching in the test suite, but don't want to make large scale changes to the library code for this.

Could we add a very awkward array assignment specific filter globally to the code of the test suite, then selectively turn it off?

anndata/_core/anndata.py Show resolved Hide resolved
anndata/_core/anndata.py Outdated Show resolved Hide resolved
anndata/_core/merge.py Outdated Show resolved Hide resolved
anndata/_core/merge.py Outdated Show resolved Hide resolved
anndata/_core/merge.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
anndata/utils.py Outdated Show resolved Hide resolved
@ivirshup
Copy link
Member

Also I think this could get a release note for any upstream deprecation warnings it fixes.

Co-authored-by: Isaac Virshup <[email protected]>
anndata/_io/write.py Outdated Show resolved Hide resolved
anndata/tests/helpers.py Outdated Show resolved Hide resolved
@ivirshup ivirshup mentioned this pull request Oct 10, 2023
1 task
@ivirshup ivirshup removed this from the 0.10.2 milestone Oct 10, 2023
Copy link
Member

@ivirshup ivirshup left a comment

Choose a reason for hiding this comment

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

In principal I approve, I've just made suggestions on a few minor things that I think were left over from stuff left to other PRs.

Mostly formatting

.azure-pipelines.yml Outdated Show resolved Hide resolved
anndata/_io/specs/methods.py Outdated Show resolved Hide resolved
anndata/tests/helpers.py Outdated Show resolved Hide resolved
anndata/tests/test_dask.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@flying-sheep
Copy link
Member Author

@ivirshup ping

Copy link
Member

@ivirshup ivirshup left a comment

Choose a reason for hiding this comment

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

Apart from the one comment this is good to go

@flying-sheep flying-sheep enabled auto-merge (squash) October 24, 2023 15:40
@flying-sheep flying-sheep merged commit 00f39eb into main Oct 24, 2023
11 checks passed
@flying-sheep flying-sheep deleted the fix-warnings branch October 24, 2023 16:45
meeseeksmachine pushed a commit to meeseeksmachine/anndata that referenced this pull request Oct 24, 2023
ivirshup pushed a commit that referenced this pull request Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Catch lots of subtle bugs by setting -Werror in tests
2 participants