Skip to content

Commit 9a81dab

Browse files
committed
added docs for Panel4D/panelnd
updated whatsnew/RELEASE removed old variable in panel creation (was for a previous version) all tests pass
1 parent 16becb0 commit 9a81dab

File tree

4 files changed

+138
-1
lines changed

4 files changed

+138
-1
lines changed

RELEASE.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ pandas 0.10.0
4343
`describe_option`, and `reset_option`. Deprecate `get_printoptions`,
4444
`set_printoptions`, and `reset_printoptions` (#2393)
4545

46+
**Experimental Features**
47+
- Add support for Panel4D, a named 4 Dimensional stucture
48+
- Add support for ndpanel factory functions, to create custom, domain-specific
49+
N Dimensional containers
50+
4651
**API Changes**
4752

4853
- inf/-inf are no longer considered as NA by isnull/notnull. To be cler, this

doc/source/dsintro.rst

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,3 +798,119 @@ method:
798798
major_axis=date_range('1/1/2000', periods=5),
799799
minor_axis=['a', 'b', 'c', 'd'])
800800
panel.to_frame()
801+
802+
Panel4D (Experimental)
803+
----------------------
804+
805+
``Panel4D`` is a 4-Dimensional named container very much like a ``Panel``, but
806+
having 4 named dimensions. It is intended as a test bed for more N-Dimensional named
807+
containers.
808+
809+
- **labels**: axis 0, each item corresponds to a Panel contained inside
810+
- **items**: axis 1, each item corresponds to a DataFrame contained inside
811+
- **major_axis**: axis 2, it is the **index** (rows) of each of the
812+
DataFrames
813+
- **minor_axis**: axis 3, it is the **columns** of each of the DataFrames
814+
815+
816+
``Panel4D`` is a sub-class of ``Panel``, so most methods that work on Panels are
817+
applicable to Panel4D.
818+
819+
Construction of Panel4D works in a very similar manner to a ``Panel``
820+
821+
From 4D ndarray with optional axis labels
822+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
823+
824+
.. ipython:: python
825+
826+
p4d = Panel4D(randn(2, 2, 5, 4),
827+
labels=['Label1','Label2'],
828+
items=['Item1', 'Item2'],
829+
major_axis=date_range('1/1/2000', periods=5),
830+
minor_axis=['A', 'B', 'C', 'D'])
831+
p4d
832+
833+
834+
From dict of Panel objects
835+
~~~~~~~~~~~~~~~~~~~~~~~~~~
836+
837+
.. ipython:: python
838+
839+
data = { 'Label1' : Panel({ 'Item1' : DataFrame(randn(4, 3)) }),
840+
'Label2' : Panel({ 'Item2' : DataFrame(randn(4, 2)) }) }
841+
Panel4D(data)
842+
843+
Note that the values in the dict need only be **convertible to Panels**.
844+
Thus, they can be any of the other valid inputs to Panel as per above.
845+
846+
Slicing
847+
~~~~~~~
848+
849+
Slicing works in a similar manner to a Panel. ``[]`` slices the first dimension.
850+
``.ix`` allows you to slice abitrarily and get back lower dimensional objects
851+
852+
.. ipython:: python
853+
854+
p4d['Label1']
855+
856+
4D -> Panel
857+
858+
.. ipython:: python
859+
860+
p4d.ix[:,:,:,'A']
861+
862+
4D -> DataFrame
863+
864+
.. ipython:: python
865+
866+
p4d.ix[:,:,0,'A']
867+
868+
4D -> Series
869+
870+
.. ipython:: python
871+
872+
p4d.ix[:,0,0,'A']
873+
874+
Transposing
875+
~~~~~~~~~~~
876+
877+
A Panel4D can be rearranged using its ``transpose`` method (which does not make a
878+
copy by default unless the data are heterogeneous):
879+
880+
.. ipython:: python
881+
882+
p4d.transpose(3, 2, 1, 0)
883+
884+
PanelND (Experimental)
885+
----------------------
886+
887+
PanelND is a module with a set of factory functions to enable a user to construct N-dimensional named
888+
containers like Panel4D, with a custom set of axis labels. Thus a domain-specific container can easily be
889+
created.
890+
891+
The following creates a Panel5D. A new panel type object must be sliceable into a lower dimensional object.
892+
Here we slice to a Panel4D.
893+
894+
.. ipython:: python
895+
896+
from pandas.core import panelnd
897+
Panel5D = panelnd.create_nd_panel_factory(
898+
klass_name = 'Panel5D',
899+
axis_orders = [ 'cool', 'labels','items','major_axis','minor_axis'],
900+
axis_slices = { 'labels' : 'labels', 'items' : 'items', 'major_axis' : 'major_axis', 'minor_axis' : 'minor_axis' },
901+
slicer = Panel4D,
902+
axis_aliases = { 'major' : 'major_axis', 'minor' : 'minor_axis' },
903+
stat_axis = 2)
904+
905+
p5d = Panel5D(dict(C1 = p4d))
906+
p5d
907+
908+
# print a slice of our 5D
909+
p5d.ix['C1',:,:,0:3,:]
910+
911+
# transpose it
912+
p5d.transpose(1,2,3,4,0)
913+
914+
# look at the values & dim
915+
p5d.values.shape
916+
p5d.values.ndim

doc/source/v0.10.0.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ Updated PyTables Support
110110
import os
111111
os.remove('store.h5')
112112

113+
NDim Panels (Experimental)
114+
~~~~~~~~~~~~~~~~~~~~~~~~~~
115+
116+
Adding experimental support for Panel4D and factory functions to create n-dimensional named panels.
117+
:ref:`Docs <dsintro-panel4d>` for NDim. Here is a taste of what to expect.
118+
119+
.. ipython:: python
120+
121+
p4d = Panel4D(randn(2, 2, 5, 4),
122+
labels=['Label1','Label2'],
123+
items=['Item1', 'Item2'],
124+
major_axis=date_range('1/1/2000', periods=5),
125+
minor_axis=['A', 'B', 'C', 'D'])
126+
p4d
127+
128+
129+
113130
API changes
114131
~~~~~~~~~~~
115132

pandas/core/panel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ def _init_dict(self, data, axes, dtype=None):
280280

281281
# shallow copy
282282
arrays = []
283-
reshaped_data = data.copy()
284283
haxis_shape = [ len(a) for a in raxes ]
285284
for h in haxis:
286285
v = values = data.get(h)

0 commit comments

Comments
 (0)