Skip to content

Commit d1c6912

Browse files
committed
BUG: Fix the element-wise mask generation method in make_spase
1 parent bff0ac0 commit d1c6912

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

pandas/core/sparse/array.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -791,13 +791,11 @@ def make_sparse(arr, kind='block', fill_value=None):
791791
arr = arr.astype(object)
792792

793793
if is_object_dtype(arr.dtype):
794-
mask = []
795-
for e in arr:
796-
if type(e) is type(fill_value):
797-
mask.append(e != fill_value)
798-
else:
799-
mask.append(True)
800-
mask = np.array(mask)
794+
mask = np.ones(len(arr), dtype=np.bool)
795+
fv_type = type(fill_value)
796+
797+
cond = np.fromiter((type(x) is fv_type for x in arr), dtype=np.bool)
798+
mask[cond] = arr[cond] != fill_value
801799
else:
802800
mask = arr != fill_value
803801

0 commit comments

Comments
 (0)