Skip to content

Commit

Permalink
BUG: SparseDataFrame.icol return SparseSeries. SparseSeries.from_arra…
Browse files Browse the repository at this point in the history
…y return SparseSeries. close #2227, #2229
  • Loading branch information
wesm committed Nov 14, 2012
1 parent bd34795 commit a97b9b5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pandas 0.9.1
- Fix SparseSeries.__pow__ issue with NA input (#2220)
- Fix icol with integer sequence failure (#2228)
- Fixed resampling tz-aware time series issue (#2245)
- SparseDataFrame.icol was not returning SparseSeries (#2227, #2229)
pandas 0.9.0
============
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ class DataFrame(NDFrame):
_auto_consolidate = True
_verbose_info = True
_het_axis = 1
_col_klass = Series

_AXIS_NUMBERS = {
'index': 0,
Expand Down Expand Up @@ -1733,7 +1734,8 @@ def icol(self, i):
return self.ix[:, i]

values = self._data.iget(i)
return Series.from_array(values, index=self.index, name=label)
return self._col_klass.from_array(values, index=self.index,
name=label)

def _ixs(self, i, axis=0):
if axis == 0:
Expand Down
1 change: 1 addition & 0 deletions pandas/sparse/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class SparseDataFrame(DataFrame):
_columns = None
_series = None
_is_mixed_type = False
_col_klass = SparseSeries
ndim = 2

def __init__(self, data=None, index=None, columns=None,
Expand Down
7 changes: 7 additions & 0 deletions pandas/sparse/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ def __new__(cls, data, index=None, sparse_index=None, kind='block',
output.name = name
return output

@classmethod
def from_array(cls, arr, index=None, name=None, copy=False):
"""
Simplified alternate constructor
"""
return SparseSeries(arr, index=index, name=name, copy=copy)

def __init__(self, data, index=None, sparse_index=None, kind='block',
fill_value=None, name=None, copy=False):
"""Data structure for labeled, sparse floating point data
Expand Down
6 changes: 6 additions & 0 deletions pandas/sparse/tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,12 @@ def test_getitem(self):

self.assertRaises(Exception, sdf.__getitem__, ['a', 'd'])

def test_icol(self):
# #2227
result = self.frame.icol(0)
self.assertTrue(isinstance(result, SparseSeries))
assert_sp_series_equal(result, self.frame['A'])

def test_set_value(self):
res = self.frame.set_value('foobar', 'B', 1.5)
self.assert_(res is not self.frame)
Expand Down

0 comments on commit a97b9b5

Please sign in to comment.