Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failsafe html handling #1392

Merged
merged 8 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
* Restructure plotting code to be compatible with mpl>=3.3 ([1312](https://github.com/arviz-devs/arviz/pull/1312) and [1352](https://github.com/arviz-devs/arviz/pull/1352))
* Replaced `_fast_kde()` with `kde()` which now also supports circular variables via the argument `circular` ([1284](https://github.com/arviz-devs/arviz/pull/1284)).
* Increased `from_pystan` attrs information content ([1353](https://github.com/arviz-devs/arviz/pull/1353))
* Allow `plot_trace` to return and accept axes ([#1361](https://github.com/arviz-devs/arviz/pull/1361))
* Update diagnostics to be on par with posterior package ([#1366](https://github.com/arviz-devs/arviz/pull/1366))
* Use method="average" in `scipy.stats.rankdata` ([#1380](https://github.com/arviz-devs/arviz/pull/1380))
* Add more `plot_parallel` examples ([#1380](https://github.com/arviz-devs/arviz/pull/1380))
* Bump minimum xarray version to 0.16.1 ([#1389](https://github.com/arviz-devs/arviz/pull/1389)
* Fix multi rope for `plot_forest` ([#1390](https://github.com/arviz-devs/arviz/pull/1390))
* Bump minimum xarray version to 0.16.1 ([#1389](https://github.com/arviz-devs/arviz/pull/1389))
* Allow `plot_trace` to return and accept axes ([1361](https://github.com/arviz-devs/arviz/pull/1361))
* Update diagnostics to be on par with posterior package ([1366](https://github.com/arviz-devs/arviz/pull/1366))
* Use method="average" in `scipy.stats.rankdata` ([1380](https://github.com/arviz-devs/arviz/pull/1380))
* Add more `plot_parallel` examples ([1380](https://github.com/arviz-devs/arviz/pull/1380))
* Bump minimum xarray version to 0.16.1 ([1389](https://github.com/arviz-devs/arviz/pull/1389)
* Fix multi rope for `plot_forest` ([1390](https://github.com/arviz-devs/arviz/pull/1390))
* Bump minimum xarray version to 0.16.1 ([1389](https://github.com/arviz-devs/arviz/pull/1389))
* `from_dict` will now store warmup groups even with the main group missing ([1386](https://github.com/arviz-devs/arviz/pull/1386))
* increase robustness for repr_html handling ([1392](https://github.com/arviz-devs/arviz/pull/1392))

### Deprecation

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ include LICENSE

recursive-include arviz *.mplstyle
recursive-include arviz *.nc
recursive-include arviz/static *
2 changes: 1 addition & 1 deletion arviz/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from .io_cmdstanpy import from_cmdstanpy
from .io_dict import from_dict
from .io_emcee import from_emcee
from .io_netcdf import from_netcdf, to_netcdf
from .io_json import from_json
from .io_netcdf import from_netcdf, to_netcdf
from .io_numpyro import from_numpyro
from .io_pyjags import from_pyjags
from .io_pymc3 import from_pymc3, from_pymc3_predictions
Expand Down
2 changes: 1 addition & 1 deletion arviz/data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from copy import deepcopy
from typing import Any, Dict, List

import pkg_resources
import numpy as np
import pkg_resources
import xarray as xr

try:
Expand Down
51 changes: 27 additions & 24 deletions arviz/data/inference_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
import netCDF4 as nc
import numpy as np
import xarray as xr
from xarray.core.options import OPTIONS
from xarray.core.utils import either_dict_or_kwargs

from ..rcparams import rcParams
from ..utils import HtmlTemplate, _subset_list
from .base import _extend_xr_method, dict_to_dataset, _make_json_serializable
from ..utils import HtmlTemplate, _subset_list, either_dict_or_kwargs
from .base import _extend_xr_method, _make_json_serializable, dict_to_dataset

try:
import ujson as json
Expand Down Expand Up @@ -147,27 +145,32 @@ def __repr__(self):

def _repr_html_(self):
"""Make html representation of InferenceData object."""
display_style = OPTIONS["display_style"]
if display_style == "text":
try:
from xarray.core.options import OPTIONS

display_style = OPTIONS["display_style"]
if display_style == "text":
html_repr = f"<pre>{escape(repr(self))}</pre>"
else:
elements = "".join(
[
HtmlTemplate.element_template.format(
group_id=group + str(uuid.uuid4()),
group=group,
xr_data=getattr( # pylint: disable=protected-access
self, group
)._repr_html_(),
)
for group in self._groups_all
]
)
formatted_html_template = ( # pylint: disable=possibly-unused-variable
HtmlTemplate.html_template.format(elements)
)
css_template = HtmlTemplate.css_template # pylint: disable=possibly-unused-variable
html_repr = "%(formatted_html_template)s%(css_template)s" % locals()
except: # pylint: disable=bare-except
html_repr = f"<pre>{escape(repr(self))}</pre>"
else:
elements = "".join(
[
HtmlTemplate.element_template.format(
group_id=group + str(uuid.uuid4()),
group=group,
xr_data=getattr( # pylint: disable=protected-access
self, group
)._repr_html_(),
)
for group in self._groups_all
]
)
formatted_html_template = ( # pylint: disable=possibly-unused-variable
HtmlTemplate.html_template.format(elements)
)
css_template = HtmlTemplate.css_template # pylint: disable=possibly-unused-variable
html_repr = "%(formatted_html_template)s%(css_template)s" % locals()
return html_repr

def __delattr__(self, group):
Expand Down
2 changes: 1 addition & 1 deletion arviz/data/io_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .. import utils
from ..rcparams import rcParams
from .base import dict_to_dataset, generate_dims_coords, make_attrs, requires
from .inference_data import InferenceData, WARMUP_TAG
from .inference_data import WARMUP_TAG, InferenceData


# pylint: disable=too-many-instance-attributes
Expand Down
2 changes: 1 addition & 1 deletion arviz/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
from .posteriorplot import plot_posterior
from .ppcplot import plot_ppc
from .rankplot import plot_rank
from .separationplot import plot_separation
from .traceplot import plot_trace
from .violinplot import plot_violin
from .separationplot import plot_separation

__all__ = [
"plot_autocorr",
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/separationplot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Separation plot for discrete outcome models."""
import warnings

import numpy as np
import xarray as xr

Expand Down
Loading