Skip to content

calling methods on wrapped duck arrays #6636

@keewis

Description

@keewis

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 call to_dense and get a pint(dask(numpy)), without having dask know about sparse?

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    arraydiscussionDiscussing a topic with no specific actions yetneeds attentionIt's been a while since this was pushed on. Needs attention from the owner or a maintainer.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions