Skip to content

Commit

Permalink
Robustify preview module (#2398)
Browse files Browse the repository at this point in the history
* make preview module more robust

catch import errors so an existing arviz-xyz
broken installation doesn't affect regular arviz

* add info element and logging

* docs and linters

* use markdown file for docs
  • Loading branch information
OriolAbril authored Dec 19, 2024
1 parent 9dbd43e commit adb2fef
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
41 changes: 36 additions & 5 deletions arviz/preview.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
# pylint: disable=unused-import,unused-wildcard-import,wildcard-import
# pylint: disable=unused-import,unused-wildcard-import,wildcard-import,invalid-name
"""Expose features from arviz-xyz refactored packages inside ``arviz.preview`` namespace."""
import logging

_log = logging.getLogger(__name__)

info = ""

try:
from arviz_base import *

status = "arviz_base available, exposing its functions as part of arviz.preview"
_log.info(status)
except ModuleNotFoundError:
pass
status = "arviz_base not installed"
_log.info(status)
except ImportError:
status = "Unable to import arviz_base"
_log.info(status, exc_info=True)

info += status + "\n"

try:
import arviz_stats
from arviz_stats import *

status = "arviz_stats available, exposing its functions as part of arviz.preview"
_log.info(status)
except ModuleNotFoundError:
pass
status = "arviz_stats not installed"
_log.info(status)
except ImportError:
status = "Unable to import arviz_stats"
_log.info(status, exc_info=True)
info += status + "\n"

try:
from arviz_plots import *

status = "arviz_plots available, exposing its functions as part of arviz.preview"
_log.info(status)
except ModuleNotFoundError:
pass
status = "arviz_plots not installed"
_log.info(status)
except ImportError:
status = "Unable to import arviz_plots"
_log.info(status, exc_info=True)

info += status + "\n"
1 change: 1 addition & 0 deletions doc/source/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ API Reference
plot_utils
utils
rcparams
preview
wrappers
stats_refitting
11 changes: 11 additions & 0 deletions doc/source/api/preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(preview_api)=

# Preview
This module give access to upcoming refactored features by exposing
all objects in [arviz-base](https://arviz-base.readthedocs.io/en/latest/),
[arviz-stats](https://arviz-stats.readthedocs.io/en/latest/) and
[arviz-plots](https://arviz-plots.readthedocs.io/en/latest/)
under a single namespace: `arviz.preview`.

In addition, there is also an `arviz.preview.info` to check availability
of the different sub-libraries.
3 changes: 3 additions & 0 deletions doc/source/getting_started/Installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Use the below pip command to install ArviZ with all of its :ref:`Optional-depend
pip install "arviz[all]"
It is also possible to use ``pip install "arviz[preview]"` to access
:ref:`upcoming refactored features <preview_api>`.
Using conda-forge
=================
Expand Down

0 comments on commit adb2fef

Please sign in to comment.