Skip to content

Conversation

jbrockmendel
Copy link
Member

@simonjayhawkins mypy doesn't like this

$ mypy pandas
pandas/core/base.py:679: error: "ArrayLike" has no attribute "nbytes"
pandas/core/indexes/base.py:246: error: Type variable "pandas._typing.ArrayLike" is unbound
pandas/core/indexes/base.py:246: note: (Hint: Use "Generic[ArrayLike]" or "Protocol[ArrayLike]" base class to bind "ArrayLike" inside a class)
pandas/core/indexes/base.py:246: note: (Hint: Use "ArrayLike" in function signature to bind "ArrayLike" inside a function)
pandas/core/indexes/base.py:1152: error: "ArrayLike" has no attribute "copy"
pandas/core/indexes/base.py:3881: error: ArrayLike? has no attribute "view"
pandas/core/series.py:252: error: "ArrayLike" has no attribute "copy"
pandas/io/pytables.py:2240: error: "ExtensionDtype" has no attribute "itemsize"
pandas/io/pytables.py:2245: error: "ExtensionArray" has no attribute "size"
pandas/io/pytables.py:2248: error: "ExtensionArray" has no attribute "codes"
pandas/io/pytables.py:4985: error: "ExtensionArray" has no attribute "codes"

Is this a product of ArrayLike being a TypeVar instead of a Union? At least the last two look like they need to be Categorical instead of ExtensionArray, not sure about the others.

@WillAyd
Copy link
Member

WillAyd commented Feb 1, 2020

pandas/core/indexes/base.py:246: error: Type variable "pandas._typing.ArrayLike" is unbound
pandas/core/indexes/base.py:246: note: (Hint: Use "Generic[ArrayLike]" or "Protocol[ArrayLike]" base class to bind "ArrayLike" inside a class)
pandas/core/indexes/base.py:246: note: (Hint: Use "ArrayLike" in function signature to bind "ArrayLike" inside a function)

@simonjayhawkins might know better but I don't think you can use a TypeVar for a class instance; the point of it is to make for generic functions and just assigned to a standalone variable that might not make sense

@WillAyd WillAyd added the Typing type annotations, mypy/pyright type checking label Feb 1, 2020
@jbrockmendel
Copy link
Member Author

so should we implement something else in pandas._typing for Union[np.ndarray, "ExtensionArray"]?

@jbrockmendel
Copy link
Member Author

closing to clear the queue

@jbrockmendel jbrockmendel deleted the arraylike branch February 1, 2020 16:44
@simonjayhawkins simonjayhawkins mentioned this pull request Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants