Skip to content

Commit

Permalink
support strings in elements.get_node_id() (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
jGaboardi authored Nov 26, 2023
1 parent 891156e commit a17788a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions momepy/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,8 @@ def get_node_id(
total=objects.shape[0],
disable=not verbose,
):
if np.isnan(eid):
results_list.append(np.nan)
if pd.isna(eid):
results_list.append(pd.NA)
else:
edge = edges.loc[eid]
start_id = edge.node_start
Expand Down
14 changes: 12 additions & 2 deletions momepy/tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import geopandas as gpd
import numpy as np
import pandas as pd
import pytest
from geopandas.testing import assert_geodataframe_equal
from packaging.version import Version
Expand Down Expand Up @@ -154,8 +155,17 @@ def test_get_node_id(self):
self.df_buildings["nID"] = mm.get_network_id(
self.df_buildings, self.df_streets, "nID"
)
ids = mm.get_node_id(self.df_buildings, nodes, edges, "nodeID", "nID")
assert not ids.isna().any()
ids1 = mm.get_node_id(self.df_buildings, nodes, edges, "nodeID", "nID")
assert not ids1.isna().any()

# test for NaNs within `object` nIDs column
edges["nID"] = edges["nID"].astype(str)
_df_buildings = self.df_buildings.copy()
_df_buildings["nID"] = _df_buildings["nID"].astype(str)
_df_buildings.loc[[0, 1], "nID"] = pd.NA
ids2 = mm.get_node_id(_df_buildings, nodes, edges, "nodeID", "nID")
assert ids2.isna().sum() == 2
np.testing.assert_array_equal(ids2[ids2.isna()].index, [0, 1])

def test_get_node_id_ratio(self):
nx = mm.gdf_to_nx(self.df_streets)
Expand Down

0 comments on commit a17788a

Please sign in to comment.