Skip to content

Commit

Permalink
ENH: set/get value working for sparse classes too, close #437
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Dec 6, 2011
1 parent d4c29ac commit a94710a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pandas/core/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,9 @@ def __getitem__(self, item):
else: # pragma: no cover
raise

def _get_item_cache(self, key):
return self[key]

def get_value(self, index, col):
s = self._series[col]
return s.get_value(index)
Expand Down Expand Up @@ -1506,9 +1509,7 @@ def _set_items(self, new_items):
# DataFrame's columns / "items"
minor_axis = SparsePanelAxis('_minor_axis', 'columns')

def __getitem__(self, key):
"""
"""
def _get_item_cache(self, key):
return self._frames[key]

def __setitem__(self, key, value):
Expand All @@ -1526,6 +1527,9 @@ def __setitem__(self, key, value):
if key not in self.items:
self._items = Index(list(self.items) + [key])

def set_value(self, item, row, column, value):
raise Exception('Sparse object scalar values are immutable')

def __delitem__(self, key):
loc = self.items.get_loc(key)
indices = range(loc) + range(loc + 1, len(self.items))
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ def test_select(self):
result = p.select(lambda x: x in ('foo',), axis='items')
self.assert_panel_equal(result, p.reindex(items=[]))

def test_get_value(self):
for item in self.panel.items:
for mjr in self.panel.major_axis[::2]:
for mnr in self.panel.minor_axis:
result = self.panel.get_value(item, mjr, mnr)
expected = self.panel[item][mnr][mjr]
assert_almost_equal(result, expected)

class CheckIndexing(object):


Expand Down

0 comments on commit a94710a

Please sign in to comment.