Skip to content

Commit 4473e57

Browse files
committed
BUG: Create SparseBlock.__init__ to set type information of SparseArray
1 parent f14bbeb commit 4473e57

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

pandas/core/internals.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2632,10 +2632,34 @@ class SparseBlock(NonConsolidatableMixIn, Block):
26322632
is_sparse = True
26332633
is_numeric = True
26342634
_box_to_block_values = False
2635-
_can_hold_na = True
26362635
_ftype = 'sparse'
26372636
_holder = SparseArray
26382637

2638+
def __init__(self, values, placement, ndim=None, fastpath=False, **kwargs):
2639+
super(SparseBlock, self).__init__(values, placement,
2640+
ndim, fastpath,
2641+
**kwargs)
2642+
2643+
dtype = self.values.sp_values.dtype
2644+
2645+
if is_float_dtype(dtype):
2646+
self.is_float = True
2647+
self._can_hold_na = True
2648+
elif is_complex_dtype(dtype):
2649+
self.is_complex = True
2650+
self._can_hold_na = True
2651+
elif is_integer_dtype(dtype):
2652+
self.is_integer = True
2653+
self._can_hold_na = False
2654+
elif is_bool_dtype(dtype):
2655+
self.is_bool = True
2656+
self._can_hold_na = False
2657+
elif is_object_dtype(dtype):
2658+
self.is_object = True
2659+
self._can_hold_na = True
2660+
else:
2661+
self._can_hold_na = False
2662+
26392663
def coerce_to_target_dtype(self, other, copy=True):
26402664
return super(SparseBlock, self).coerce_to_target_dtype(other, copy)
26412665

0 commit comments

Comments
 (0)