|
|
|
@ -89,7 +89,7 @@ class Relation:
|
|
|
|
|
content = []
|
|
|
|
|
for row in loaded['content']:
|
|
|
|
|
if len(row) != len(header):
|
|
|
|
|
raise ValueError(_(f'Line {row} contains an incorrect amount of values'))
|
|
|
|
|
raise ValueError(_('Line %d contains an incorrect amount of values') % row)
|
|
|
|
|
t_row: Tuple[Optional[Union[int, float, str, Rdate]], ...] = load(
|
|
|
|
|
row,
|
|
|
|
|
Tuple[Optional[Union[int, float, str, Rdate]], ...], # type: ignore
|
|
|
|
@ -137,7 +137,7 @@ class Relation:
|
|
|
|
|
|
|
|
|
|
for row in content:
|
|
|
|
|
if len(row) != len(header):
|
|
|
|
|
raise ValueError(_(f'Line {row} contains an incorrect amount of values'))
|
|
|
|
|
raise ValueError(_('Line %d contains an incorrect amount of values') % row)
|
|
|
|
|
r_content.append(row)
|
|
|
|
|
|
|
|
|
|
# Guess types
|
|
|
|
@ -181,7 +181,7 @@ class Relation:
|
|
|
|
|
try:
|
|
|
|
|
c_expr = compile(expr, 'selection', 'eval')
|
|
|
|
|
except:
|
|
|
|
|
raise Exception(_(f'Failed to compile expression: {expr}'))
|
|
|
|
|
raise Exception(_('Failed to compile expression: %s') % expr)
|
|
|
|
|
|
|
|
|
|
content = []
|
|
|
|
|
for i in self.content:
|
|
|
|
@ -194,7 +194,7 @@ class Relation:
|
|
|
|
|
if eval(c_expr, attributes):
|
|
|
|
|
content.append(i)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise Exception(_(f'Failed to evaluate {expr} with {i}\n{e}'))
|
|
|
|
|
raise Exception(_('Failed to evaluate {expr} with {i}\n{e}').format(expr=expr, i=i, e=e))
|
|
|
|
|
return Relation(self.header, frozenset(content))
|
|
|
|
|
|
|
|
|
|
def product(self, other: 'Relation') -> 'Relation':
|
|
|
|
@ -473,7 +473,7 @@ class Header(tuple):
|
|
|
|
|
|
|
|
|
|
for i in self:
|
|
|
|
|
if not is_valid_relation_name(i):
|
|
|
|
|
raise Exception(_(f'"{i}" is not a valid attribute name'))
|
|
|
|
|
raise Exception(_('"%s" is not a valid attribute name') % i)
|
|
|
|
|
|
|
|
|
|
if len(self) != len(set(self)):
|
|
|
|
|
raise Exception('Attribute names must be unique')
|
|
|
|
@ -489,12 +489,12 @@ class Header(tuple):
|
|
|
|
|
attrs = list(self)
|
|
|
|
|
for old, new in params.items():
|
|
|
|
|
if not is_valid_relation_name(new):
|
|
|
|
|
raise Exception(_(f'{new} is not a valid attribute name'))
|
|
|
|
|
raise Exception(_('%s is not a valid attribute name') % new)
|
|
|
|
|
try:
|
|
|
|
|
id_ = attrs.index(old)
|
|
|
|
|
attrs[id_] = new
|
|
|
|
|
except:
|
|
|
|
|
raise Exception(_(f'Field not found: {old}'))
|
|
|
|
|
raise Exception(_('Field not found: %s') % old)
|
|
|
|
|
return Header(attrs)
|
|
|
|
|
|
|
|
|
|
def sharedAttributes(self, other: 'Header') -> int:
|
|
|
|
|