Skip to content

Commit

Permalink
(fix): submodule warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan-gold committed Sep 3, 2024
1 parent 1e2930b commit 95d7b74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/anndata/experimental/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
dict(
(kv if isinstance(kv, tuple) else (kv, kv))
for kv in (
"CSRDataset",
"CSCDataset",
("CSRDataset", "abc.CSRDataset"),
("CSCDataset", "abc.CSCDataset"),
"sparse_dataset",
"read_elem",
"write_elem",
Expand All @@ -35,13 +35,23 @@


def __getattr__(attr_name: str) -> Any:
print(_DEPRECATED.get(attr_name))
if new_name := _DEPRECATED.get(attr_name):
rename = f"using its new name {new_name} " if new_name != attr_name else ""
new_sub_name = new_name.split(".")[-1]
rename = (
f"using its new name {new_sub_name} " if new_sub_name != attr_name else ""
)
submodule = "." + ".".join(new_name.split(".")[:-1]) if "." in new_name else ""
msg = (
f"Importing {attr_name} from `anndata.experimental` is deprecated. "
f"Import {rename}from `anndata` directly."
f"Import {rename}from `anndata{submodule}` directly."
)
warnings.warn(msg, FutureWarning)
if "." in new_name:
export = anndata
for subname in new_name.split("."):
export = getattr(export, subname)
return
return getattr(anndata, new_name)
msg = f"module {__name__!r} has no attribute {attr_name!r}"
raise AttributeError(msg)
Expand Down
10 changes: 8 additions & 2 deletions tests/test_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ def test_deprecated_read(tmp_path):
)
def test_warn_on_import_from_experimental(old_name: str, new_name: str):
pattern = rf"Importing {old_name}"
if new_name != old_name:
pattern += rf".*using its new name {new_name}"
if (new_sub_name := new_name.split(".")[-1]) != old_name:
pattern += rf".*using its new name {new_sub_name}"
if "." in new_name:
pattern += (
r".*anndata." + r".".join(new_name.split(".")[:-1])
if "." in new_name
else r""
)
with pytest.warns(FutureWarning, match=pattern):
getattr(anndata.experimental, old_name)

0 comments on commit 95d7b74

Please sign in to comment.