@@ -124,22 +124,20 @@ def _from_sequence(
124
124
# None]"; expected "Union[dtype[Any], None, type, _SupportsDType, str,
125
125
# Union[Tuple[Any, int], Tuple[Any, Union[int, Sequence[int]]], List[Any],
126
126
# _DTypeDict, Tuple[Any, Any]]]"
127
- if ( None not in scalars ) :
127
+ if None not in scalars :
128
128
result = np .asarray (scalars , dtype = dtype )
129
129
else :
130
130
try :
131
- scalars_not_none = [item for item in scalars if item is not None ]
132
- except :
133
- raise ValueError ("NumpyExtensionArray must be 1-dimensional" )
134
- indexes_not_none = []
135
- indexed_data = [None ]* len (scalars )
136
- scalars_not_none_casted = np .asarray (scalars_not_none , dtype = dtype )
137
- for i in range (len (scalars )):
138
- if scalars [i ] is not None :
139
- indexes_not_none .append (i )
131
+ scalars_not_none = [item for item in scalars if item is not None ]
132
+ except Exception as err :
133
+ raise ValueError ("NumpyExtensionArray must be 1-dimensional" ) from err
134
+ indexes_not_none = []
135
+ indexed_data = [None ] * len (scalars )
136
+ scalars_not_none_casted = np .asarray (scalars_not_none , dtype = dtype )
137
+ indexes_not_none = [i for i , item in enumerate (scalars ) if item is not None ]
140
138
for i in range (len (scalars_not_none )):
141
- indexed_data [indexes_not_none [i ]]= scalars_not_none_casted [i ]
142
- result = np .asarray (indexed_data , dtype = "object" )
139
+ indexed_data [indexes_not_none [i ]] = scalars_not_none_casted [i ]
140
+ result = np .asarray (indexed_data , dtype = "object" )
143
141
if (
144
142
result .ndim > 1
145
143
and not hasattr (scalars , "dtype" )
0 commit comments