Skip to content

Commit

Permalink
use concat_tables to remove unsupported cast
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekstrand committed Jan 21, 2025
1 parent 157b69f commit 9c49413
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lenskit/lenskit/data/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,11 @@ def add_entities(
raise DataError(f"found {n_dupes} duplicate IDs, but re-inserts not allowed")

log.debug("adding %d new IDs", len(fresh_ids))
new_tbl = pa.table({id_name: fresh_ids})
if table is None:
table = pa.table({id_name: fresh_ids})
table = new_tbl
else:
new_batch = pa.record_batch({id_name: fresh_ids})
new_batch = new_batch.cast(schema)
batches = table.to_batches()
batches.append(new_batch)
table = pa.Table.from_batches(batches)
table = pa.concat_tables([table, new_tbl], promote_options="permissive")

self._tables[cls] = table

Expand Down Expand Up @@ -328,12 +325,7 @@ def add_relationships(

cur_table = self._tables[cls]
if cur_table is not None:
schema = pa.unify_schemas(
[cur_table.schema, new_table.schema], promote_options="permissive"
)
batches = [b.cast(schema) for b in cur_table.to_batches()]
batches += [b.cast(schema) for b in new_table.to_batches()]
new_table = pa.Table.from_batches(batches)
new_table = pa.concat_tables([cur_table, new_table], promote_options="permissive")

if not rc_def.repeats.is_present:
_log.debug("checking for repeated interactions")
Expand Down

0 comments on commit 9c49413

Please sign in to comment.