From 690f692d2b6adfa8f952f6fb602603191aebea19 Mon Sep 17 00:00:00 2001 From: dachengx Date: Sun, 17 Mar 2024 05:32:03 -0500 Subject: [PATCH 1/2] Debug when `bins_type` is not set --- appletree/component.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/appletree/component.py b/appletree/component.py index 99d697f5..76588ed2 100644 --- a/appletree/component.py +++ b/appletree/component.py @@ -53,12 +53,12 @@ def __init__(self, name: Optional[str] = None, llh_name: Optional[str] = None, * if "bins" in kwargs.keys() and "bins_type" in kwargs.keys(): self.set_binning(**kwargs) - if self.bins_type != "meshgrid" and self.add_eps_to_hist: - warn( - "It is empirically dangerous to have add_eps_to_hist==True,\ - when your bins_type is not meshgrid! It may lead to very bad fit with\ - lots of eff==0." - ) + if self.bins_type != "meshgrid" and self.add_eps_to_hist: + warn( + "It is empirically dangerous to have add_eps_to_hist==True,\ + when your bins_type is not meshgrid! It may lead to very bad fit with\ + lots of eff==0." + ) def set_binning(self, **kwargs): """Set binning of component.""" @@ -66,6 +66,8 @@ def set_binning(self, **kwargs): raise ValueError("bins and bins_type must be set!") self.bins = kwargs.get("bins") self.bins_type = kwargs.get("bins_type") + if self.bins_type not in ["irreg", "meshgrid"]: + raise ValueError(f"Unsupported bins_type {self.bins_type}!") if self.bins_type == "meshgrid": warning = "The usage of meshgrid binning is highly discouraged." From d6140876dc3ed11ff2d412d98c22d28e63cbfb1d Mon Sep 17 00:00:00 2001 From: dachengx Date: Sun, 17 Mar 2024 06:33:09 -0500 Subject: [PATCH 2/2] Fix bug of `new_component` --- appletree/component.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appletree/component.py b/appletree/component.py index 76588ed2..9f22d695 100644 --- a/appletree/component.py +++ b/appletree/component.py @@ -66,7 +66,7 @@ def set_binning(self, **kwargs): raise ValueError("bins and bins_type must be set!") self.bins = kwargs.get("bins") self.bins_type = kwargs.get("bins_type") - if self.bins_type not in ["irreg", "meshgrid"]: + if self.bins_type not in ["irreg", "meshgrid", None]: raise ValueError(f"Unsupported bins_type {self.bins_type}!") if self.bins_type == "meshgrid": @@ -554,7 +554,7 @@ def new_component(self, llh_name: Optional[str] = None, pass_binning: bool = Tru name=self.name + "_copy", llh_name=llh_name, bins=self.bins, - bins_type=self.bins, + bins_type=self.bins_type, ) else: raise ValueError("Should provide bins and bins_type if you want to pass binning!")