Skip to content

Commit 071e950

Browse files
jbrockmendelproost
authored andcommitted
REF: raise scalar_data_error to make mypy happy (pandas-dev#28484)
1 parent af46268 commit 071e950

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

pandas/core/indexes/base.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def __new__(
452452
elif hasattr(data, "__array__"):
453453
return Index(np.asarray(data), dtype=dtype, copy=copy, name=name, **kwargs)
454454
elif data is None or is_scalar(data):
455-
cls._scalar_data_error(data)
455+
raise cls._scalar_data_error(data)
456456
else:
457457
if tupleize_cols and is_list_like(data):
458458
# GH21470: convert iterable to list before determining if empty
@@ -4020,7 +4020,9 @@ def _try_convert_to_int_index(cls, data, copy, name, dtype):
40204020

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

40494051
if not isinstance(data, (np.ndarray, Index)):
40504052
if data is None or is_scalar(data):
4051-
cls._scalar_data_error(data)
4053+
raise cls._scalar_data_error(data)
40524054

40534055
# other iterable of some kind
40544056
if not isinstance(data, (ABCSeries, list, tuple)):

pandas/core/indexes/category.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def __new__(
194194
# if data is None, then categories must be provided
195195
if is_scalar(data):
196196
if data is not None or categories is None:
197-
cls._scalar_data_error(data)
197+
raise cls._scalar_data_error(data)
198198
data = []
199199

200200
data = cls._create_categorical(data, dtype=dtype)

0 commit comments

Comments
 (0)