<div dir="ltr">Numpy already does support a specific unit, datetime64 and timedelta64, think through that very mechanism.  Its also probably the most complicated unit since at least there is no such thing as leap meters.  And it works well and is very useful IMHO<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Nov 2, 2017 at 3:40 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"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Thu, Nov 2, 2017 at 2:37 PM, Stephan Hoyer <span dir="ltr"><<a href="mailto:shoyer@gmail.com" target="_blank">shoyer@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"><span><div class="gmail_quote"><div dir="ltr">On Thu, Nov 2, 2017 at 9:45 AM <<a href="mailto:josef.pktd@gmail.com" target="_blank">josef.pktd@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">similar, scipy.special has ufuncs<br></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>what units are those?</div><div><br></div><div>Most code that I know (i.e. scipy.stats and statsmodels) does not use only</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>"normal mathematical operations with ufuncs"<br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I guess there are a lot of "abnormal" mathematical operations </div><div>where just simply propagating the units will not work.</div></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div><br></div><div>Aside: The problem is more general also for other datastructures.</div><div>E.g. statsmodels for most parts uses only numpy ndarrays inside the</div><div>algorithm and computations because that provides well defined</div><div>behavior. (e.g. pandas behaved too differently in many cases) </div><div>I don't have much idea yet about how to change the infrastructure to</div><div>allow the use of dask arrays, sparse matrices and similar and possibly </div><div>automatic differentiation.</div></div></div></div></blockquote><div><br></div></div></span><div dir="ltr"><div class="gmail_quote"><div>This is the exact same reason why pandas and xarray do not support wrapping arbitrary ndarray subclasses or duck array types. The operations we use internally (on numpy.ndarray objects) may not be what you would expect externally, and may even be implementation details not considered part of the public API. For example, in xarray we use numpy.nanmean() or bottleneck.nanmean() instead of numpy.mean().</div><div><br></div><div>For NumPy and xarray, I think we could (and should) define an interface to support subclasses and duck types for generic operations for core use-cases. My main concern with subclasses / duck-arrays is undefined/untested behavior, especially where we might silently give the wrong answer or trigger some undesired operation (e.g., loading a lazily computed into memory) rather than raising an informative error. Leaking implementation details is another concern: we have already had several cases in NumPy where a function only worked on a subclass if a particular method was called internally, and broke when that was changed.</div></div></div></div></blockquote><div><br></div></div></div><div>Would this issue be ameliorated given Nathaniel's proposal to try to move away from subclasses and towards storing data in dtypes? Or would that just mean that xarray would need to ban dtypes it doesn't know about?<br></div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>______________________________<wbr>_________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/numpy-discussion</a><br>
<br></blockquote></span></div><br></div></div>
<br>______________________________<wbr>_________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/numpy-<wbr>discussion</a><br>
<br></blockquote></div><br></div>