@@ -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 )):
0 commit comments