def _canonical_key(cls, args, kwargs): extra_dims = cls.extra_dims dimensions_set = set(extra_dims) if not set(kwargs) <= dimensions_set: extra = sorted(set(kwargs) - dimensions_set) raise TypeError( '%s does not have the following %s: %s\n' 'Valid dimensions are: %s' % ( cls.__name__, s('dimension', extra), ', '.join(extra), ', '.join(extra_dims), ), ) if len(args) > len(extra_dims): raise TypeError( '%s has %d extra %s but %d %s given' % ( cls.__name__, len(extra_dims), s('dimension', extra_dims), len(args), plural('was', 'were', args), ), ) missing = object() coords = OrderedDict(zip(extra_dims, repeat(missing))) to_add = dict(zip(extra_dims, args)) coords.update(to_add) added = set(to_add) for key, value in kwargs.items(): if key in added: raise TypeError( '%s got multiple values for dimension %r' % ( cls.__name__, coords, ), ) coords[key] = value added.add(key) missing = {k for k, v in coords.items() if v is missing} if missing: missing = sorted(missing) raise TypeError( 'no coordinate provided to %s for the following %s: %s' % ( cls.__name__, s('dimension', missing), ', '.join(missing), ), ) # validate that all of the provided values exist along their given # dimensions for key, value in coords.items(): if value not in cls.extra_dims[key]: raise ValueError( '%r is not a value along the %s dimension of %s' % ( value, key, cls.__name__, ), ) return coords, tuple(coords.items())
def _canonical_key(cls, args, kwargs): extra_dims = cls.extra_dims dimensions_set = set(extra_dims) if not set(kwargs) <= dimensions_set: extra = sorted(set(kwargs) - dimensions_set) raise TypeError( '%s does not have the following %s: %s\n' 'Valid dimensions are: %s' % ( cls.__name__, s('dimension', extra), ', '.join(extra), ', '.join(extra_dims), ), ) if len(args) > len(extra_dims): raise TypeError( '%s has %d extra %s but %d %s given' % ( cls.__name__, len(extra_dims), s('dimension', extra_dims), len(args), plural('was', 'were', args), ), ) missing = object() coords = OrderedDict(zip(extra_dims, repeat(missing))) to_add = dict(zip(extra_dims, args)) coords.update(to_add) added = set(to_add) for key, value in kwargs.items(): if key in added: raise TypeError( '%s got multiple values for dimension %r' % ( cls.__name__, coords, ), ) coords[key] = value added.add(key) missing = {k for k, v in coords.items() if v is missing} if missing: missing = sorted(missing) raise TypeError( 'no coordinate provided to %s for the following %s: %s' % ( cls.__name__, s('dimension', missing), ', '.join(missing), ), ) # validate that all of the provided values exist along their given # dimensions for key, value in coords.items(): if value not in cls.extra_dims[key]: raise ValueError( '%r is not a value along the %s dimension of %s' % ( value, key, cls.__name__, ), ) return coords, tuple(coords.items())