Skip to content

Commit 7c5944e

Browse files
committed
Make xhistogram dependency optional
1 parent f560e1e commit 7c5944e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

pymc_experimental/distributions/histogram_utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import numpy as np
44
import pymc as pm
5-
import xhistogram.core
65
from numpy.typing import ArrayLike
76

87
try:
@@ -11,13 +10,21 @@
1110
except ImportError:
1211
dask = None
1312

13+
try:
14+
import xhistogram.core
15+
except ImportError:
16+
xhistogram = None
17+
1418

1519
__all__ = ["quantile_histogram", "discrete_histogram", "histogram_approximation"]
1620

1721

1822
def quantile_histogram(
1923
data: ArrayLike, n_quantiles=1000, zero_inflation=False
2024
) -> Dict[str, ArrayLike]:
25+
if xhistogram is None:
26+
raise RuntimeError("quantile_histogram requires xhistogram package")
27+
2128
if dask and isinstance(data, (dask.dataframe.Series, dask.dataframe.DataFrame)):
2229
data = data.to_dask_array(lengths=True)
2330
if zero_inflation:
@@ -52,6 +59,9 @@ def quantile_histogram(
5259

5360

5461
def discrete_histogram(data: ArrayLike, min_count=None) -> Dict[str, ArrayLike]:
62+
if xhistogram is None:
63+
raise RuntimeError("discrete_histogram requires xhistogram package")
64+
5565
if dask and isinstance(data, (dask.dataframe.Series, dask.dataframe.DataFrame)):
5666
data = data.to_dask_array(lengths=True)
5767
mid, count_uniq = np.unique(data, return_counts=True)

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
pymc>=4.0.1
2-
xhistogram

0 commit comments

Comments
 (0)