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

dropped bottleneck warning message #311

Closed
wants to merge 3 commits into from
Closed
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
13 changes: 8 additions & 5 deletions treeple/stats/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import importlib.util
import os
import sys
import warnings
from typing import Optional, Tuple

Expand All @@ -20,20 +20,20 @@
from treeple._lib.sklearn.ensemble._forest import BaseForest, ForestClassifier

BOTTLENECK_AVAILABLE = False
if "bottleneck" in sys.modules:
if importlib.util.find_spec("bottleneck"):
import bottleneck as bn

BOTTLENECK_AVAILABLE = True

BOTTLENECK_WARNING = (
"Not using bottleneck for calculations involvings nans. Expect slower performance."
)
DISABLE_BN_ENV_VAR = "TREEPLE_NO_BOTTLENECK"

if BOTTLENECK_AVAILABLE and DISABLE_BN_ENV_VAR not in os.environ:
nanmean_f = bn.nanmean
anynan_f = lambda arr: bn.anynan(arr, axis=2)
else:
warnings.warn(
"Not using bottleneck for calculations involvings nans. Expect slower performance."
)
nanmean_f = np.nanmean
anynan_f = lambda arr: np.isnan(arr).any(axis=2)

Expand Down Expand Up @@ -261,6 +261,9 @@ def _compute_null_distribution_coleman(
metric_star_pi : ArrayLike of shape (n_samples,)
An array of the metrics computed on the other half of the trees.
"""
if not BOTTLENECK_AVAILABLE:
warnings.warn(BOTTLENECK_WARNING)

# sample two sets of equal number of trees from the combined forest these are the posteriors
# (n_estimators * 2, n_samples, n_outputs)
all_y_pred = np.concatenate((y_pred_proba_normal, y_pred_proba_perm), axis=0)
Expand Down
Loading