File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717import functools
1818import logging
1919import re
20+ import warnings
2021
21- from xarray import open_datatree as from_netcdf
22+ from xarray import open_datatree as from_netcdf , DataTree
2223
2324from_zarr = functools .partial (from_netcdf , engine = "zarr" )
2425
2728info = ""
2829
2930
30- class MigrationError ( RuntimeError ):
31- """Error raised when a legacy name is accessed on the ``arviz`` namespace."""
31+ class MigrationWarning ( DeprecationWarning ):
32+ """Warning raised when a legacy name is accessed on the ``arviz`` namespace."""
3233
3334
3435try :
@@ -104,11 +105,13 @@ class MigrationError(RuntimeError):
104105def __getattr__ (name ):
105106 """Guide users who expect legacy names on the ``arviz`` namespace."""
106107 if name == "InferenceData" :
107- raise MigrationError (
108+ warnings . warn (
108109 "arviz.InferenceData is no longer available on the "
109110 "arviz package; ArviZ now uses xarray's DataTree for the same "
110- f"role. See the migration guide: { _MIGRATION_GUIDE_URL } "
111+ f"role. See the migration guide: { _MIGRATION_GUIDE_URL } " ,
112+ MigrationWarning ,
111113 )
114+ return DataTree
112115 raise AttributeError (f"module { __name__ !r} has no attribute { name !r} " )
113116
114117
Original file line number Diff line number Diff line change 1818import arviz_plots
1919import arviz_stats
2020import pytest
21+ from xarray import DataTree
2122
2223import arviz as az
2324
@@ -88,15 +89,15 @@ def test_incompatible_package_versions(monkeypatch):
8889
8990def test_inference_data_import_points_to_migration_guide ():
9091 """Legacy arviz.InferenceData should error with a link to the migration guide."""
91- with pytest .raises (az .MigrationError , match = "https://python.arviz.org/.*/migration_guide.*" ):
92+ with pytest .warns (az .MigrationWarning , match = "https://python.arviz.org/.*/migration_guide.*" ):
9293 from arviz import InferenceData
9394
94- InferenceData
95+ assert InferenceData is DataTree
9596
9697
9798def test_inference_data_getattr_points_to_migration_guide ():
9899 """Legacy arviz.InferenceData should error with a link to the migration guide."""
99- with pytest .raises (az .MigrationError , match = "https://python.arviz.org/.*/migration_guide.*" ):
100+ with pytest .warns (az .InferenceData , match = "https://python.arviz.org/.*/migration_guide.*" ):
100101 az .InferenceData
101102
102103
You can’t perform that action at this time.
0 commit comments