From e26b1960cffbbfa8ccfa3d7d9fbf454d67cb8071 Mon Sep 17 00:00:00 2001 From: y-p Date: Wed, 14 Nov 2012 21:56:06 +0200 Subject: [PATCH 1/2] TST: icol() should propegate fill_value for sparse data frames --- pandas/tests/test_frame.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/tests/test_frame.py b/pandas/tests/test_frame.py index 7787a5c6e4fc7..2db2851bb6abc 100644 --- a/pandas/tests/test_frame.py +++ b/pandas/tests/test_frame.py @@ -1327,6 +1327,11 @@ def test_irow_icol_duplicates(self): xp = df.ix[:, [0]] assert_frame_equal(rs, xp) + def test_icol_sparse_propegate_fill_value(self): + from pandas.sparse.api import SparseDataFrame + df=SparseDataFrame({'A' : [999,1]},default_fill_value=999) + self.assertTrue( len(df['A'].sp_values) == len(df.icol(0).sp_values)) + def test_iget_value(self): for i, row in enumerate(self.frame.index): for j, col in enumerate(self.frame.columns): From e949f9cbfac3a85c1959e98060838b6605983f94 Mon Sep 17 00:00:00 2001 From: y-p Date: Wed, 14 Nov 2012 21:44:27 +0200 Subject: [PATCH 2/2] BUG: icol() should propegate fill_value for sparse data frames #2249 --- pandas/core/frame.py | 11 +++++++++-- pandas/sparse/series.py | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index d91be2d1f36c1..4b506a23f9fb2 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1734,8 +1734,15 @@ def icol(self, i): return self.ix[:, i] values = self._data.iget(i) - return self._col_klass.from_array(values, index=self.index, - name=label) + if hasattr(self,'default_fill_value'): + s = self._col_klass.from_array(values, index=self.index, + name=label, + fill_value= self.default_fill_value) + else: + s = self._col_klass.from_array(values, index=self.index, + name=label) + + return s def _ixs(self, i, axis=0): if axis == 0: diff --git a/pandas/sparse/series.py b/pandas/sparse/series.py index 9e4228d3ef25f..8be9e2b5c7d75 100644 --- a/pandas/sparse/series.py +++ b/pandas/sparse/series.py @@ -147,11 +147,11 @@ def __new__(cls, data, index=None, sparse_index=None, kind='block', return output @classmethod - def from_array(cls, arr, index=None, name=None, copy=False): + def from_array(cls, arr, index=None, name=None, copy=False,fill_value=None): """ Simplified alternate constructor """ - return SparseSeries(arr, index=index, name=name, copy=copy) + return SparseSeries(arr, index=index, name=name, copy=copy,fill_value=fill_value) def __init__(self, data, index=None, sparse_index=None, kind='block', fill_value=None, name=None, copy=False):