From 047502ed8ec3c2712e6de5ae5784bd0bb21d4dcc Mon Sep 17 00:00:00 2001 From: Sergey Vasilyev Date: Tue, 2 Jan 2024 12:33:32 +0100 Subject: [PATCH] Tolerate column type mismatches in non-strict mode --- data_diff/hashdiff_tables.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/data_diff/hashdiff_tables.py b/data_diff/hashdiff_tables.py index 82f33369..3fb53dd9 100644 --- a/data_diff/hashdiff_tables.py +++ b/data_diff/hashdiff_tables.py @@ -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) @@ -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)