Skip to content

Commit 6b374f9

Browse files
committed
fixed conversion to sparse for non-numeric index; todo: display of sparse
1 parent 504ad46 commit 6b374f9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pandas/sparse/array.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from pandas import compat, lib
1414
from pandas.compat import range
15+
from pandas.core.common import notnull
1516

1617
from pandas._sparse import SparseIndex, BlockIndex, IntIndex
1718
import pandas._sparse as splib
@@ -133,8 +134,6 @@ def __new__(cls, data, sparse_index=None, index=None, kind='integer',
133134
values.fill(data)
134135
data = values
135136

136-
if dtype is not None:
137-
dtype = np.dtype(dtype)
138137
is_sparse_array = isinstance(data, SparseArray)
139138
if fill_value is None:
140139
if is_sparse_array:
@@ -156,6 +155,9 @@ def __new__(cls, data, sparse_index=None, index=None, kind='integer',
156155
raise AssertionError("Non array-like type {0} must have"
157156
" the same length as the"
158157
" index".format(type(values)))
158+
if dtype is None:
159+
dtype = values.dtype
160+
dtype = np.dtype(dtype)
159161

160162
# Create array, do *not* copy data by default
161163
if copy:
@@ -544,7 +546,7 @@ def make_sparse(arr, kind='block', fill_value=nan):
544546
length = len(arr)
545547

546548
if np.isnan(fill_value):
547-
mask = ~np.isnan(arr)
549+
mask = notnull(arr)
548550
else:
549551
mask = arr != fill_value
550552

0 commit comments

Comments
 (0)