Skip to content

Commit d8c2b6e

Browse files
committed
fixup! ENH: Native conversion from/to scipy.sparse matrix to SparseDataFrame
1 parent a1a88ff commit d8c2b6e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Diff for: pandas/sparse/array.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
is_integer_dtype,
2121
is_bool_dtype,
2222
is_list_like,
23+
is_string_dtype,
2324
is_scalar, is_dtype_equal)
2425
from pandas.types.cast import (_possibly_convert_platform, _maybe_promote,
2526
_astype_nansafe, _find_common_type)
@@ -769,10 +770,13 @@ def make_sparse(arr, kind='block', fill_value=None):
769770
if isnull(fill_value):
770771
mask = notnull(arr)
771772
else:
772-
mask = np.not_equal(arr, fill_value)
773-
# In NumPy 1.12.0, not implemented at least for arr.dtype=str
774-
if mask is NotImplemented:
775-
mask = np.not_equal(arr.astype(object), fill_value)
773+
# For str arrays in NumPy 1.12.0, operator!= below isn't
774+
# element-wise but just returns False if fill_value is not str,
775+
# so cast to object comparison to be safe
776+
if is_string_dtype(arr):
777+
arr = arr.astype(object)
778+
779+
mask = arr != fill_value
776780

777781
length = len(arr)
778782
if length != mask.size:

0 commit comments

Comments
 (0)