Re: [Python-Dev] PEP 0484 - the Numeric Tower

2015年10月14日 15:39:06 -0700

On Wed, Oct 14, 2015 at 3:04 PM, Laura Creighton <[email protected]> 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
[email protected]
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to