FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

ENH: Static typing support for custom array containers · Issue #21737 · numpy/numpy · GitHub

/ numpy Public

ENH: Static typing support for custom array containers #21737

Description

Proposed new feature or change:

It would be nice to have static typing support for custom array containers like pandas Series, xarrays DataArray (pydata/xarray#6524) etc.
Such that you can do:

import pandas as pd
import numpy as np

x = pd.Series([1, 2, 3])
y = np.exp(x)
reveal_type(y)  # Should be pd.Series but is np.ndarray

I assume this should be possible using Protocols and using something like this:

from typing import Protocol, TypeVar

class HasArrayUFunc(Protocol):
    def __array_ufunc__(ufunc, method, *inputs, **kwargs):
        pass

ArrayOrHasArrayUFunc = TypeVar("ArrayOrHasArrayUFunc", ndarray, HasArrayUFunc)

def exp(x: ArrayOrHasArrayUFunc) -> ArrayOrHasArrayUFunc: ...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL