Skip to content

TYP: fix mypy error in pandas/core/common.py #39106

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,14 @@ def convert_to_list_like(
values: Union[Scalar, Iterable, AnyArrayLike]
) -> Union[List, AnyArrayLike]:
"""
Convert list-like or scalar input to list-like. List, numpy and pandas array-like
inputs are returned unmodified whereas others are converted to list.
Convert list-like or scalar input to list-like.

List, numpy and pandas array-like inputs are returned unmodified
whereas others are converted to list.
"""
if isinstance(values, (list, np.ndarray, ABCIndex, ABCSeries, ABCExtensionArray)):
# np.ndarray resolving as Any gives a false positive
return values # type: ignore[return-value]
return cast(Union[List, AnyArrayLike], values)
Copy link
Member

Choose a reason for hiding this comment

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

The comment above indicates that this ignore can be removed after we have numpy types. no need to add cast yet. While numpy types resolve to Any and np.ndarray is part of AnyArrayLike we may have false positives.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, thank you for the clarification.
So, probably this PR should be closed?

Copy link
Member

Choose a reason for hiding this comment

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

the changes to the docstring are ok, but I'll close this for now.

elif isinstance(values, abc.Iterable) and not isinstance(values, str):
return list(values)

Expand Down