<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 1, 2015 at 10:32 AM, Sebastian Berg <span dir="ltr"><<a href="mailto:sebastian@sipsolutions.net" target="_blank">sebastian@sipsolutions.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On Mi, 2015-07-01 at 10:05 -0400, <a href="mailto:josef.pktd@gmail.com">josef.pktd@gmail.com</a> wrote:<br>
> About the deprecation warning for using another type than integers, in<br>
> ones, reshape, indexing and so on:<br>
><br>
><br>
> Wouldn't it be nicer to accept floats that are equal to an integer?<br>
><br>
<br>
</span>Hmmm, the biggest point was that the old solution was to basically<br>
(besides strings) use `int(...)`, which means it does not raise any<br>
errors as you also mention.<br>
I am open to think about allowing exact floats for most of this<br>
(frankly, not advanced indexing at least for the moment, but we never<br>
did there), I think scipy may be doing that for some functions?<br>
<br>
The disadvantage I see is, that some weirder calculations would possible<br>
work most of the times, but not always, what I mean is such a case.<br>
A -- possibly silly -- example:<br>
<br>
In [8]: for i in range(10):<br>
...: print i, i == i * 0.1 * 10<br>
...:<br>
0 True<br>
1 True<br>
2 True<br>
3 False<br>
4 True<br>
5 True<br>
6 False<br>
7 False<br>
8 True<br>
9 True<br>
<br>
I am somewhat opposed to rounding a lot (i.e. not noticing if you got<br>
3.3333 somewhere), so not sure if you can define a "tolerance"<br>
reasonable here unless it is exact. Though I guess you are right that<br>
`//` will also just round silently already.<br></blockquote><div><br></div><div>Yes, I thought about this, something like `int_if_close` in analogy to real_if_close would be useful.</div><div><br></div><div>However, given that we need to decide on a threshold in this case, I thought it's overkill to put that into reshape, ones and indexing and similar. </div><div><br></div><div>Simpler cases would work</div><div>number if triangular elements<br></div><div><br></div><div><div>>>> for i in range(10): print(i, i * (i - 1) / 2. == int(i * (i - 1) / 2.))</div><div><br></div><div>0 True</div><div>1 True</div><div>2 True</div><div>3 True</div><div>4 True</div><div>5 True</div><div>6 True</div><div>7 True</div><div>8 True</div><div>9 True</div></div><div><br></div><div>also np.ceil and np.trunc return floats, not integers.</div><div><br></div><div>One disadvantage of raising or warning after the equality check is that developers have a tendency to write "nice" unit tests. Then the casting doesn't break in the unit tests but might raise an exception at some random data.</div><div><br></div><div><br></div><div>For reference: here are my changes in cleaning up</div><div><a href="https://github.com/statsmodels/statsmodels/pull/2490/files">https://github.com/statsmodels/statsmodels/pull/2490/files</a><br></div><div><br></div><div><br></div><div>Josef</div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
- Sebastian<br>
<span class=""><br>
><br>
> for example<br>
><br>
><br>
> >>> 5.0 == 5<br>
> True<br>
><br>
><br>
> >>> np.ones(10 / 2)<br>
> array([ 1., 1., 1., 1., 1.])<br>
> >>> 10 / 2 == 5<br>
> True<br>
><br>
><br>
> or the python 2 version<br>
><br>
><br>
> >>> np.ones(10. / 2)<br>
> array([ 1., 1., 1., 1., 1.])<br>
> >>> 10. / 2 == 5<br>
> True<br>
><br>
><br>
> I'm using now 10 // 2, or int(10./2 + 1) but this is unconditional<br>
> and doesn't raise if the numbers are not close or equal to an integer<br>
> (which would be a bug)<br>
><br>
><br>
><br>
><br>
> Josef<br>
><br>
><br>
><br>
><br>
</span>> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
> <a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br>
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br></div></div>