Skip to content

add_row and add_rows should not raise if schemata differ #127

@lars-reimann

Description

@lars-reimann

Is your feature request related to a problem?

At the moment, the add_row and add_rows methods of Table raise an exception if the schemata of the current Table and the new Row differ:

if self._schema != row.schema:
    raise SchemaMismatchError()

This is a particular problem, if the Table is empty.

Desired solution

  • If the schema of the Table is empty (no columns), accept any Row and use the schema of the Row as the schema of the new Table
  • Otherwise, verify that the list of column names is the same for the Table and the Row. Don't fail if the types differ, but instead widen them so all values in the Table and the values in the Row are included. For each column, the resulting type should be the lowest common supertype of the type of the column in the Table and the Row

Example:

  • Schema of Table:
{
   "a": Integer()
}
  • Schema of Row:
{
   "a": RealNumber()
}
  • Schema of resulting Table:
{
   "a": RealNumber() # Common supertype of `Integer()` and `RealNumber()`
}

Type hierarchy:

  • Anything
    • RealNumber
      • Integer
    • Boolean
    • String

Nullability of one of the types gets propagated to the result, i.e. iff any of the types was nullable, the result type is also nullable.

Possible alternatives (optional)

No response

Screenshots (optional)

No response

Additional Context (optional)

No response

Metadata

Metadata

Labels

releasedIncluded in a release

Type

No type

Projects

Status

✔️ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions