Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/arviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
info = ""


class MigrationError(RuntimeError):
"""Error raised when a legacy name is accessed on the ``arviz`` namespace."""
class MigrationWarning(DeprecationWarning):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
class MigrationWarning(DeprecationWarning):
class MigrationWarning(FutureWarning):

DeprecationWarning is intended for devs and is less visible than FutureWarning.

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.

I would actually argue it should be a subclass of UserWarning. It is very much a present issue and the vast majority of InferenceData use will be broken now. Only type hints, and things like isinstance(...) or calling a handful of methods without keyword arguments will continue to work.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I subclassed it from both warning types; UserWarning first

"""Warning raised when a legacy name is accessed on the ``arviz`` namespace."""


try:
Expand Down Expand Up @@ -104,11 +104,17 @@ class MigrationError(RuntimeError):
def __getattr__(name):
"""Guide users who expect legacy names on the ``arviz`` namespace."""
if name == "InferenceData":
raise MigrationError(
import warnings
from xarray import DataTree

warnings.warn(
"arviz.InferenceData is no longer available on the "
"arviz package; ArviZ now uses xarray's DataTree for the same "
f"role. See the migration guide: {_MIGRATION_GUIDE_URL}"
f"role. See the migration guide: {_MIGRATION_GUIDE_URL}",
Comment thread
aloctavodia marked this conversation as resolved.
MigrationWarning,
)

return DataTree
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


Expand Down
11 changes: 6 additions & 5 deletions tests/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import arviz_plots
import arviz_stats
import pytest
from xarray import DataTree

import arviz as az

Expand All @@ -33,10 +34,10 @@ def test_info_attr():

def test_aliases():
# These are xarray aliases exposed for user convenience
xarray_aliases = {"from_netcdf", "from_zarr"}
xarray_aliases = {"from_netcdf", "from_zarr", "InferenceData"}

for obj_name in dir(az):
if not obj_name.startswith("_") and obj_name not in ["info", "MigrationError"]:
if not obj_name.startswith("_") and obj_name not in ["info", "MigrationWarning"]:
obj = getattr(az, obj_name)

if obj_name in xarray_aliases:
Expand Down Expand Up @@ -88,15 +89,15 @@ def test_incompatible_package_versions(monkeypatch):

def test_inference_data_import_points_to_migration_guide():
"""Legacy arviz.InferenceData should error with a link to the migration guide."""
with pytest.raises(az.MigrationError, match="https://python.arviz.org/.*/migration_guide.*"):
with pytest.warns(az.MigrationWarning, match="https://python.arviz.org/.*/migration_guide.*"):
from arviz import InferenceData

InferenceData
assert InferenceData is DataTree


def test_inference_data_getattr_points_to_migration_guide():
"""Legacy arviz.InferenceData should error with a link to the migration guide."""
with pytest.raises(az.MigrationError, match="https://python.arviz.org/.*/migration_guide.*"):
with pytest.warns(az.MigrationWarning, match="https://python.arviz.org/.*/migration_guide.*"):
az.InferenceData


Expand Down