6
6
from esda .moran import Moran_Local
7
7
8
8
from eis_toolkit import exceptions
9
- from eis_toolkit .exceptions import InvalidParameterValueException
10
9
11
10
12
11
@beartype
@@ -19,12 +18,12 @@ def _local_morans_i(
19
18
elif weight_type == "knn" :
20
19
w = libpysal .weights .KNN .from_dataframe (gdf , k = k )
21
20
else :
22
- raise InvalidParameterValueException ("Invalid weight_type. Use 'queen' or 'knn'." )
21
+ raise exceptions . InvalidParameterValueException ("Invalid weight_type. Use 'queen' or 'knn'." )
23
22
24
23
w .transform = "R"
25
24
26
25
if len (gdf [column ]) != len (w .weights ):
27
- raise InvalidParameterValueException ("Dimension mismatch between data and weights matrix." )
26
+ raise exceptions . InvalidParameterValueException ("Dimension mismatch between data and weights matrix." )
28
27
29
28
moran_loc = Moran_Local (gdf [column ], w , permutations = permutations )
30
29
@@ -59,12 +58,18 @@ def local_morans_i(
59
58
60
59
Raises:
61
60
EmptyDataFrameException: The input geodataframe is empty.
61
+ InvalidColumnException: The input column is not found in the input geodataframe.
62
+ InvalidParameterValueException: Input parameter values for `k` or `permutations` are invalid.
63
+ NonNumericDataException: The input column contains non-numeric data.
62
64
"""
63
65
if gdf .shape [0 ] == 0 :
64
66
raise exceptions .EmptyDataFrameException ("Geodataframe is empty." )
65
67
66
68
if column not in gdf .columns :
67
- raise exceptions .InvalidParameterValueException (f"Column '{ column } ' not found in the GeoDataFrame." )
69
+ raise exceptions .InvalidColumnException (f"Column '{ column } ' not found in the GeoDataFrame." )
70
+
71
+ if not np .issubdtype (gdf [column ].dtype , np .number ):
72
+ raise exceptions .NonNumericDataException (f"Column '{ column } ' must contain numeric data." )
68
73
69
74
if k < 1 :
70
75
raise exceptions .InvalidParameterValueException ("k must be > 0." )
0 commit comments