VariationModel: assert that locations are unique
This commit is contained in:
parent
d8152feb21
commit
05824b8616
@ -190,6 +190,9 @@ class VariationModel(object):
|
||||
"""
|
||||
|
||||
def __init__(self, locations, axisOrder=None):
|
||||
if len(set(tuple(sorted(l.items())) for l in locations)) != len(locations):
|
||||
raise ValueError("locations must be unique")
|
||||
|
||||
self.origLocations = locations
|
||||
self.axisOrder = axisOrder if axisOrder else []
|
||||
|
||||
@ -197,9 +200,10 @@ class VariationModel(object):
|
||||
keyFunc = self.getMasterLocationsSortKeyFunc(locations, axisOrder=self.axisOrder)
|
||||
axisPoints = keyFunc.axisPoints
|
||||
self.locations = sorted(locations, key=keyFunc)
|
||||
# TODO Assert that locations are unique.
|
||||
self.mapping = [self.locations.index(l) for l in locations] # Mapping from user's master order to our master order
|
||||
self.reverseMapping = [locations.index(l) for l in self.locations] # Reverse of above
|
||||
|
||||
# Mapping from user's master order to our master order
|
||||
self.mapping = [self.locations.index(l) for l in locations]
|
||||
self.reverseMapping = [locations.index(l) for l in self.locations]
|
||||
|
||||
self._computeMasterSupports(axisPoints, self.axisOrder)
|
||||
self._subModels = {}
|
||||
|
@ -138,3 +138,13 @@ class VariationModelTest(object):
|
||||
assert model.locations == sortedLocs
|
||||
assert model.supports == supports
|
||||
assert model.deltaWeights == deltaWeights
|
||||
|
||||
def test_init_duplicate_locations(self):
|
||||
with pytest.raises(ValueError, match="locations must be unique"):
|
||||
VariationModel(
|
||||
[
|
||||
{"foo": 0.0, "bar": 0.0},
|
||||
{"foo": 1.0, "bar": 1.0},
|
||||
{"bar": 1.0, "foo": 1.0},
|
||||
]
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user