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

(feat): io submodule #1682

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open

(feat): io submodule #1682

wants to merge 40 commits into from

Conversation

ilan-gold
Copy link
Contributor

@ilan-gold ilan-gold commented Sep 20, 2024

A brief summary of how this was handled and why:

  1. I moved everything into io related to i/o
  2. I left read_zarr and read_h5ad at the top-level for now, although I think that should be deprecated in favor of everything going through io in the future despite their "high" status above the others. They are now documented as being from io to begin to encourage that behavior although we aren't throwing warnings for e.g., anndata.read_h5ad yet
  3. I also made a backwards compat for people who use from anndata._io import blah since uhhhhhhh yikes by leaving that module alone. However, at least if anyone tries to import from the top-level from anndata._io import read_h5ad, it will warn. Also, I added a public note about this issue since it seems pervasive.
  4. I added tests for the deprecations. For now, we need to check the scanpy imports for warnings but we can open the PR for scanpy before its release to adapt. I think the imports are cached or something so pytest.warns can't run reliably every time because the warning doesn't come every time....not sure what's up with that

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@ilan-gold ilan-gold added skip-gpu-ci topic: io breaking change ‼️ A breaking change that needs a major version update labels Sep 20, 2024
@ilan-gold ilan-gold added this to the 0.11.0 milestone Sep 20, 2024
tests/test_readwrite.py Outdated Show resolved Hide resolved
src/anndata/_core/anndata.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Sep 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.49%. Comparing base (34e9783) to head (a947d3e).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1682      +/-   ##
==========================================
- Coverage   86.87%   84.49%   -2.39%     
==========================================
  Files          39       40       +1     
  Lines        6036     6044       +8     
==========================================
- Hits         5244     5107     -137     
- Misses        792      937     +145     
Flag Coverage Δ
84.49% <100.00%> (?)

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

Files with missing lines Coverage Δ
src/anndata/__init__.py 93.54% <100.00%> (+0.95%) ⬆️
src/anndata/_core/anndata.py 83.72% <100.00%> (ø)
src/anndata/_core/sparse_dataset.py 92.43% <ø> (ø)
src/anndata/_io/__init__.py 100.00% <100.00%> (ø)
src/anndata/_io/read.py 82.60% <ø> (+1.55%) ⬆️
src/anndata/_io/specs/lazy_methods.py 100.00% <ø> (ø)
src/anndata/_types.py 85.29% <ø> (ø)
src/anndata/experimental/__init__.py 100.00% <100.00%> (ø)
src/anndata/io.py 100.00% <100.00%> (ø)
src/anndata/typing.py 100.00% <100.00%> (ø)
... and 1 more

... and 7 files with indirect coverage changes

@ilan-gold ilan-gold marked this pull request as ready for review September 20, 2024 10:16
Copy link
Member

@flying-sheep flying-sheep left a comment

Choose a reason for hiding this comment

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

Very nice and clean! We should add a release note fragment for this change.

We do turn FutureWarnings into errors right? So it’s impossible that you missed one in here, right?

docs/api.md Show resolved Hide resolved
@ilan-gold
Copy link
Contributor Author

ilan-gold commented Sep 20, 2024

We do turn FutureWarnings into errors right? So it’s impossible that you missed one in here, right?

Could you elaborate? When I search FutureWarning in our code base, I don't see anything that might signal they are treated as errors, and a lot of pytest.warns.

@flying-sheep
Copy link
Member

flying-sheep commented Sep 20, 2024

One of our test job runs with --strict-warnings, which turns all warnings into errors except the ones from an allowlist (that exists because we haven’t gotten around to dealing with them).

These are the default filters, applied in every test job:

config.addinivalue_line(
"filterwarnings", "ignore::anndata._warnings.OldFormatWarning"
)
config.addinivalue_line(
"filterwarnings", "ignore::anndata._warnings.ExperimentalFeatureWarning"
)

This is the allowlist:

anndata/pyproject.toml

Lines 148 to 154 in 34e9783

filterwarnings_when_strict = [
"default::anndata._warnings.ImplicitModificationWarning",
"default:Transforming to str index:UserWarning",
"default:(Observation|Variable) names are not unique. To make them unique:UserWarning",
"default::scipy.sparse.SparseEfficiencyWarning",
"default::dask.array.core.PerformanceWarning",
]

This is the code that turns all warnings into errors except the above.

def pytest_collection_modifyitems(
session: pytest.Session, config: pytest.Config, items: Iterable[pytest.Item]
):
if not config.getoption("--strict-warnings"):
return
warning_filters = [
"error",
*_config_get_strlist(config, "filterwarnings"),
*_config_get_strlist(config, "filterwarnings_when_strict"),
]
warning_marks = [pytest.mark.filterwarnings(f) for f in warning_filters]

README.md Outdated Show resolved Hide resolved
src/anndata/__init__.py Outdated Show resolved Hide resolved
src/anndata/_io/specs/lazy_methods.py Outdated Show resolved Hide resolved
src/anndata/_io/__init__.py Show resolved Hide resolved
docs/release-notes/1682.feat.md Outdated Show resolved Hide resolved
@ilan-gold
Copy link
Contributor Author

Sorry at @flying-sheep yes I knew that about stricto-warnings, but I meant about FutureWarning specifically, which is what confused me. In any case I misread "impossible" as "possible" hence my confusion. So yes, it's impossible we missed

Copy link
Member

@flying-sheep flying-sheep left a comment

Choose a reason for hiding this comment

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

Looks great! Two questions

Comment on lines 29 to 30
# We use this in test by attribute access
from . import specs # noqa: F401, E402
Copy link
Member

Choose a reason for hiding this comment

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

Any reason why we shouldn’t just stop doing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would need to investigate what it's doing there or what that comment even means. Maybe an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I deleted it and nothing happened so....

Copy link
Member

@flying-sheep flying-sheep Sep 20, 2024

Choose a reason for hiding this comment

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

I put that import and comment there because Isaac made the tests access this by attribute:

import anndata as ad

do_stuff_with(ad._io.specs.foobar)

instead of importing that submodule. It happened to work because some other code somewhere else caused anndata._io.specs to be imported, but “happens to work because of side effects” is not what I want to build upon.

Now that the tests no longer access stuff that way, this import is no longer necessary.

src/anndata/io/__init__.py Outdated Show resolved Hide resolved
@flying-sheep
Copy link
Member

flying-sheep commented Sep 20, 2024

I got rid of a few more obsolete import hacks: a947d3e

Why breaking change ‼️ A breaking change that needs a major version update ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change ‼️ A breaking change that needs a major version update skip-gpu-ci topic: io
Projects
None yet
Development

Successfully merging this pull request may close these issues.

io submodule
2 participants