3
3
import logging
4
4
from collections import defaultdict
5
5
from typing import Iterator
6
- from operator import attrgetter
7
6
8
7
import attrs
9
8
@@ -83,7 +82,7 @@ def __attrs_post_init__(self):
83
82
if self .bisection_factor < 2 :
84
83
raise ValueError ("Must have at least two segments per iteration (i.e. bisection_factor >= 2)" )
85
84
86
- def _validate_and_adjust_columns (self , table1 , table2 ):
85
+ def _validate_and_adjust_columns (self , table1 , table2 , * , strict : bool = True ):
87
86
for c1 , c2 in safezip (table1 .relevant_columns , table2 .relevant_columns ):
88
87
if c1 not in table1 ._schema :
89
88
raise ValueError (f"Column '{ c1 } ' not found in schema for table { table1 } " )
@@ -93,23 +92,23 @@ def _validate_and_adjust_columns(self, table1, table2):
93
92
# Update schemas to minimal mutual precision
94
93
col1 = table1 ._schema [c1 ]
95
94
col2 = table2 ._schema [c2 ]
96
- if isinstance (col1 , PrecisionType ):
97
- if not isinstance (col2 , PrecisionType ):
95
+ if isinstance (col1 , PrecisionType ) and isinstance ( col2 , PrecisionType ) :
96
+ if strict and not isinstance (col2 , PrecisionType ):
98
97
raise TypeError (f"Incompatible types for column '{ c1 } ': { col1 } <-> { col2 } " )
99
98
100
- lowest = min (col1 , col2 , key = attrgetter ( " precision" ) )
99
+ lowest = min (col1 , col2 , key = lambda col : col . precision )
101
100
102
101
if col1 .precision != col2 .precision :
103
102
logger .warning (f"Using reduced precision { lowest } for column '{ c1 } '. Types={ col1 } , { col2 } " )
104
103
105
104
table1 ._schema [c1 ] = attrs .evolve (col1 , precision = lowest .precision , rounds = lowest .rounds )
106
105
table2 ._schema [c2 ] = attrs .evolve (col2 , precision = lowest .precision , rounds = lowest .rounds )
107
106
108
- elif isinstance (col1 , (NumericType , Boolean )):
109
- if not isinstance (col2 , (NumericType , Boolean )):
107
+ elif isinstance (col1 , (NumericType , Boolean )) and isinstance ( col2 , ( NumericType , Boolean )) :
108
+ if strict and not isinstance (col2 , (NumericType , Boolean )):
110
109
raise TypeError (f"Incompatible types for column '{ c1 } ': { col1 } <-> { col2 } " )
111
110
112
- lowest = min (col1 , col2 , key = attrgetter ( " precision" ) )
111
+ lowest = min (col1 , col2 , key = lambda col : col . precision )
113
112
114
113
if col1 .precision != col2 .precision :
115
114
logger .warning (f"Using reduced precision { lowest } for column '{ c1 } '. Types={ col1 } , { col2 } " )
@@ -120,11 +119,11 @@ def _validate_and_adjust_columns(self, table1, table2):
120
119
table2 ._schema [c2 ] = attrs .evolve (col2 , precision = lowest .precision )
121
120
122
121
elif isinstance (col1 , ColType_UUID ):
123
- if not isinstance (col2 , ColType_UUID ):
122
+ if strict and not isinstance (col2 , ColType_UUID ):
124
123
raise TypeError (f"Incompatible types for column '{ c1 } ': { col1 } <-> { col2 } " )
125
124
126
125
elif isinstance (col1 , StringType ):
127
- if not isinstance (col2 , StringType ):
126
+ if strict and not isinstance (col2 , StringType ):
128
127
raise TypeError (f"Incompatible types for column '{ c1 } ': { col1 } <-> { col2 } " )
129
128
130
129
for t in [table1 , table2 ]:
0 commit comments