Skip to content

Commit

Permalink
BUG: Fix make_sparse mask generation not to cast when dtype is object
Browse files Browse the repository at this point in the history
  • Loading branch information
Licht-T committed Sep 18, 2017
1 parent cbb090f commit 7804303
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pandas/core/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from pandas.core.dtypes.common import (
_ensure_platform_int,
is_float, is_integer,
is_object_dtype,
is_integer_dtype,
is_bool_dtype,
is_list_like,
Expand Down Expand Up @@ -789,7 +790,16 @@ def make_sparse(arr, kind='block', fill_value=None):
if is_string_dtype(arr):
arr = arr.astype(object)

mask = arr != fill_value
if is_object_dtype(arr.dtype):
mask = []
for e in arr:
if type(e) is type(fill_value):
mask.append(e != fill_value)
else:
mask.append(True)
mask = np.array(mask)
else:
mask = arr != fill_value

length = len(arr)
if length != mask.size:
Expand Down

0 comments on commit 7804303

Please sign in to comment.