[Python-Dev] PEP 0484 - the Numeric Tower (original) (raw)
Chris Barker chris.barker at noaa.gov
Wed Oct 14 18:36:35 EDT 2015
- Previous message (by thread): [Python-Dev] PEP 0484 - the Numeric Tower
- Next message (by thread): [Python-Dev] PEP 0484 - the Numeric Tower
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Oct 14, 2015 at 3:04 PM, Laura Creighton <lac at openend.se> wrote:
That code writers in the scientific python world mostly never think of Decimal users, doesn't mean they don't end up writing perfectly wonderful tools and libraries we use. :) thankfully :)
sure -- but those are almost guaranteed to convert to float internally, as there is no decimal dtype for numpy.
in fact, much numpy code is actually semi-statically typed. The common idiom is to write your functions to take "something that can be turned into a float array", which, in practice, means that calling:
np.asarray(the_input_object, dtype-np.float64)
Doesn't raise an exception.[1] And, often ends up returning an array with the right shape, also, so maybe:
np.asarray(the_input_object, dtype-np.float64).reshape(-1, 2)
I guess it would be nice if there were a way to describe that in type annotations.
-CHB
[1] for those not in the know, "asarray" is more or less:
if the input is already an array as specified, return that array unchanged.
elif the input is a buffer or memoryview that fits the specification, wrap an ndarray around that buffer.
else call np.array() on it -- which will attempt make an appropriate numpy array, and copy the values from the input object into it.
I was looking for a way for the Python type hinting to be expressive
enough to handle this common (at least in my world) case. So then, even if the bokeh developers (just to pick some friends) forget about me in their type annotations,
as you see above, it's generally more complicated than a single scalar dtype...
--
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20151014/db68a3ae/attachment.html>
- Previous message (by thread): [Python-Dev] PEP 0484 - the Numeric Tower
- Next message (by thread): [Python-Dev] PEP 0484 - the Numeric Tower
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]