Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
names, normal variables names, column paths and variable paths
(all are tuples).
"""
# Variable names for column and normal variables.
colnames, varnames = [], []
# Column paths and types for each of the previous variable.
colpaths, vartypes = [], []
for (var, val) in condvars.items():
if hasattr(val, 'pathname'): # column
colnames.append(var)
colpaths.append(val.pathname)
else: # array
try:
varnames.append(var)
vartypes.append(numexpr_getType(val)) # expensive
except ValueError:
# This is more clear than the error given by Numexpr.
raise TypeError( "variable ``%s`` has data type ``%s``, "
"not allowed in conditions"
% (var, val.dtype.name) )
colnames, varnames = tuple(colnames), tuple(varnames)
colpaths, vartypes = tuple(colpaths), tuple(vartypes)
condkey = (condition, colnames, varnames, colpaths, vartypes)
return condkey
values = self.values
types_ = []
for name in self.names:
value = vars_[name]
if hasattr(value, 'atom'):
types_.append(value.atom)
elif hasattr(value, 'dtype'):
types_.append(value)
else:
# try to convert into a NumPy array
value = np.array(value)
types_.append(value)
values.append(value)
# Create a signature for the expression
signature = [(name, getType(type_))
for (name, type_) in zip(self.names, types_)]
# Compile the expression
self._compiled_expr = NumExpr(expr, signature, **kwargs)
# Guess the shape for the outcome and the maindim of inputs
self.shape, self.maindim = self._guess_shape()