in torcharrow/dtypes.py [0:0]
def common_dtype(l, r):
if is_void(l):
return r.with_null()
if is_void(r):
return l.with_null()
if is_any(l):
return r
if is_any(r):
return l
if is_string(l) and is_string(r):
return String(l.nullable or r.nullable)
if is_boolean_or_numerical(l) and is_boolean_or_numerical(r):
return promote(l, r)
if is_tuple(l) and is_tuple(r) and len(l.fields) == len(r.fields):
res = []
for i, j in zip(l.fields, r.fields):
m = common_dtype(i, j)
if m is None:
return None
res.append(m)
return Tuple(res).with_null(l.nullable or r.nullable)
if is_map(l) and is_map(r):
k = common_dtype(l.key_dtype, r.key_dtype)
i = common_dtype(l.item_dtype, r.item_dtype)
return (
Map(k, i).with_null(l.nullable or r.nullable)
if k is not None and i is not None
else None
)
if is_list(l) and is_list(r):
k = common_dtype(l.item_dtype, r.item_dtype)
return List(k).with_null(l.nullable or r.nullable) if k is not None else None
if l.with_null() == r.with_null():
return l if l.nullable else r
return None