Skip to content

Commit 2267a65

Browse files
y-pwesm
y-p
authored andcommitted
BUG: icol() should propegate fill_value for sparse data frames #2249
1 parent 2335d10 commit 2267a65

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

pandas/core/frame.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -1740,8 +1740,15 @@ def icol(self, i):
17401740
return self.ix[:, i]
17411741

17421742
values = self._data.iget(i)
1743-
return self._col_klass.from_array(values, index=self.index,
1744-
name=label)
1743+
if hasattr(self,'default_fill_value'):
1744+
s = self._col_klass.from_array(values, index=self.index,
1745+
name=label,
1746+
fill_value= self.default_fill_value)
1747+
else:
1748+
s = self._col_klass.from_array(values, index=self.index,
1749+
name=label)
1750+
1751+
return s
17451752

17461753
def _ixs(self, i, axis=0):
17471754
if axis == 0:

pandas/sparse/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,11 @@ def __new__(cls, data, index=None, sparse_index=None, kind='block',
147147
return output
148148

149149
@classmethod
150-
def from_array(cls, arr, index=None, name=None, copy=False):
150+
def from_array(cls, arr, index=None, name=None, copy=False,fill_value=None):
151151
"""
152152
Simplified alternate constructor
153153
"""
154-
return SparseSeries(arr, index=index, name=name, copy=copy)
154+
return SparseSeries(arr, index=index, name=name, copy=copy,fill_value=fill_value)
155155

156156
def __init__(self, data, index=None, sparse_index=None, kind='block',
157157
fill_value=None, name=None, copy=False):

0 commit comments

Comments
 (0)