Skip to content

Commit

Permalink
Fix collision removal
Browse files Browse the repository at this point in the history
  • Loading branch information
janssenhenning committed Apr 7, 2022
1 parent 1c02cbf commit 9372b06
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions masci_tools/io/parsers/tabulator/tabulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,18 @@ def _remove_collisions(self,
if len(paths) == 1:
continue

if abs(index) > len(paths[0]):
if abs(index) > max(len(path) for path in paths):
raise ValueError(f'Cannot disambiguate paths {paths}')

disambiguated_keypaths = []
for path in paths:
if abs(index) > len(path):
disambiguated_keypaths.append((path, name))
else:
disambiguated_keypaths.append((path[:index], f'{path[index]}{self.separator}{name}'))

#Go up levels until they can be distinguished
unique_paths = self._remove_collisions(
[(path[:index], f'{path[index]}{self.separator}{name}') for path in paths], index=index - 1)
unique_paths = self._remove_collisions(disambiguated_keypaths, index=index - 1)

for path, unique_path in zip(paths, unique_paths):
keypaths[keypaths.index((path, name))] = path, unique_path[1]
Expand Down

0 comments on commit 9372b06

Please sign in to comment.