[Numpy-discussion] Casting Bug or a "Feature"?

Chris Barker - NOAA Federal chris.barker at noaa.gov
Fri Jan 18 01:23:10 EST 2013


On Thu, Jan 17, 2013 at 5:19 PM, Olivier Delalleau <shish at keba.be> wrote:
> 2013/1/16  <josef.pktd at gmail.com>:
>> On Wed, Jan 16, 2013 at 10:43 PM, Patrick Marsh
>> <patrickmarshwx at gmail.com> wrote:

>> I could live with an exception for lossy down casting in this case.

I'm not sure what the idea here is -- would you only get an exception
if the value was such that the downcast would be lossy? If so, a major
-1

The other option would be to always raise an exception if types would
cause a downcast, i.e:

arr = np.zeros(shape, dtype-uint8)

arr2 = arr + 30 # this would raise an exception

arr2 = arr + np.uint8(30) # you'd have to do this

That sure would be clear and result if few errors of this type, but
sure seems verbose and "static language like" to me.

> Long story short, +1 for warning, -1 for exception, and +1 for a
> config flag that allows one to change to exceptions by default, if
> desired.

is this for value-dependent or any casting of this sort?

-Chris


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov



More information about the NumPy-Discussion mailing list