Skip to content

Commit

Permalink
Address multiple deprecation warnings (#2333)
Browse files Browse the repository at this point in the history
* check cmaps aren't registered yet

* update black version

* fix deprecation warnings

* update changelog

* fix missed rename

* fix inferencedata style.css
  • Loading branch information
OriolAbril authored Mar 27, 2024
1 parent 7c52d0a commit dbef460
Show file tree
Hide file tree
Showing 207 changed files with 262 additions and 67 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
### New features

- Add new example data `rugby_field` and update `rugby` example data ([2322](https://github.com/arviz-devs/arviz/pull/2322))

- Support for `pytree`s and robust to nested dictionaries. (2291)
- Support for `pytree`s and robust to nested dictionaries. ([2291](https://github.com/arviz-devs/arviz/pull/2291))


### Maintenance and fixes
- Fix deprecation warnings in multiple dependencies ([2329](https://github.com/arviz-devs/arviz/pull/2329),
[2332](https://github.com/arviz-devs/arviz/pull/2332) and [2333](https://github.com/arviz-devs/arviz/pull/2333))

### Deprecation

Expand Down
3 changes: 2 additions & 1 deletion arviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ def _log(

def _mpl_cm(name, colorlist):
cmap = LinearSegmentedColormap.from_list(name, colorlist, N=256)
mpl.colormaps.register(cmap, name="cet_" + name)
if "cet_" + name not in mpl.colormaps():
mpl.colormaps.register(cmap, name="cet_" + name)


try:
Expand Down
1 change: 1 addition & 0 deletions arviz/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Code for loading and manipulating data structures."""

from .base import CoordSpec, DimSpec, dict_to_dataset, numpy_to_data_array, pytree_to_dataset
from .converters import convert_to_dataset, convert_to_inference_data
from .datasets import clear_data_home, list_datasets, load_arviz_data
Expand Down
1 change: 1 addition & 0 deletions arviz/data/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Low level converters usually used by other functions."""

import datetime
import functools
import importlib
Expand Down
1 change: 1 addition & 0 deletions arviz/data/converters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""High level conversion functions."""

import numpy as np
import tree
import xarray as xr
Expand Down
1 change: 1 addition & 0 deletions arviz/data/datasets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base IO code for all datasets. Heavily influenced by scikit-learn's implementation."""

import hashlib
import itertools
import json
Expand Down
31 changes: 14 additions & 17 deletions arviz/data/inference_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ def from_netcdf(
)

try:
with h5netcdf.File(filename, mode="r") if engine == "h5netcdf" else nc.Dataset(
filename, mode="r"
with (
h5netcdf.File(filename, mode="r")
if engine == "h5netcdf"
else nc.Dataset(filename, mode="r")
) as file_handle:
if base_group == "/":
data = file_handle
Expand Down Expand Up @@ -744,11 +746,11 @@ def to_dataframe(
if len(dfs) > 1:
for group, df in dfs.items():
df.columns = [
col
if col in ("draw", "chain")
else (group, *col)
if isinstance(col, tuple)
else (group, col)
(
col
if col in ("draw", "chain")
else (group, *col) if isinstance(col, tuple) else (group, col)
)
for col in df.columns
]
dfs, *dfs_tail = list(dfs.values())
Expand Down Expand Up @@ -1918,8 +1920,7 @@ def concat(
copy: bool = True,
inplace: "Literal[True]",
reset_dim: bool = True,
) -> None:
...
) -> None: ...


@overload
Expand All @@ -1929,8 +1930,7 @@ def concat(
copy: bool = True,
inplace: "Literal[False]",
reset_dim: bool = True,
) -> InferenceData:
...
) -> InferenceData: ...


@overload
Expand All @@ -1941,8 +1941,7 @@ def concat(
copy: bool = True,
inplace: "Literal[False]",
reset_dim: bool = True,
) -> InferenceData:
...
) -> InferenceData: ...


@overload
Expand All @@ -1953,8 +1952,7 @@ def concat(
copy: bool = True,
inplace: "Literal[True]",
reset_dim: bool = True,
) -> None:
...
) -> None: ...


@overload
Expand All @@ -1965,8 +1963,7 @@ def concat(
copy: bool = True,
inplace: bool = False,
reset_dim: bool = True,
) -> Optional[InferenceData]:
...
) -> Optional[InferenceData]: ...


# pylint: disable=protected-access, inconsistent-return-statements
Expand Down
4 changes: 1 addition & 3 deletions arviz/data/io_cmdstan.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,9 +732,7 @@ def _process_configuration(comments):
key = (
"warmup_time_seconds"
if "(Warm-up)" in comment
else "sampling_time_seconds"
if "(Sampling)" in comment
else "total_time_seconds"
else "sampling_time_seconds" if "(Sampling)" in comment else "total_time_seconds"
)
results[key] = float(value)
elif "=" in comment:
Expand Down
1 change: 1 addition & 0 deletions arviz/data/io_datatree.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Conversion between InferenceData and DataTree."""

from .inference_data import InferenceData


Expand Down
5 changes: 2 additions & 3 deletions arviz/data/io_dict.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Dictionary specific conversion code."""

import warnings
from typing import Optional

Expand Down Expand Up @@ -59,9 +60,7 @@ def __init__(
self.coords = (
coords
if pred_coords is None
else pred_coords
if coords is None
else {**coords, **pred_coords}
else pred_coords if coords is None else {**coords, **pred_coords}
)
self.index_origin = index_origin
self.coords = coords
Expand Down
1 change: 1 addition & 0 deletions arviz/data/io_emcee.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""emcee-specific conversion code."""

import warnings
from collections import OrderedDict

Expand Down
1 change: 1 addition & 0 deletions arviz/data/io_numpyro.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""NumPyro-specific conversion code."""

import logging
from typing import Callable, Optional

Expand Down
1 change: 1 addition & 0 deletions arviz/data/io_pyjags.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Convert PyJAGS sample dictionaries to ArviZ inference data objects."""

import typing as tp
from collections import OrderedDict
from collections.abc import Iterable
Expand Down
1 change: 1 addition & 0 deletions arviz/data/io_pyro.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Pyro-specific conversion code."""

import logging
from typing import Callable, Optional
import warnings
Expand Down
1 change: 1 addition & 0 deletions arviz/data/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Data specific utilities."""

import warnings
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions arviz/plots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Plotting functions."""

from .autocorrplot import plot_autocorr
from .bpvplot import plot_bpv
from .bfplot import plot_bf
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/autocorrplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Autocorrelation plot of data."""

from ..data import convert_to_dataset
from ..labels import BaseLabeller
from ..sel_utils import xarray_var_iter
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/autocorrplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh Autocorrplot."""

import numpy as np
from bokeh.models import DataRange1d, BoxAnnotation
from bokeh.models.annotations import Title
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/bpvplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh Bayesian p-value Posterior predictive plot."""

import numpy as np
from bokeh.models import BoxAnnotation
from bokeh.models.annotations import Title
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/compareplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh Compareplot."""

from bokeh.models import Span
from bokeh.models.annotations import Title, Legend

Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/densityplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh Densityplot."""

from collections import defaultdict
from itertools import cycle

Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/distplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh Distplot."""

import matplotlib.pyplot as plt
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/dotplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh dotplot."""

import math
import warnings
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/ecdfplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh ecdfplot."""

from matplotlib.colors import to_hex

from ...plot_utils import _scale_fig_size
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/elpdplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh ELPDPlot."""

import warnings

import bokeh.plotting as bkp
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/energyplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh energyplot."""

from itertools import cycle

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/hdiplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh hdiplot."""

import numpy as np

from ...plot_utils import _scale_fig_size, vectorized_to_hex
Expand Down
6 changes: 3 additions & 3 deletions arviz/plots/backends/bokeh/kdeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from bokeh.models import ColumnDataSource
from bokeh.models.glyphs import Scatter
from matplotlib.cm import get_cmap
from matplotlib import colormaps
from matplotlib.colors import rgb2hex
from matplotlib.pyplot import rcParams as mpl_rcParams

Expand Down Expand Up @@ -188,7 +188,7 @@ def plot_kde(

cmap = contourf_kwargs.pop("cmap", "viridis")
if isinstance(cmap, str):
cmap = get_cmap(cmap)
cmap = colormaps[cmap]
if isinstance(cmap, Callable):
colors = [rgb2hex(item) for item in cmap(np.linspace(0, 1, len(levels_scaled) + 1))]
else:
Expand Down Expand Up @@ -225,7 +225,7 @@ def plot_kde(
else:
cmap = pcolormesh_kwargs.pop("cmap", "viridis")
if isinstance(cmap, str):
cmap = get_cmap(cmap)
cmap = colormaps[cmap]
if isinstance(cmap, Callable):
colors = [rgb2hex(item) for item in cmap(np.linspace(0, 1, 256))]
else:
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/khatplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh pareto shape plot."""

from collections.abc import Iterable

from matplotlib import cm
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/lmplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh linear regression plot."""

import numpy as np
from bokeh.models.annotations import Legend

Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/loopitplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh loopitplot."""

import numpy as np
from bokeh.models import BoxAnnotation
from matplotlib.colors import hsv_to_rgb, rgb_to_hsv, to_hex, to_rgb
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/mcseplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh mcseplot."""

import numpy as np
from bokeh.models import ColumnDataSource, Span
from bokeh.models.glyphs import Scatter
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/pairplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh pairplot."""

import warnings
from copy import deepcopy
from uuid import uuid4
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/parallelplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh Parallel coordinates plot."""

import numpy as np
from bokeh.models import DataRange1d
from bokeh.models.tickers import FixedTicker
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/posteriorplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh Plot posterior densities."""

from numbers import Number
from typing import Optional

Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/ppcplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh Posterior predictive plot."""

import numpy as np
from bokeh.models.annotations import Legend
from bokeh.models.glyphs import Scatter
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/rankplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh rankplot."""

import numpy as np

from bokeh.models import Span
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/separationplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh separation plot."""

import numpy as np

from ...plot_utils import _scale_fig_size, vectorized_to_hex
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/traceplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh Traceplot."""

import warnings
from collections.abc import Iterable
from itertools import cycle
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/bokeh/violinplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Bokeh Violinplot."""

import numpy as np
from bokeh.models.annotations import Title

Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/matplotlib/autocorrplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Matplotlib Autocorrplot."""

import matplotlib.pyplot as plt
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/matplotlib/bpvplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Matplotib Bayesian p-value Posterior predictive plot."""

import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/matplotlib/compareplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Matplotlib Compareplot."""

import matplotlib.pyplot as plt

from ...plot_utils import _scale_fig_size
Expand Down
1 change: 1 addition & 0 deletions arviz/plots/backends/matplotlib/densityplot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Matplotlib Densityplot."""

from itertools import cycle

import matplotlib.pyplot as plt
Expand Down
Loading

0 comments on commit dbef460

Please sign in to comment.