Repository: gibsramen/evident

Issue:
Fix NaN issue in OnlyOneCategory exception
https://github.com/gibsramen/evident/blob/d1a3fe636764f47278d4cbade05534a2b57d1b87/evident/_exceptions.py#L61

If NaN exists, this line will fail because the number of "unique" levels > 1

Discussion:

Patch:
diff --git a/evident/__init__.py b/evident/__init__.py
index 10d1afa..162a668 100644
--- a/evident/__init__.py
+++ b/evident/__init__.py
@@ -1,6 +1,6 @@
 from .diversity_handler import AlphaDiversityHandler, BetaDiversityHandler
 
 
-__version__ = "0.1.1"
+__version__ = "0.1.2dev"
 
 __all__ = ["AlphaDiversityHandler", "BetaDiversityHandler"]
diff --git a/evident/_exceptions.py b/evident/_exceptions.py
index 45038ee..283a8e3 100644
--- a/evident/_exceptions.py
+++ b/evident/_exceptions.py
@@ -58,7 +58,7 @@ class NonCategoricalColumnError(Exception):
 
 class OnlyOneCategoryError(Exception):
     def __init__(self, column: pd.Series):
-        value = column.unique().item()
+        value = column.dropna().unique().item()
         message = (
             f"Column {column.name} has only one value: '{value}'."
         )


Test patch:
diff --git a/evident/tests/test_effect_size.py b/evident/tests/test_effect_size.py
index 5b7fb0f..aab55be 100644
--- a/evident/tests/test_effect_size.py
+++ b/evident/tests/test_effect_size.py
@@ -4,6 +4,7 @@ import pytest
 
 from evident import AlphaDiversityHandler
 from evident import effect_size as expl
+from evident import _exceptions as exc
 
 
 @pytest.mark.parametrize("mock", ["alpha_mock", "beta_mock"])
@@ -98,3 +99,22 @@ def test_nan_in_cols():
     adh = AlphaDiversityHandler(faith_vals, df)
     assert not np.isnan(adh.calculate_effect_size("col1").effect_size)
     assert not np.isnan(adh.calculate_effect_size("col2").effect_size)
+
+
+def test_nan_in_cols_one_one_cat():
+    col1 = ["a", "a", np.nan, "b", "b", "b"]
+    col2 = ["c", "c", np.nan, np.nan, np.nan, "c"]
+
+    df = pd.DataFrame({"col1": col1, "col2": col2})
+    df.index = [f"S{x}" for x in range(len(col1))]
+
+    faith_vals = pd.Series([1, 3, 4, 5, 6, 6])
+    faith_vals.index = df.index
+    adh = AlphaDiversityHandler(faith_vals, df)
+    assert not np.isnan(adh.calculate_effect_size("col1").effect_size)
+
+    with pytest.raises(exc.OnlyOneCategoryError) as exc_info:
+        adh.calculate_effect_size("col2")
+
+    exp_err_msg = "Column col2 has only one value: 'c'."
+    assert str(exc_info.value) == exp_err_msg