Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subtables do not validate during concatenation #65

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion quivr/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,12 @@ def __get__(self, obj: Optional[tables.Table], objtype: type) -> Union[Self, T]:
schema = self.schema.with_metadata(metadata)

subtable = pa.Table.from_arrays(array.flatten(), schema=schema)
return self.table_type.from_pyarrow(subtable, permit_nulls=self.nullable)
# We don't validate the subtable. If the parent table were validated,
# then the subtable would have been validated as part of that process.
# If the parent table is intentionally not validated, then we don't
# want to validate the subtable either as it will throw an error
# when accessing the subtable as a column (e.g. during concatenation).
return self.table_type.from_pyarrow(subtable, permit_nulls=self.nullable, validate=False)

def _nulls(self, n: int) -> pa.Array:
"""Return an array of nulls of the appropriate size."""
Expand Down
23 changes: 19 additions & 4 deletions test/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,31 @@ def test_concatenate_empty_tables():


def test_concatenate_no_validate():

class OtherTable(qv.Table):
y = qv.Int64Column(validator=qv.le(0))

class ValidationTable(qv.Table):
x = qv.Int64Column(validator=qv.ge(0))
subtable = OtherTable.as_column(nullable=True)

t1 = ValidationTable.from_kwargs(x=[-1], validate=False)
t2 = ValidationTable.from_kwargs(x=[1], validate=False)
valid = ValidationTable.from_kwargs(
x=[1], subtable=OtherTable.from_kwargs(y=[-1], validate=False), validate=False
)
invalid_x = ValidationTable.from_kwargs(x=[-1], subtable=[None], validate=False)
invalid_subtable = ValidationTable.from_kwargs(
x=[1], subtable=OtherTable.from_kwargs(y=[1], validate=False), validate=False
)

with pytest.raises(qv.ValidationError, match="Column x failed validation"):
qv.concatenate([t1, t2])
qv.concatenate([invalid_x, valid])

have = qv.concatenate([invalid_x, valid], validate=False)
assert len(have) == 2

have = qv.concatenate([t1, t2], validate=False)
# Subtables are not validated during concatenation, as the main table
# was initialized with validate=False
have = qv.concatenate([valid, invalid_subtable])
assert len(have) == 2


Expand Down
Loading