Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit 53dacba

Browse files
authored
Merge pull request #21 from coreofscience/revert-leaf-changes-if-they-remove-all-leaves
Revert leaf removals if they delete all leaves
2 parents 60de06b + d6a977c commit 53dacba

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
requirements = [
1111
"Click>=7.0,<8",
1212
"python-igraph>=0.8.0,<1",
13-
"wostools>=2.0.6,<3",
13+
"wostools>=2.0.7,<3",
1414
]
1515

1616
setup_requirements = [

src/sap/__init__.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,12 @@ def leaf(self, graph: Graph) -> Graph:
145145
not_leaves_anymore["leaf"] = 0
146146

147147
if self.max_leaf_age is not None:
148-
ignored = "\n".join(new_graph.vs.select(year_eq=None)["name"])
149-
logging.info(f"Ignoring these nodes for year calculations:\n{ignored}")
148+
ignored = new_graph.vs.select(year_eq=None)
149+
ignored = [
150+
{attr: v[attr] for attr in ignored.attributes()} for v in ignored
151+
]
152+
if ignored:
153+
logging.info(f"Ignoring these nodes for year calculations:\n{ignored}")
150154
newest_publication_year: int = max(
151155
filter(None, new_graph.vs[potential_leaves]["year"])
152156
)
@@ -156,6 +160,12 @@ def leaf(self, graph: Graph) -> Graph:
156160
)
157161
not_leaves_anymore["leaf"] = 0
158162

163+
if not any(new_graph.vs["leaf"]) and any(new_graph.vs["extended_leaf"]):
164+
logging.info(
165+
f"Reverting leaf cut policies, as they remove all possible leaves"
166+
)
167+
new_graph.vs["leaf"] = new_graph.vs["extended_leaf"]
168+
159169
if self.max_leaves is not None:
160170
sorted_leaves = _sorted_nodes(new_graph, "leaf")
161171
not_leaves_anymore = sorted_leaves[self.max_leaves :]

src/sap/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def describe(ctx, sources, output):
9090
click.echo(graph.summary() + "\n")
9191
except TypeError:
9292
logger.exception(
93-
f"There was an error processin the graph\n{graph.summary()}"
93+
f"There was an error processing the graph\n{graph.summary()}"
9494
)
9595

9696

0 commit comments

Comments
 (0)