Skip to content

Commit

Permalink
Minor bugfix in writer
Browse files Browse the repository at this point in the history
  • Loading branch information
clbarnes committed Nov 23, 2022
1 parent cbea9d8 commit e74f3d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion navis/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def write_zip(self, x, filepath, **kwargs):
finally:
# Remove temporary file - we do this inside the loop
# to avoid unnecessarily occupying space as we write
if f:
if os.path.exists(f):
os.remove(f)

# Set filepath to zipfile -> this overwrite filepath set in write_single
Expand Down
7 changes: 3 additions & 4 deletions navis/io/swc_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,24 +601,23 @@ def sort_swc(df: pd.DataFrame, roots, sort_children=True, inplace=False):
child = row.node_id
parent = row.parent_id
children[parent].append(child)
node_id_to_orig_idx[child] = row.index
node_id_to_orig_idx[child] = row.Index

if sort_children:
to_visit = sorted(roots, reverse=True)
else:
to_visit = list(roots)[::-1]

idx = 0
order = np.full(len(df), np.nan)
count = 0
while to_visit:
node_id = to_visit.pop()
order[node_id_to_orig_idx[node_id]] = count
cs = children.pop(order[-1], [])
if sort_children:
to_visit.append(sorted(sort_children, reverse=True))
to_visit.extend(sorted(cs, reverse=True))
else:
to_visit.append(cs[::-1])
to_visit.extend(cs[::-1])
count += 1

# undefined behaviour if any nodes are not reachable from the given roots
Expand Down

0 comments on commit e74f3d4

Please sign in to comment.