Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if value is None and not self.allow_none:
self.error(obj, value)
if value is None or value is Undefined:
return super(Array, self).validate(obj, value)
try:
r = np.asarray(value, dtype=self.dtype)
if isinstance(value, np.ndarray) and r is not value:
warnings.warn(
'Given trait value dtype "%s" does not match required type "%s". '
'A coerced copy has been created.' % (
np.dtype(value.dtype).name,
np.dtype(self.dtype).name))
value = r
except (ValueError, TypeError) as e:
raise TraitError(e)
return super(Array, self).validate(obj, value)