Skip to content

Commit f03e0bd

Browse files
committed
Make xhistogram dependency optional
1 parent c3634e1 commit f03e0bd

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
@@ -17,7 +17,6 @@
1717

1818
import numpy as np
1919
import pymc as pm
20-
import xhistogram.core
2120
from numpy.typing import ArrayLike
2221

2322
try:
@@ -26,13 +25,21 @@
2625
except ImportError:
2726
dask = None
2827

28+
try:
29+
import xhistogram.core
30+
except ImportError:
31+
xhistogram = None
32+
2933

3034
__all__ = ["quantile_histogram", "discrete_histogram", "histogram_approximation"]
3135

3236

3337
def quantile_histogram(
3438
data: ArrayLike, n_quantiles=1000, zero_inflation=False
3539
) -> Dict[str, ArrayLike]:
40+
if xhistogram is None:
41+
raise RuntimeError("quantile_histogram requires xhistogram package")
42+
3643
if dask and isinstance(data, (dask.dataframe.Series, dask.dataframe.DataFrame)):
3744
data = data.to_dask_array(lengths=True)
3845
if zero_inflation:
@@ -67,6 +74,9 @@ def quantile_histogram(
6774

6875

6976
def discrete_histogram(data: ArrayLike, min_count=None) -> Dict[str, ArrayLike]:
77+
if xhistogram is None:
78+
raise RuntimeError("discrete_histogram requires xhistogram package")
79+
7080
if dask and isinstance(data, (dask.dataframe.Series, dask.dataframe.DataFrame)):
7181
data = data.to_dask_array(lengths=True)
7282
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.3.0
2-
xhistogram

0 commit comments

Comments
 (0)