def _promote_numeric(self, typ): coercer = expressions.coercer_from_dtype(typ) if isinstance(typ, tarray) and not isinstance(self.dtype, tarray): return coercer.ec.coerce(self) elif isinstance(typ, tndarray) and not isinstance(self.dtype, tndarray): return coercer.ec.coerce(self) else: return coercer.coerce(self)
def unify_exprs(*exprs: 'Expression') -> Tuple: assert len(exprs) > 0 types = {e.dtype for e in exprs} # all types are the same if len(types) == 1: return exprs + (True, ) for t in types: c = expressions.coercer_from_dtype(t) if all(c.can_coerce(e.dtype) for e in exprs): return tuple([c.coerce(e) for e in exprs]) + (True, ) # cannot coerce all types to the same type return exprs + (False, )
def unify_exprs(*exprs: 'Expression') -> Tuple: assert len(exprs) > 0 types = {e.dtype for e in exprs} # all types are the same if len(types) == 1: return exprs + (True,) for t in types: c = expressions.coercer_from_dtype(t) if all(c.can_coerce(e.dtype) for e in exprs): return tuple([c.coerce(e) for e in exprs]) + (True,) # cannot coerce all types to the same type return exprs + (False,)