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
4 changes: 1 addition & 3 deletions pandas/core/strings/object_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ def _str_map(
na_value = self._str_na_value

if not len(self):
# 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.


arr = np.asarray(self, dtype=object)
mask = isna(arr)
Expand Down