Skip to content

Commit

Permalink
Don't sort string indexes when merging parameter values
Browse files Browse the repository at this point in the history
Sorting may break e.g. time pattern values or maps with
arbitrary string indices.
  • Loading branch information
soininen committed Oct 30, 2024
1 parent 34c8ead commit d076802
Show file tree
Hide file tree
Showing 3 changed files with 253 additions and 213 deletions.
9 changes: 7 additions & 2 deletions spinedb_api/parameter_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,13 @@ def to_dict(self):
def merge(self, other):
if not isinstance(other, type(self)):
return self
new_indexes = np.unique(np.concatenate((self.indexes, other.indexes)))
new_indexes.sort(kind="mergesort")
if self.indexes and not isinstance(self.indexes[0], str):
new_indexes = np.unique(np.concatenate((self.indexes, other.indexes)))
else:
# Avoid sorting when indices are arbitrary strings
existing = set(self.indexes)
additional = [x for x in other.indexes if x not in existing]
new_indexes = np.concat((self.indexes, additional))

def _merge(value, other):
return other if value is None else merge_parsed(value, other)
Expand Down
5 changes: 5 additions & 0 deletions tests/mock_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ def _assert_success(self, result):
item, error = result
self.assertIsNone(error)
return item

def _assert_imports(self, result):
count, errors = result
self.assertEqual(errors, [])
return count
Loading

0 comments on commit d076802

Please sign in to comment.