diff --git a/ra2ce/analysis/damages/damages_utils.py b/ra2ce/analysis/damages/damages_utils.py index 21f15c0f6..448ae4d12 100644 --- a/ra2ce/analysis/damages/damages_utils.py +++ b/ra2ce/analysis/damages/damages_utils.py @@ -19,7 +19,6 @@ along with this program. If not, see . """ - import logging from typing import Any, List @@ -130,10 +129,11 @@ def create_summary_statistics(gdf: GeoDataFrame) -> dict: # get a default value if any key of the dictionary is nan # (because the mode operation on the 'lanes' column for a road type results in an empty array) - default_value = np.mean( + lanes_values = np.mean( list(_val for _val in _lanes_dict.values() if not np.isnan(_val)) ) - + # Round the mean to the nearest integer + default_value = np.ceil(lanes_values) # Replace nan with the calculated average return { _road_type: _lanes if not np.isnan(_lanes) else default_value diff --git a/tests/analysis/damages/test_damages_utils.py b/tests/analysis/damages/test_damages_utils.py index c2640c9da..2db7a5526 100644 --- a/tests/analysis/damages/test_damages_utils.py +++ b/tests/analysis/damages/test_damages_utils.py @@ -69,8 +69,8 @@ def test_clean_lane_data(self): [ pytest.param([0, 1, 3], [0, 1, 3], id="Valid lanes"), pytest.param([np.nan, 1, 3], [2, 1, 3], id="First lane invalid"), - pytest.param([0, np.nan, 3], [0, 1.5, 3], id="Middle lane invalid"), - pytest.param([0, 1, np.nan], [0, 1, 0.5], id="Last lane invalid"), + pytest.param([0, np.nan, 3], [0, 2, 3], id="Middle lane invalid"), + pytest.param([0, 1, np.nan], [0, 1, 1], id="Last lane invalid"), pytest.param( [np.nan, np.nan, np.nan], [np.nan, np.nan, np.nan],