Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Informative warning for shortest path unsigned integer #169

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pandana/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ def shortest_path_length(self, node_a, node_b, imp_name=None):

len = self.net.shortest_path_distance(node_a, node_b, imp_num)

if len == 4294967.295:
warnings.warn(
"Unsigned integer: shortest path distance is trying to be calculated between\
external %s and %s unconntected nodes"%(node_a, node_b)
)

return len

def shortest_path_lengths(self, nodes_a, nodes_b, imp_name=None):
Expand All @@ -298,8 +304,7 @@ def shortest_path_lengths(self, nodes_a, nodes_b, imp_name=None):

"""
if len(nodes_a) != len(nodes_b):
raise ValueError("Origin and destination counts don't match: {}, {}"
.format(len(nodes_a), len(nodes_b)))
raise ValueError("Origin and destination counts don't match: {}, {}".format(len(nodes_a), len(nodes_b)))

# map to internal node indexes
nodes_a_idx = self._node_indexes(pd.Series(nodes_a)).values
Expand All @@ -309,6 +314,13 @@ def shortest_path_lengths(self, nodes_a, nodes_b, imp_name=None):

lens = self.net.shortest_path_distances(nodes_a_idx, nodes_b_idx, imp_num)

if 4294967.295 in lens:
unconnected_idx = [i for i,v in enumerate(lens) if v == 4294967.295]
unconnected_nodes = [(nodes_a[i],nodes_b[i]) for i in unconnected_idx]
warnings.warn(
"Unsigned integer: shortest path distance is trying to be calculated \
between the following external unconnected nodes: %s"%(unconnected_nodes))

return lens

def set(self, node_ids, variable=None, name="tmp"):
Expand Down