-
-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quantity 2.0 #91
base: main
Are you sure you want to change the base?
Quantity 2.0 #91
Conversation
Signed-off-by: nstarman <[email protected]>
I totally missed this one, so I am confused why there is a APE 23 and APE 25 here. And why report is in PDF instead of Markdown. Is this related to the following? |
I'll clean that up.
The report was for the Moore grant, not the APE. I'm including the PDF to eventually turn into an APE, written in Markdown. |
@nstarman, I think this looks really good so far, I'm quite excited to work with other arrays inside Quantity! I was wondering if you have given any thought to supporting arrays with labeled axes (e.g. xarray) during this effort? I think supporting xarray (or the other way around, xarray supporting Quantity) is really important going forward, and I think it's worth considering adding first-class support this feature for Quantity 2.0. |
xarray already has support for units via https://github.com/xarray-contrib/pint-xarray, so making |
I guess it depends on how we want to interact with the rest of the astropy ecosystem, for example: how can we make |
Support for x-array has to use their framework, which is how |
@rieder, @LourensVeen - this is the document for Quantity wrapping that I was talking about. |
@nstarman - I've been thinking a bit more about the Quantity 2.0 things, and one question I wonder about is the subclassing vs a protocal logic. I think I understand the basic idea well enough -- and like the idea for Somewhat related, but more on the implementation, I found the use of the Anyway, really just for clarification! |
Second question is more of a nitpick - I'm not enchanted with |
Yeah. With (as a note, the simple
Agreed that the Either way, I think my suggestion would be start by not implementing the
We can add the subclassing or |
That's for sure. But IMO still worthwhile pursuing. I would be interested to reach to folks in the fall.
It's interesting. The most useful bit about the protocol is that it's a concrete definition of the duck type. In many respects getting community agreement on the protocol is key to defining it. That being said, my top realistic choice would be for us to define a Protocol, then assemble other unit libraries to collaborate on a Quantity API under the auspices of the Consortium for Python Data API Standards (https://data-apis.org). Our Protocol would then become a subclass of the common Protocol, which adds on any Astropy-specific functionality, e.g. |
One more thing: you mention wanting quantities to be immutable - is that meant to be just for the instance, or also the underlying array? For numpy arrays, that basically is a non-starter - one has to do in-place stuff with large arrays, both to get decent performance and to reduce memory use. In principle, one could get a new quantity wrapper out, but am not sure if that is not more confusing rather than less: after On p.s. Now followed the links to the |
On the |
I would advocate starting with just the Array API.
|
Just Quantity itself! I agree we shouldn't do anything to the underlying object, except maybe convert it to an array if it's a list.
Really the abstract-final pattern can be summarized as: concrete classes can never inherit from other concrete classes, only abstract ones. This actually ends up simplifying a lot of code / ensuring classes don't get too complex. See https://docs.kidger.site/equinox/pattern/. So for Quantity this would mean
Amongst the many benefits, adding an |
Mostly a reminder, that when discussing other array types in the coordination meeting, one that was considered of particular interest, was |
Hi, xarray dev here 👋 I just saw this issue thanks to @byrdie . @keewis and I are the ones who made xarray work with pint, and wrote the blog post about that. I didn't even know that https://github.com/KaoruNishikawa/xarray-quantity existed! We would love to see integration between xarray and
We can go into details, but in general if your units array class implements the array API then most things in xarray should "just work". |
@TomNicholas - belatedly, also a direct reply to your note: we just discussed how we want to proceed with this "Quantity 2.0" project, and your note made clear that the first alternative to |
PDF link: https://github.com/nstarman/astropy-APEs/blob/units-quantity-2.0/APE25/report.pdf