Skip to content

Commit

Permalink
Adds bool as supported type for comparisons
Browse files Browse the repository at this point in the history
Relevant to biocore#27
  • Loading branch information
gibsramen committed Jan 10, 2023
1 parent 9cfd089 commit f6ef1b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 5 additions & 3 deletions evident/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
calculate_rm_anova_power)
from .utils import _listify, _check_sample_overlap

SUPP_TYPES = [np.dtype("object"), np.dtype("bool")]


class _BaseDataHandler(ABC):
"""Abstract class for handling data and metadata."""
Expand Down Expand Up @@ -48,7 +50,7 @@ def __init__(
warn_msg_level_count = False
for col in cat_columns:
# Drop non-categorical columns
if metadata[col].dtype != np.dtype("object"):
if metadata[col].dtype not in SUPP_TYPES:
cols_to_drop.append(col)
continue

Expand Down Expand Up @@ -120,7 +122,7 @@ def calculate_effect_size(
:returns: Effect size
:rtype: evident.results.EffectSizeResult
"""
if self.metadata[column].dtype != np.dtype("object"):
if self.metadata[column].dtype not in SUPP_TYPES:
raise exc.NonCategoricalColumnError(self.metadata[column])

column_choices = self.metadata[column].dropna().unique()
Expand Down Expand Up @@ -353,7 +355,7 @@ def _create_partial_power_func(
:returns: Stem of power function based on chosen column
:rtype: partial function
"""
if self.metadata[column].dtype != np.dtype("object"):
if self.metadata[column].dtype not in SUPP_TYPES:
raise exc.NonCategoricalColumnError(self.metadata[column])

column_choices = self.metadata[column].dropna().unique()
Expand Down
10 changes: 10 additions & 0 deletions evident/tests/test_data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ def test_alpha_data_nan(self, alpha_mock):
assert exp_warn_msg_1 == warn_msg_1
assert exp_warn_msg_2 == warn_msg_2

def test_bool(self, alpha_mock):
data = alpha_mock.data
md = alpha_mock.metadata
md["classification_bool"] = md["classification"] == "B1"

adh = UnivariateDataHandler(data, md)
es1 = adh.calculate_effect_size("classification")
es2 = adh.calculate_effect_size("classification_bool")
assert es1.effect_size == es2.effect_size


class TestBetaDiv:
def test_init_beta_div_handler(self):
Expand Down

0 comments on commit f6ef1b9

Please sign in to comment.