Re: [Numpy-discussion] Deprecating silent truncation of floats when assigned to int array

2016-06-17 Thread Ralf Gommers
On Tue, Jun 14, 2016 at 12:23 AM, Ian Henriksen <
insertinterestingnameh...@gmail.com> wrote:

> Personally, I think this is a great idea. +1 to more informative errors.
>

+1 from me as well

Ralf



> Best,
> Ian Henriksen
>
> On Mon, Jun 13, 2016 at 2:11 PM Nathaniel Smith  wrote:
>
>> It was recently pointed out:
>>
>>   https://github.com/numpy/numpy/issues/7730
>>
>> that this code silently truncates floats:
>>
>> In [1]: a = np.arange(10)
>>
>> In [2]: a.dtype
>> Out[2]: dtype('int64')
>>
>> In [3]: a[3] = 1.5
>>
>> In [4]: a[3]
>> Out[4]: 1
>>
>> The proposal is that we should deprecate this, and eventually turn it
>> into an error. Any objections?
>>
>> We recently went through a similar deprecation cycle for in-place
>> operations, i.e., this used to silently truncate but now raises an
>> error:
>>
>> In [1]: a = np.arange(10)
>>
>> In [2]: a += 1.5
>>
>> ---
>> TypeError Traceback (most recent call
>> last)
>>  in ()
>> > 1 a += 1.5
>>
>> TypeError: Cannot cast ufunc add output from dtype('float64') to
>> dtype('int64') with casting rule 'same_kind'
>>
>> so the proposal here is to extend this to regular assignment.
>>
>> -n
>>
>> --
>> Nathaniel J. Smith -- https://vorpus.org
>> ___
>> NumPy-Discussion mailing list
>> NumPy-Discussion@scipy.org
>> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Deprecating silent truncation of floats when assigned to int array

2016-06-13 Thread Ian Henriksen
Personally, I think this is a great idea. +1 to more informative errors.
Best,
Ian Henriksen

On Mon, Jun 13, 2016 at 2:11 PM Nathaniel Smith  wrote:

> It was recently pointed out:
>
>   https://github.com/numpy/numpy/issues/7730
>
> that this code silently truncates floats:
>
> In [1]: a = np.arange(10)
>
> In [2]: a.dtype
> Out[2]: dtype('int64')
>
> In [3]: a[3] = 1.5
>
> In [4]: a[3]
> Out[4]: 1
>
> The proposal is that we should deprecate this, and eventually turn it
> into an error. Any objections?
>
> We recently went through a similar deprecation cycle for in-place
> operations, i.e., this used to silently truncate but now raises an
> error:
>
> In [1]: a = np.arange(10)
>
> In [2]: a += 1.5
> ---
> TypeError Traceback (most recent call last)
>  in ()
> > 1 a += 1.5
>
> TypeError: Cannot cast ufunc add output from dtype('float64') to
> dtype('int64') with casting rule 'same_kind'
>
> so the proposal here is to extend this to regular assignment.
>
> -n
>
> --
> Nathaniel J. Smith -- https://vorpus.org
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Deprecating silent truncation of floats when assigned to int array

2016-06-13 Thread Nathaniel Smith
It was recently pointed out:

  https://github.com/numpy/numpy/issues/7730

that this code silently truncates floats:

In [1]: a = np.arange(10)

In [2]: a.dtype
Out[2]: dtype('int64')

In [3]: a[3] = 1.5

In [4]: a[3]
Out[4]: 1

The proposal is that we should deprecate this, and eventually turn it
into an error. Any objections?

We recently went through a similar deprecation cycle for in-place
operations, i.e., this used to silently truncate but now raises an
error:

In [1]: a = np.arange(10)

In [2]: a += 1.5
---
TypeError Traceback (most recent call last)
 in ()
> 1 a += 1.5

TypeError: Cannot cast ufunc add output from dtype('float64') to
dtype('int64') with casting rule 'same_kind'

so the proposal here is to extend this to regular assignment.

-n

-- 
Nathaniel J. Smith -- https://vorpus.org
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion