Skip to content

Commit d4a19fc

Browse files
Clear nodes and edges cache when updating/joining
1 parent d869fdd commit d4a19fc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

gerrychain/graph/graph.py

+6
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ def add_data(self, df, columns=None):
191191
else:
192192
self.data = df[columns]
193193

194+
del self.nodes
195+
194196
def join(self, dataframe, columns=None, left_index=None, right_index=None):
195197
"""Add data from a dataframe to the graph, matching nodes to rows when
196198
the node's `left_index` attribute equals the row's `right_index` value.
@@ -231,6 +233,8 @@ def join(self, dataframe, columns=None, left_index=None, right_index=None):
231233

232234
networkx.set_node_attributes(self, node_attributes)
233235

236+
del self.nodes
237+
234238
@functools.cache
235239
def cached_neighbors(self, n):
236240
return list(super().neighbors(n))
@@ -282,6 +286,8 @@ def add_boundary_perimeters(graph, geometries):
282286
boundary_perimeter = total_perimeter - shared_perimeter
283287
graph.nodes[node]["boundary_perim"] = boundary_perimeter
284288

289+
del graph.nodes
290+
285291

286292
def check_dataframe(df):
287293
for column in df.columns:

0 commit comments

Comments
 (0)