Skip to content

Commit

Permalink
Fix issue with combine while filling None's
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed Oct 17, 2023
1 parent 3e99d12 commit 1b441b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/biocframe/BiocFrame.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,23 +844,27 @@ def combine(self, *other: "BiocFrame") -> "BiocFrame":
all_objects = [self] + list(other)

all_columns = [x.column_names for x in all_objects]
all_columns.append(self.column_names)
all_unique_columns = list(
set([item for sublist in all_columns for item in sublist])
)

all_row_names = [None] * len(self) if self.row_names is None else self.row_names
all_num_rows = sum([len(x) for x in all_objects])
all_data = self.data.copy()

for ocol in all_unique_columns:
if ocol not in all_data:
all_data[ocol] = [None] * len(self)

for obj in other:
for ocol in all_unique_columns:
if ocol not in all_data:
all_data[ocol] = [None] * len(obj)

_tcol = None
if ocol not in obj.column_names:
all_data[ocol] = [None] * len(obj)
_tcol = [None] * len(obj)
else:
all_data[ocol] = combine(all_data[ocol], obj.column(ocol))
_tcol = obj.column(ocol)

all_data[ocol] = combine(all_data[ocol], _tcol)

rnames = obj.row_names
if rnames is None:
Expand Down
2 changes: 1 addition & 1 deletion src/biocframe/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def validate_rows(

if len(incorrect_len_keys) > 0:
raise ValueError(
"`BiocFrame` expects all columns in ``data`` to be of equal"
"All columns in ``data`` must be the same "
f"length, these columns do not: {', '.join(incorrect_len_keys)}."
)

Expand Down

0 comments on commit 1b441b1

Please sign in to comment.