Skip to content

Commit

Permalink
hacking on HDFStore, incorporating submitted patches and optimizing
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Jun 22, 2011
1 parent 8715fb2 commit 8c94213
Show file tree
Hide file tree
Showing 4 changed files with 624 additions and 139 deletions.
22 changes: 12 additions & 10 deletions pandas/core/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2000,23 +2000,25 @@ def pivot(index, columns, values):
return DataFrame(index=[])

try:
major_axis = Index(sorted(set(index)))
minor_axis = Index(sorted(set(columns)))

major_labels, _ = tseries.getMergeVec(index, major_axis.indexMap)
minor_labels, _ = tseries.getMergeVec(columns, minor_axis.indexMap)

longIndex = _make_long_index(index, columns)
valueMat = values.view(np.ndarray).reshape(len(values), 1)

longIndex = LongPanelIndex(major_axis, minor_axis,
major_labels, minor_labels)

longPanel = LongPanel(valueMat, ['foo'], longIndex)
longPanel = longPanel.sort()
return longPanel.to_wide()['foo']
except PanelError:
return _slow_pivot(index, columns, values)

def _make_long_index(major_values, minor_values):
major_axis = Index(sorted(set(major_values)))
minor_axis = Index(sorted(set(minor_values)))

major_labels, _ = tseries.getMergeVec(major_values, major_axis.indexMap)
minor_labels, _ = tseries.getMergeVec(minor_values, minor_axis.indexMap)

long_index = LongPanelIndex(major_axis, minor_axis,
major_labels, minor_labels)
return long_index

def _slow_pivot(index, columns, values):
"""
Produce 'pivot' table based on 3 columns of this DataFrame.
Expand Down
Loading

0 comments on commit 8c94213

Please sign in to comment.