@@ -452,7 +452,7 @@ def __new__(
452
452
elif hasattr (data , "__array__" ):
453
453
return Index (np .asarray (data ), dtype = dtype , copy = copy , name = name , ** kwargs )
454
454
elif data is None or is_scalar (data ):
455
- cls ._scalar_data_error (data )
455
+ raise cls ._scalar_data_error (data )
456
456
else :
457
457
if tupleize_cols and is_list_like (data ):
458
458
# GH21470: convert iterable to list before determining if empty
@@ -4020,7 +4020,9 @@ def _try_convert_to_int_index(cls, data, copy, name, dtype):
4020
4020
4021
4021
@classmethod
4022
4022
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 (
4024
4026
"{0}(...) must be called with a collection of some "
4025
4027
"kind, {1} was passed" .format (cls .__name__ , repr (data ))
4026
4028
)
@@ -4048,7 +4050,7 @@ def _coerce_to_ndarray(cls, data):
4048
4050
4049
4051
if not isinstance (data , (np .ndarray , Index )):
4050
4052
if data is None or is_scalar (data ):
4051
- cls ._scalar_data_error (data )
4053
+ raise cls ._scalar_data_error (data )
4052
4054
4053
4055
# other iterable of some kind
4054
4056
if not isinstance (data , (ABCSeries , list , tuple )):
0 commit comments