[Numpy-discussion] tighten up ufunc casting rule

Mark Wiebe mwwiebe@gmail....
Thu Jun 2 15:06:58 CDT 2011


Would anyone object to, at least temporarily, tightening up the default
ufunc casting rule to 'same_kind' in NumPy master? It's a one line change,
so would be easy to undo, but such a change is very desirable in my opinion.

This would raise an exception, since it's np.add(a, 1.9, out=a), converting
a float to an int:

>>> a = np.arange(3, dtype=np.int32)

>>> a += 1.9


It's also relevant to the discussion of nonlinear datetime units and
datetime in general. Currently, it will silently convert a months or years
delta to a days delta. I've made the conversions between non-linear metadata
not satisfy the 'same_kind' rule, so they would be disallowed by default as
well (but easily enabled with a casting='unsafe' parameter).

By doing this change, we can see what other code it affects, such as scipy,
and patch that code to be safe for this convention whether or not it is
adopted in the next release.

-Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110602/984e7529/attachment.html 


More information about the NumPy-Discussion mailing list