Skip to content
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

TYP: misc fixes for numpy types 3 #36100

Closed

Conversation

simonjayhawkins
Copy link
Member

pandas\core\reshape\merge.py:1931: error: Incompatible types in assignment (expression has type "ndarray", variable has type "ExtensionArray")  [assignment]
pandas\core\reshape\merge.py:1932: error: Incompatible types in assignment (expression has type "ndarray", variable has type "ExtensionArray")  [assignment]
pandas\core\reshape\merge.py:1941: error: Incompatible types in assignment (expression has type "ndarray", variable has type "ExtensionArray")  [assignment]
pandas\core\reshape\merge.py:1950: error: Incompatible types in assignment (expression has type "ndarray", variable has type "ExtensionArray")  [assignment]
pandas\core\reshape\merge.py:1951: error: Incompatible types in assignment (expression has type "ndarray", variable has type "ExtensionArray")  [assignment]
pandas\io\pytables.py:5084: error: Incompatible types in assignment (expression has type "ndarray", variable has type "ExtensionArray")  [assignment]

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Sep 3, 2020
@@ -5076,7 +5076,7 @@ def _dtype_to_kind(dtype_str: str) -> str:
return kind


def _get_data_and_dtype_name(data: ArrayLike):
def _get_data_and_dtype_name(data: AnyArrayLikeUnion):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be better to ensure we unwrap to avoid Index/Series?

for my edification: i was under the impression that AnyArrayLike vs AnyArrayLikeUnion only mattered when we had more than one of them in a signature; i.e.

def foo(arg: AnyArrayLike) -> AnyArrayLike:

implies the return type matches the arg type, while using AnyArrayLikeUnion does not imply that. if that's correct, does it matter which we use in cases like this with only one annotation in the signature?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this case we change the type of data in the body. i.e assign to data and hence no preserving type of data.

I've used ..Union to be consistent with FrameOrSeries.

we could change ArrayLike and AnyArrayLike to be unions and ArrayLikeT and AnyArrayLikeT for type variables.

or we could assign to another variable name in the body (simpler, but imo messy and less clear)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im happy to follow your lead on this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WillAyd wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or we could assign to another variable name in the body (simpler, but imo messy and less clear)

I don't think worth going down this path. We will likely need a Union type for variable type annotations anyway, since if we use ArrayLike we would get error: Type variable "pandas._typing.ArrayLike" is unbound [valid-type]

@jreback jreback added this to the 1.2 milestone Sep 4, 2020
@@ -40,7 +40,9 @@
# array-like

AnyArrayLike = TypeVar("AnyArrayLike", "ExtensionArray", "Index", "Series", np.ndarray)
AnyArrayLikeUnion = Union["ExtensionArray", "Index", "Series", np.ndarray]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a comment on when you should use the AnyArryLike TypeVar and when the Union (for readers of this code!)

@jreback
Copy link
Contributor

jreback commented Sep 5, 2020

pls rebase

@simonjayhawkins
Copy link
Member Author

closing to clear queue. (also need a decision on naming)

@simonjayhawkins simonjayhawkins mentioned this pull request Sep 18, 2020
5 tasks
@simonjayhawkins simonjayhawkins mentioned this pull request Oct 12, 2020
5 tasks
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.

3 participants