Skip to content

Commit 8e23884

Browse files
committed
STYLE: Avoid warning with divide by zero
A warning was displayed when the length of an iterable was zero. "Avoid RuntimeWarning: divide by zero encountered in log10" Avoid this warning by explicitly checking for zero and giving alternate behavior when no nodes are presented.
1 parent 34c7092 commit 8e23884

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

nipype/pipeline/engine.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,14 @@ def _write_report_info(self, workingdir, name, graph):
750750
value=1))
751751
save_json(graph_file, json_dict)
752752
graph_file = op.join(report_dir, 'graph.json')
753-
template = '%%0%dd_' % np.ceil(np.log10(len(nodes))).astype(int)
753+
# Avoid RuntimeWarning: divide by zero encountered in log10
754+
num_nodes = len(nodes)
755+
if num_nodes > 0:
756+
index_name = np.ceil(np.log10(num_nodes)).astype(int)
757+
else:
758+
index_name = 0
759+
template = '%%0%dd_' % index_name
760+
754761
def getname(u, i):
755762
name_parts = u.fullname.split('.')
756763
#return '.'.join(name_parts[:-1] + [template % i + name_parts[-1]])

0 commit comments

Comments
 (0)