Skip to content

Commit

Permalink
sparse panel reindex unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed May 15, 2011
1 parent f5e5fa3 commit ff5653d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2008-2009 AQR Capital Management, LLC
Copyright (c) 2008-2011 AQR Capital Management, LLC
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
1 change: 1 addition & 0 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def conform(self, frame, axis='items'):
----------
frame : DataFrame
axis : {'items', 'major', 'minor'}
Axis the input corresponds to. E.g., if axis='major', then
the frame's columns would be items, and the index would be
values of the minor axis
Expand Down
17 changes: 12 additions & 5 deletions pandas/core/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,10 +751,6 @@ def stack_sparse_frame(frame):
# this is pretty fast
minor_labels = np.repeat(np.arange(len(frame.columns)), lengths)

# need to create
major_labels = np.empty(nobs, dtype=int)
stacked_values = np.empty(nobs, dtype=np.float64)

inds_to_concat = []
vals_to_concat = []
for _, series in frame.iteritems():
Expand Down Expand Up @@ -927,15 +923,26 @@ def __setstate__(self, state):

def copy(self):
"""
Make a (shallow) copy of the sparse panel
Returns
-------
copy : SparseWidePanel
"""
return SparseWidePanel(self._frames.copy(), items=self.items,
major_axis=self.major_axis,
minor_axis=self.minor_axis,
default_fill_value=self.default_fill_value,
default_kind=self.default_kind)

def to_long(self):
def to_long(self, filter_observations=True):
"""
Convert SparseWidePanel to (dense) LongPanel
Returns
-------
lp : LongPanel
"""
pass

def reindex(self, major=None, items=None, minor=None):
Expand Down
12 changes: 10 additions & 2 deletions pandas/core/tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,16 @@ def test_copy(self):
assert_sp_panel_equal(cop, self.panel)

def test_reindex(self):
def _compare_with_dense(wp, items, major, minor):
pass
def _compare_with_dense(swp, items, major, minor):
swp_re = swp.reindex(items=items, major=major,
minor=minor)
dwp_re = swp.to_dense().reindex(items=items, major=major,
minor=minor)
assert_panel_equal(swp_re.to_dense(), dwp_re)

_compare_with_dense(self.panel, self.panel.items[:2],
self.panel.major_axis[::2],
self.panel.minor_axis[::2])

def test_operators(self):
pass
Expand Down

0 comments on commit ff5653d

Please sign in to comment.