Skip to content

changed shape argument for ndarray from int to tuple in ./core/strings/object_array.py #44352

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

Merged
merged 9 commits into from
Nov 16, 2021

Conversation

nickleus27
Copy link
Contributor

xref #37715

@jbrockmendel
Copy link
Member

pandas/core/strings/object_array.py:65: error: Argument "dtype" to "ndarray" has incompatible type "Union[ExtensionDtype, str, dtype[object_], dtype[Any], Type[object]]"; expected "Union[dtype[Any], None, type, _SupportsDType[dtype[Any]], str, Union[Tuple[Any, int], Tuple[Any, Union[SupportsIndex, Sequence[SupportsIndex]]], List[Any], _DTypeDict, Tuple[Any, Any]]]" [arg-type]

# error: Argument 1 to "ndarray" has incompatible type "int";
# expected "Sequence[int]"
return np.ndarray(0, dtype=dtype) # type: ignore[arg-type]
return np.ndarray((0,), dtype=dtype)
Copy link
Member

Choose a reason for hiding this comment

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

best guess is this is intended to use np.array, not np.ndarray

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbrockmendel Thank you! I am new to this and appreciate the help. So you think calling np.array with similar arguments is needed instead of np.ndarray?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbrockmendel also, I tried using pd.test() on my local machine and I didn't get this error message. Any advice on how to test before i push again?

Copy link
Member

Choose a reason for hiding this comment

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

it should probably be np.array([], dtype=dtype).

I tried using pd.test() on my local machine and I didn't get this error message. Any advice on how to test before i push again?

Are you referring to the 'Argument 1 to "ndarray" ...'? That would show up if you a) removed the "type: ignore[arg-type]" and then ran 'mypy pandas'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jbrockmendel awesome, thank you! I will try this out.

Copy link
Contributor Author

@nickleus27 nickleus27 Nov 8, 2021

Choose a reason for hiding this comment

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

@jbrockmendel I am having trouble figuring out how to address the type errors for argument dtype. The suggestion you made about np.array instead of np.ndarray didn't solve the problem. Should I close this pr if I cannot figure it out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am going to close this pull request for now. I am going to research the problem further, and come back to this once I have a good working solution. Thank you for helping me get started.

Copy link
Member

Choose a reason for hiding this comment

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

what went wrong with np.array([], dtype=dtype)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same type error as with the np.ndarray

Copy link
Member

Choose a reason for hiding this comment

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

looks like it is a similar error but now complaining about the dtype rather than the first arg

error: Argument "dtype" to "array" has incompatible type "Union[ExtensionDtype, str, dtype[object_], dtype[Any], Type[object]]"; expected "Union[dtype[Any], None, type, _SupportsDType[dtype[Any]], str, Union[Tuple[Any, int], Tuple[Any, Union[SupportsIndex, Sequence[SupportsIndex]]], List[Any], _DTypeDict, Tuple[Any, Any]]]"  [arg-type]

this might be fixed by changing the annotaiton for 'dtype' from Dtype | None to NpDtype | None; @simonjayhawkins may know more than me about the intention here.

@nickleus27 nickleus27 closed this Nov 8, 2021
@nickleus27 nickleus27 reopened this Nov 10, 2021
@nickleus27
Copy link
Contributor Author

@jbrockmendel How are you today? Do you think these changes could work?

@jbrockmendel
Copy link
Member

lgtm cc @simonjayhawkins

@jreback jreback added this to the 1.4 milestone Nov 16, 2021
@jreback jreback added the Typing type annotations, mypy/pyright type checking label Nov 16, 2021
@jreback jreback merged commit 700be61 into pandas-dev:master Nov 16, 2021
@jreback
Copy link
Contributor

jreback commented Nov 16, 2021

thanks @nickleus27

@nickleus27 nickleus27 deleted the nicks_typ_err branch January 5, 2022 18:42
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