Repository: martinfleis/momepy (python)

Issue:
momepy.Unique counts Nans while it shouldn't
https://github.com/martinfleis/momepy/blob/896cb70ef80bfca07fd12dd5f3da827613367ab6/momepy/diversity.py#L778
This line should be changed to exclude nans in the computation of unique elements. Possible solution: add a keyword `include_nan` and if False switch this line to values_list.dropna().unique()

Pull request description:
ENH: add dropna keyword to `Unique`
Closes #279

Patch:
diff --git a/momepy/diversity.py b/momepy/diversity.py
index 78c924f..048ff71 100644
--- a/momepy/diversity.py
+++ b/momepy/diversity.py
@@ -728,6 +728,8 @@ class Unique:
         spatial weights matrix
     unique_id : str
         name of the column with unique id used as ``spatial_weights`` index
+    dropna : bool (default True)
+        Don’t include NaN in the counts of unique values.
     verbose : bool (default True)
         if True, shows progress bars in loops and indication of steps
 
@@ -754,7 +756,9 @@ class Unique:
     100%|██████████| 144/144 [00:00<00:00, 722.50it/s]
     """
 
-    def __init__(self, gdf, values, spatial_weights, unique_id, verbose=True):
+    def __init__(
+        self, gdf, values, spatial_weights, unique_id, dropna=True, verbose=True
+    ):
         self.gdf = gdf
         self.sw = spatial_weights
         self.id = gdf[unique_id]
@@ -775,7 +779,7 @@ class Unique:
                 neighbours += spatial_weights.neighbors[index]
 
                 values_list = data.loc[neighbours]
-                results_list.append(len(values_list.unique()))
+                results_list.append(values_list.nunique(dropna=dropna))
             else:
                 results_list.append(np.nan)
 


Test patch:
diff --git a/tests/test_diversity.py b/tests/test_diversity.py
index 9395388..a2966d6 100644
--- a/tests/test_diversity.py
+++ b/tests/test_diversity.py
@@ -169,6 +169,13 @@ class TestDiversity:
         assert un.isna().any()
         assert un[5] == 8
 
+        self.df_tessellation.loc[0, "cat"] = np.nan
+        un = mm.Unique(self.df_tessellation, "cat", self.sw, "uID", dropna=False).series
+        assert un[0] == 9
+
+        un = mm.Unique(self.df_tessellation, "cat", self.sw, "uID", dropna=True).series
+        assert un[0] == 8
+
     def test_Percentile(self):
         perc = mm.Percentiles(self.df_tessellation, "area", self.sw, "uID").frame
         assert np.all(