Skip to content

Commit

Permalink
Refacto: introduce intermediary methods to create cells in case of pr…
Browse files Browse the repository at this point in the history
…imary key constraint and considering case-sensitivity
  • Loading branch information
amelie-rondot committed Feb 10, 2024
1 parent 69bc07a commit af7bb2a
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions frictionless/resources/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,18 +413,29 @@ def primary_key_cells(
self,
row: Row,
case_sensitive: bool
) -> Tuple[Row, Any]:
) -> Tuple[str, Any]:
"""Create a tuple containg all cells related to primary_key
"""
return tuple(row[label] for label in
self.labels_related_to_primary_key(row, case_sensitive))

def labels_related_to_primary_key(
self,
row: Row,
case_sensitive: bool,
) -> List[str]:
"""Create a list of TabelResource labels which correspond to the
primary_key schema considering case-sensitivity
"""
if case_sensitive:
cells = tuple(row[name] for name in self.schema.primary_key)
else: # Ignore case
lower_primary_keys = [
labels_primary_key = self.schema.primary_key
else:
lower_primary_key = [
pk.lower() for pk in self.schema.primary_key
]
labels_primary_key = [label for label in row.field_names if label.lower() in lower_primary_keys]
cells = tuple(row[label] for label in labels_primary_key)
return cells
labels_primary_key = [label for label in row.field_names
if label.lower() in lower_primary_key]
return labels_primary_key

# Read
def read_cells(self, *, size: Optional[int] = None) -> List[List[Any]]:
Expand Down

0 comments on commit af7bb2a

Please sign in to comment.