Skip to content

Commit

Permalink
Refacto: WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
amelie-rondot committed Feb 10, 2024
1 parent ff761a5 commit 833b898
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions frictionless/resources/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ def __open_row_stream(self):
enumerated_content_stream = self.dialect.read_enumerated_content_stream(
self.cell_stream
)


# Create row stream
def row_stream():
Expand Down Expand Up @@ -332,17 +333,8 @@ def row_stream():
# Primary Key Error
if is_integrity and self.schema.primary_key:
try:
if self.dialect.header_case:
cells = tuple(row[name] for name in self.schema.primary_key)
else: # Ignore case
cells = ()
lower_primary_keys = [
pk.lower() for pk in self.schema.primary_key
]
# cells = tuple(row[label] if (label.lower() for label in row.field_names) in lower_primary_keys )
for label in row.field_names:
if label.lower() in lower_primary_keys:
cells = cells + (row[label],)
cells = self.primary_key_cells(row,
self.dialect.header_case)
except KeyError:
# Row does not have primary_key as key
# There should already be a missing-label error in
Expand Down Expand Up @@ -417,8 +409,27 @@ def row_stream():
# # Create row stream
self.__row_stream = row_stream()

# Read
def primary_key_cells(
self,
row: Row,
case_sensitive: bool
) -> Tuple[Row, Any]:
"""Create a tuple containg all cells related to primary_key
"""
if case_sensitive:
cells = tuple(row[name] for name in self.schema.primary_key)
else: # Ignore case
cells = ()
lower_primary_keys = [
pk.lower() for pk in self.schema.primary_key
]
# cells = tuple(row[label] if (label.lower() for label in row.field_names) in lower_primary_keys )
for label in row.field_names:
if label.lower() in lower_primary_keys:
cells = cells + (row[label],)
return cells

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

0 comments on commit 833b898

Please sign in to comment.