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 #36098

Merged
merged 3 commits into from
Sep 5, 2020
Merged

Conversation

simonjayhawkins
Copy link
Member

pandas/core/dtypes/cast.py:1491: error: Incompatible return value type (got "Type[object]", expected "Union[dtype, ExtensionDtype]")  [return-value]
pandas/core/dtypes/cast.py:1553: error: Incompatible types in assignment (expression has type "Type[object]", variable has type "Union[dtype, ExtensionDtype]")  [assignment]
pandas/core/construction.py:601: error: Incompatible default for argument "dtype_if_empty" (default has type "Type[object]", argument has type "Union[ExtensionDtype, str, dtype, Type[str], Type[float], Type[int], Type[complex], Type[bool]]")  [assignment]
pandas/core/generic.py:6217: error: Argument "dtype_if_empty" to "create_series_with_explicit_dtype" has incompatible type "Type[object]"; expected "Union[ExtensionDtype, str, dtype, Type[str], Type[float], Type[int], Type[complex], Type[bool]]"  [arg-type]
pandas/tests/arrays/sparse/test_dtype.py:97: error: Argument 1 to "SparseDtype" has incompatible type "Type[object]"; expected "Union[ExtensionDtype, str, dtype, Type[str], Type[float], Type[int], Type[complex], Type[bool]]"  [arg-type]
pandas/tests/arrays/sparse/test_dtype.py:172: error: Argument 1 to "SparseDtype" has incompatible type "Type[object]"; expected "Union[ExtensionDtype, str, dtype, Type[str], Type[float], Type[int], Type[complex], Type[bool]]"  [arg-type]
pandas/tests/arrays/sparse/test_combine_concat.py:44: error: Argument 1 to "SparseDtype" has incompatible type "Type[object]"; expected "Union[ExtensionDtype, str, dtype, Type[str], Type[float], Type[int], Type[complex], Type[bool]]"  [arg-type]
pandas/tests/arrays/sparse/test_array.py:561: error: Argument 1 to "SparseDtype" has incompatible type "Type[object]"; expected "Union[ExtensionDtype, str, dtype, Type[str], Type[float], Type[int], Type[complex], Type[bool]]"  [arg-type]

@simonjayhawkins simonjayhawkins added the Typing type annotations, mypy/pyright type checking label Sep 3, 2020
@@ -383,7 +383,9 @@ def extract_array(obj, extract_numpy: bool = False):
if extract_numpy and isinstance(obj, ABCPandasArray):
obj = obj.to_numpy()

return obj
# error: Incompatible return value type (got "Index", expected "ExtensionArray")
# error: Incompatible return value type (got "Series", expected "ExtensionArray")
Copy link
Member

Choose a reason for hiding this comment

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

Could we avoid this by assigning to a new name before returning?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll look some more, but we are using ABC types here which always create issues with eliminating types so I just added the ignore for now so that the return types can be added.

@@ -62,7 +62,7 @@
# other

Dtype = Union[
"ExtensionDtype", str, np.dtype, Type[Union[str, float, int, complex, bool]]
"ExtensionDtype", str, np.dtype, Type[Union[str, float, int, complex, bool, object]]
Copy link
Member

Choose a reason for hiding this comment

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

object here is for when we use object as a shorthand for np.dtype(object)?

Copy link
Member Author

Choose a reason for hiding this comment

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

yep, but Dtype is also used to type the public facing api. ideally we don't want object here, but we don't want users to have false positives either. saying that we have not yet come to an agreement on how we will make the types public. see #28142

@@ -2316,7 +2316,7 @@ def _concat_same_type(self, to_concat):

return union_categoricals(to_concat)

def isin(self, values):
def isin(self, values) -> 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.

so here we know that this returns a bool dtyped ndarray, is it worth somehow annotating this as such?

Copy link
Member

Choose a reason for hiding this comment

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

IIRC there has been some discussion in numpy about making it viable to annotate something like np.ndarray[bool], but it is still hypothetical (cc @shoyer?)

@jreback jreback added this to the 1.2 milestone Sep 4, 2020
@jreback
Copy link
Contributor

jreback commented Sep 4, 2020

@jbrockmendel good here?

@jbrockmendel
Copy link
Member

all good

@jreback jreback merged commit cab3e0e into pandas-dev:master Sep 5, 2020
@simonjayhawkins simonjayhawkins deleted the np-types branch September 5, 2020 07:31
jbrockmendel pushed a commit to jbrockmendel/pandas that referenced this pull request Sep 8, 2020
kesmit13 pushed a commit to kesmit13/pandas that referenced this pull request Nov 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.

3 participants