diff --git a/pandana/network.py b/pandana/network.py index 61303ea..fe3086c 100644 --- a/pandana/network.py +++ b/pandana/network.py @@ -282,6 +282,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): @@ -322,6 +328,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"): diff --git a/pandana/utils.py b/pandana/utils.py index 10e0885..b3ef06f 100644 --- a/pandana/utils.py +++ b/pandana/utils.py @@ -25,3 +25,10 @@ def reindex(series1, series2): right_index=True, how="left") return df.right + +def adjacency_matrix(edges_df, plot_matrix=False): + df = pd.crosstab(edges_df['from'], edges_df['to']) + idx = df.columns.union(df.index) + df = df.reindex(index = idx, columns=idx, fill_value=0) + + return df