<div dir="ltr">So to be explicit, since you never actually say it, you are proposing to change the YTArray behavior to allow for adding a dimensionless 0 to a unitful array without erroring?<div><br></div><div>If that is what you're suggesting, it seems fine to me, but couldn't we just turn off the `start` argument to solve this problem without your proposed change?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 31, 2016 at 12:39 PM, Nathan Goldbaum <span dir="ltr"><<a href="mailto:nathan12343@gmail.com" target="_blank">nathan12343@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>Today a student I am working with ran into an issue illustrated by the following test script:</div><div><br></div><div>    from yt.units import cm</div><div><br></div><div>    arr = [1, 2, 3]*cm</div><div>    sum(arr)</div><div><br></div><div>Right now this errors out with the following traceback:</div><div><br></div><div><a href="http://paste.yt-project.org/show/6378/" target="_blank">http://paste.yt-project.org/show/6378/</a><br></div><div><br></div><div>The reason for this is that the python builtin sum command has an optional `start` argument, which defaults to 0. The error is happening because the first element of the array (1 km) has different units from 0.</div><div><br></div><div>Sum is probably not the best way to do this, but I think erroring out here is an overly harsh user experience, especially for a user who is new to python and might not be aware of the possible performance implications of using sum on a large array.</div><div><br></div><div>Incidentally, an analogous script with astropy quantities does work:</div><div><br></div><div>    from astropy.units import cm</div><div><br></div><div>    arr = [1, 2, 3]*cm</div><div>    sum(arr)</div><div><br></div><div>This is because astropy's quantities let you add zero (and just zero, no other float or integer will work) to an array or quantity with any units.</div><div><br></div><div>On a philosophical level, the difference between 0 cm and 0 is not particular useful in practice, and operationally allowing 0 to be added or subtracted from YTArray instances without erroring out should not have any concrete implications for real programs, since until now it has raised an error. To be honest, I'm now regretting not thinking carefully about this until now....</div><div><br></div><div>Since this is a change to how YTArray, which is fundamental to yt's internals, I wanted to check with the list before proposing a pull request that implements this change.</div><div><br></div><div>Does anyone have any objections?</div><div><br></div><div>Thanks!</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Nathan</div></font></span></div>
<br>_______________________________________________<br>
yt-dev mailing list<br>
<a href="mailto:yt-dev@lists.spacepope.org">yt-dev@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org" rel="noreferrer" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Cameron Hummels<div><span style="font-size:12.8000001907349px">NSF Postdoctoral Fellow</span></div><div><span style="font-size:12.8000001907349px">Department of Astronomy</span></div><div><span style="font-size:12.8000001907349px">California Institute of Technology</span><br></div><div><a href="http://chummels.org" style="font-size:12.8000001907349px" target="_blank">http://chummels.org</a><br></div></div></div></div>
</div>