Skip to content

Commit 70e2527

Browse files
Revive ArviZ aliases, but raise DeprecationWarning on old wrappers
Also see #4536 where the wrappers were brought back for v3. Closes #4528
1 parent b2e64cb commit 70e2527

File tree

6 files changed

+93
-13
lines changed

6 files changed

+93
-13
lines changed

RELEASE-NOTES.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
## PyMC3 vNext (4.0.0)
44
### Breaking Changes
55
- ⚠ Theano-PyMC has been replaced with Aesara, so all external references to `theano`, `tt`, and `pymc3.theanof` need to be replaced with `aesara`, `aet`, and `pymc3.aesaraf` (see [4471](https://github.com/pymc-devs/pymc3/pull/4471)).
6+
- ArviZ `plots` and `stats` *wrappers* were removed. The functions are now just available by their original names (see [#4549](https://github.com/pymc-devs/pymc3/pull/4471) and `3.11.2` release notes).
7+
- ...
68

79
### New Features
810
- The `CAR` distribution has been added to allow for use of conditional autoregressions which often are used in spatial and network models.

docs/source/api/plots.rst

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ Plots
77
Plots are delegated to the
88
`ArviZ <https://arviz-devs.github.io/arviz/index.html>`_.
99
library, a general purpose library for
10-
"exploratory analysis of Bayesian models."
11-
Refer to its documentation to use the plotting functions directly.
10+
"exploratory analysis of Bayesian models".
1211

13-
.. automodule:: pymc3.plots.posteriorplot
14-
:members:
12+
Functions from the `arviz.plots` module are available through ``pymc3.<function>`` or ``pymc3.plots.<function>``,
13+
but for their API documentation please refer to the :ref:`ArviZ documentation <arviz:plot_api>`.

docs/source/api/stats.rst

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
*****
22
Stats
33
*****
4+
5+
.. currentmodule:: pymc3.stats
6+
47
Statistics and diagnostics are delegated to the
58
`ArviZ <https://arviz-devs.github.io/arviz/index.html>`_.
69
library, a general purpose library for
7-
"exploratory analysis of Bayesian models."
8-
Refer to its documentation to use the diagnostics functions directly.
10+
"exploratory analysis of Bayesian models".
11+
12+
Functions from the `arviz.stats` module are available through ``pymc3.<function>`` or ``pymc3.stats.<function>``,
13+
but for their API documentation please refer to the :ref:`ArviZ documentation <arviz:stats_api>`.

pymc3/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def __set_compiler_flags():
6262
from pymc3.plots import *
6363
from pymc3.sampling import *
6464
from pymc3.smc import *
65+
from pymc3.stats import *
6566
from pymc3.step_methods import *
6667
from pymc3.tests import test
6768
from pymc3.tuning import *

pymc3/plots/__init__.py

+49-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 The PyMC Developers
1+
# Copyright 2021 The PyMC Developers
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -12,19 +12,61 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""PyMC3 Plotting.
15+
"""Alias for the `plots` submodule from ArviZ.
1616
17-
Plots are delegated to the `ArviZ <https://arviz-devs.github.io/arviz/>`_ library, a general purpose library for
18-
exploratory analysis of Bayesian models. For more details, see https://arviz-devs.github.io/arviz/.
19-
20-
Only `plot_posterior_predictive_glm` is kept in the PyMC code base for now, but it will move to ArviZ once the latter adds features for regression plots.
17+
Plots are delegated to the ArviZ library, a general purpose library for
18+
"exploratory analysis of Bayesian models."
19+
See https://arviz-devs.github.io/arviz/ for details on plots.
2120
"""
2221
import functools
2322
import sys
2423
import warnings
2524

2625
import arviz as az
2726

27+
# Makes this module as identical to arviz.plots as possible
28+
for attr in az.plots.__all__:
29+
obj = getattr(az.plots, attr)
30+
if not attr.startswith("__"):
31+
setattr(sys.modules[__name__], attr, obj)
32+
33+
34+
def alias_deprecation(func, alias: str):
35+
original = func.__name__
36+
37+
@functools.wraps(func)
38+
def wrapped(*args, **kwargs):
39+
raise DeprecationWarning(
40+
f"The function `{alias}` from PyMC3 was an alias for `{original}` from ArviZ. "
41+
"It was removed in PyMC3 4.0. "
42+
f"Switch to `pymc3.{original}` or `arviz.{original}`."
43+
)
44+
45+
return wrapped
46+
47+
48+
# Aliases of ArviZ functions
49+
autocorrplot = alias_deprecation(az.plot_autocorr, alias="autocorrplot")
50+
forestplot = alias_deprecation(az.plot_forest, alias="forestplot")
51+
kdeplot = alias_deprecation(az.plot_kde, alias="kdeplot")
52+
energyplot = alias_deprecation(az.plot_energy, alias="energyplot")
53+
densityplot = alias_deprecation(az.plot_density, alias="densityplot")
54+
pairplot = alias_deprecation(az.plot_pair, alias="pairplot")
55+
traceplot = alias_deprecation(az.plot_trace, alias="traceplot")
56+
compareplot = alias_deprecation(az.plot_compare, alias="compareplot")
57+
58+
2859
from pymc3.plots.posteriorplot import plot_posterior_predictive_glm
2960

30-
__all__ = ["plot_posterior_predictive_glm"]
61+
__all__ = tuple(az.plots.__all__) + (
62+
"autocorrplot",
63+
"compareplot",
64+
"forestplot",
65+
"kdeplot",
66+
"plot_posterior",
67+
"traceplot",
68+
"energyplot",
69+
"densityplot",
70+
"pairplot",
71+
"plot_posterior_predictive_glm",
72+
)

pymc3/stats/__init__.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2021 The PyMC Developers
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Alias for the `stats` submodule from ArviZ.
16+
17+
Diagnostics and auxiliary statistical functions are delegated to the ArviZ library, a general
18+
purpose library for "exploratory analysis of Bayesian models."
19+
See https://arviz-devs.github.io/arviz/ for details.
20+
"""
21+
import sys
22+
23+
import arviz as az
24+
25+
for attr in az.stats.__all__:
26+
obj = getattr(az.stats, attr)
27+
if not attr.startswith("__"):
28+
setattr(sys.modules[__name__], attr, obj)
29+
30+
31+
__all__ = tuple(az.stats.__all__)

0 commit comments

Comments
 (0)