Skip to content

Commit e1d61b9

Browse files
committed
BUG: Set fill_value and ndim parameter in make_block when generating SparseBlock from result
1 parent 1076443 commit e1d61b9

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pandas/core/internals.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,11 @@ def where(self, other, cond, align=True, raise_on_error=True,
13881388
if hasattr(other, 'reindex_axis'):
13891389
other = other.values
13901390

1391+
if is_scalar(other) or is_list_like(other):
1392+
fill_value = other
1393+
else:
1394+
fill_value = None
1395+
13911396
if hasattr(cond, 'reindex_axis'):
13921397
cond = cond.values
13931398

@@ -1446,7 +1451,12 @@ def func(cond, values, other):
14461451
if try_cast:
14471452
result = self._try_cast_result(result)
14481453

1449-
return self.make_block(result)
1454+
if isinstance(result, np.ndarray):
1455+
ndim = result.ndim
1456+
else:
1457+
ndim = None
1458+
1459+
return self.make_block(result, ndim=ndim, fill_value=fill_value)
14501460

14511461
# might need to separate out blocks
14521462
axis = cond.ndim - 1

0 commit comments

Comments
 (0)