Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Tolerate column type mismatches in non-strict mode #829

Merged
merged 1 commit into from
Jan 2, 2024
Merged
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
14 changes: 10 additions & 4 deletions data_diff/hashdiff_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ def _validate_and_adjust_columns(self, table1: TableSegment, table2: TableSegmen
col1 = table1._schema[c1]
col2 = table2._schema[c2]
if isinstance(col1, PrecisionType):
if strict and not isinstance(col2, PrecisionType):
raise TypeError(f"Incompatible types for column '{c1}': {col1} <-> {col2}")
if not isinstance(col2, PrecisionType):
if strict:
raise TypeError(f"Incompatible types for column '{c1}': {col1} <-> {col2}")
else:
continue

lowest = min(col1, col2, key=lambda col: col.precision)

Expand All @@ -123,8 +126,11 @@ def _validate_and_adjust_columns(self, table1: TableSegment, table2: TableSegmen
table2._schema[c2] = attrs.evolve(col2, precision=lowest.precision, rounds=lowest.rounds)

elif isinstance(col1, (NumericType, Boolean)):
if strict and not isinstance(col2, (NumericType, Boolean)):
raise TypeError(f"Incompatible types for column '{c1}': {col1} <-> {col2}")
if not isinstance(col2, (NumericType, Boolean)):
if strict:
raise TypeError(f"Incompatible types for column '{c1}': {col1} <-> {col2}")
else:
continue

lowest = min(col1, col2, key=lambda col: col.precision)

Expand Down