[Numpy-discussion] DType Roadmap/NEP Discussion
ralf.gommers at gmail.com
Thu Sep 19 00:33:56 EDT 2019
On Wed, Sep 18, 2019 at 4:35 PM Sebastian Berg <sebastian at sipsolutions.net>
> Hi all,
> to try and make some progress towards a decision since the broad design
> is pretty much settling from my side. I am thinking about making a
> meeting, and suggest Monday at 11am Pacific Time (I am open to other
> times though).
> My hope is to get everyone interested on board, so that we can make an
> informed decision about the general direction very soon. So just reach
> out, or discuss on the mailing list as well.
> The current draft for an NEP is here:
> There are some design goals that I would like to clear up.
The design itself seems very sensible to me insofar as I understand it.
After having read your document again, I think you're still missing the
actual goals though. "structure of class layout" and "type hierarchy" are
important, but they're not the goals. You're touching on the real goals in
places, but it may be valuable to be much more explicit there.
Here are some example goals:
1. Make creating new dtypes via the NumPy C API take >4x less lines of code
on average (in practice: for rational/quaternion, hard to measure
2. Make it possible to create new dypes with full functionality via the
NumPy Python API. Performance may be up to 1-2 orders of magnitude worse
than when creating the same dtype via the C API; the main purpose is to
allow easier prototyping of new dtypes.
3. Make the NumPy codebase more maintainable by removing special-casing of
datetime dtypes in many places.
4. Enable creation of a units library whose arrays *are* numpy arrays
rather than a subclass or duck array. This will make such a library work
much better with SciPy and other existing libraries that use np.asarray
5. Hide currently exposed implementation details in the C API so long-term
.... (you have this one, but it would be nice to work it out a little more
- after all we recently considered reverting the deprecation for direct
field access, so how important is this?)
6. Improve casting behavior for external dtypes
7. Make np.char behavior better <in ... ways> (you mention fixed length
strings work poorly now, but not what would change)
Listing non-goals would also be useful:
1. Performance: no significant performance improvements are expected. We
aim for no performance regressions.
2. Introducing new dtypes into NumPy itself
3. Pandas ExtensionArrays? You mention them, but does this dtype redesign
help Pandas in any way or not?
4. Changes to NumPy's current casting rules
5. Allow creation of dtypes that don't fit the current NumPy model of what
a dtype is (e.g. ref ), such as a variable-length string dtype.
Many of those (and there can be more, this is just what came to mind now)
can/should be a paragraph or section. In my experience describing these
goals and requirements well takes about 15-30% of the length of the design
description. Think of for example a Pandas or units library maintainer
reading this: they should be able to stop reading at where you now have
"Overview Graphic" and have a pretty clear high-level understanding of what
this whole redesign will mean for them. Same for a NumPy maintainer who
wants to get a sense of what the benefits and impacts will be: reading only
(the expanded version of) your Abstract, Motivation and Scope, and
Backwards Compatibility sections should be enough.
Here's a concrete question, that's the type of thing I'd like to understand
without having to understand the whole design in detail:
>>> import datetime
>>> import pandas as pd
>>> import datetime
>>> dti = pd.to_datetime(['1/1/2018', np.datetime64('2018-01-01'),
... datetime.datetime(2018, 1, 1)])
>>> isinstance(dti.values.dtype, np.dtype)
>>> dti.dtype == dti.values.dtype # okay, that's nice
>>> start = pd.to_datetime('2015-02-24')
>>> rng = pd.date_range(start, periods=3)
>>> t = pd.Series(rng)
>>> t_withzone = t.dt.tz_localize('UTC').dt.tz_convert('Asia/Kolkata')
0 2015-02-24 05:30:00+05:30
1 2015-02-25 05:30:00+05:30
2 2015-02-26 05:30:00+05:30
dtype: datetime64[ns, Asia/Kolkata]
>>> t_withzone.dtype == t_withzone.values.dtype # could this be True in
So can Pandas create timezone-aware numpy dtypes in the future if they want
to, or would they still be better off rolling their own?
Also one question/comment about the design content. When looking at the
current external dtypes (e.g. ), a large part of the work of
implementing a new dtype now deals with ufunc behavior. It's not clear from
your document how that changes with the new design, can you add something
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion