-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Part of the discussion in #5329. I'm opening this issue to make the discussion on this topic a bit more focused.
As mentioned in #5329 (comment), we need to find a way to
- call methods on wrapped arrays. e.g. with
pint(dask(sparse)), how do we callto_denseand get apint(dask(numpy)), without havingdaskknow aboutsparse?
To solve this, at the moment pint will pass through attribute access for methods it doesn't know. This has a few issues: these methods will remove the nesting (which might sometimes be intended), and it is easy to shadow methods (e.g. a duck array might declare a magnitude method).
Instead, we could use type accessors: arr.sparse.to_dense() would convert a pint(dask(sparse)) array to pint(dask(numpy)) by calling self._data.sparse.to_dense() until the name is the name of the type / library. Deciding if the nesting was intentionally removed is pretty difficult, though: maybe only if the result is not a duck array?
This is very explicit, but it involves __getattr__ to be truly dynamic and might be shadowed by any of the duck array. So I guess to avoid the __getattr__ magic, and to minimize the attribute shadowing, we could use a method with a string parameter: arr.array_method("sparse").to_dense() (I'm sure we can come up with a better name).