Skip to content

Make xhistogram dependency optional #92

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

Merged
merged 9 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 11 additions & 1 deletion pymc_experimental/distributions/histogram_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import numpy as np
import pymc as pm
import xhistogram.core
from numpy.typing import ArrayLike

try:
Expand All @@ -26,13 +25,21 @@
except ImportError:
dask = None

try:
import xhistogram.core
except ImportError:
xhistogram = None


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


def quantile_histogram(
data: ArrayLike, n_quantiles=1000, zero_inflation=False
) -> Dict[str, ArrayLike]:
if xhistogram is None:
raise RuntimeError("quantile_histogram requires xhistogram package")

if dask and isinstance(data, (dask.dataframe.Series, dask.dataframe.DataFrame)):
data = data.to_dask_array(lengths=True)
if zero_inflation:
Expand Down Expand Up @@ -67,6 +74,9 @@ def quantile_histogram(


def discrete_histogram(data: ArrayLike, min_count=None) -> Dict[str, ArrayLike]:
if xhistogram is None:
raise RuntimeError("discrete_histogram requires xhistogram package")

if dask and isinstance(data, (dask.dataframe.Series, dask.dataframe.DataFrame)):
data = data.to_dask_array(lengths=True)
mid, count_uniq = np.unique(data, return_counts=True)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pymc>=4.3.0
xhistogram
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,9 @@ def get_version():
classifiers=classifiers,
python_requires=">=3.8",
install_requires=install_reqs,
extras_requires=dict(dask=["dask[all]"]),
extras_requires=dict(
dask=["dask[all]"],
histogram=["xhistogram"],
complete=["dask[all]", "xhistogram"]
),
)