Skip to content

REF: raise scalar_data_error to make mypy happy #28484

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 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
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/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def __new__(
elif hasattr(data, "__array__"):
return Index(np.asarray(data), dtype=dtype, copy=copy, name=name, **kwargs)
elif data is None or is_scalar(data):
cls._scalar_data_error(data)
raise cls._scalar_data_error(data)
else:
if tupleize_cols and is_list_like(data):
# GH21470: convert iterable to list before determining if empty
Expand Down Expand Up @@ -4020,7 +4020,9 @@ def _try_convert_to_int_index(cls, data, copy, name, dtype):

@classmethod
def _scalar_data_error(cls, data):
raise TypeError(
# We return the TypeError so that we can raise it from the constructor
# in order to keep mypy happy
return TypeError(
"{0}(...) must be called with a collection of some "
"kind, {1} was passed".format(cls.__name__, repr(data))
)
Expand Down Expand Up @@ -4048,7 +4050,7 @@ def _coerce_to_ndarray(cls, data):

if not isinstance(data, (np.ndarray, Index)):
if data is None or is_scalar(data):
cls._scalar_data_error(data)
raise cls._scalar_data_error(data)

# other iterable of some kind
if not isinstance(data, (ABCSeries, list, tuple)):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def __new__(
# if data is None, then categories must be provided
if is_scalar(data):
if data is not None or categories is None:
cls._scalar_data_error(data)
raise cls._scalar_data_error(data)
data = []

data = cls._create_categorical(data, dtype=dtype)
Expand Down