Skip to content

Commit d738b64

Browse files
committed
STY: CRLF
1 parent 6d18781 commit d738b64

File tree

2 files changed

+156
-156
lines changed

2 files changed

+156
-156
lines changed

pandas/core/panel4d.py

+40-40
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
""" Panel4D: a 4-d dict like collection of panels """
2-
3-
from pandas.core.panelnd import create_nd_panel_factory
4-
from pandas.core.panel import Panel
5-
6-
Panel4D = create_nd_panel_factory(
7-
klass_name='Panel4D',
8-
axis_orders=['labels', 'items', 'major_axis', 'minor_axis'],
9-
axis_slices={'labels': 'labels', 'items': 'items',
10-
'major_axis': 'major_axis',
11-
'minor_axis': 'minor_axis'},
12-
slicer=Panel,
13-
axis_aliases={'major': 'major_axis', 'minor': 'minor_axis'},
14-
stat_axis=2)
15-
16-
17-
def panel4d_init(self, data=None, labels=None, items=None, major_axis=None,
18-
minor_axis=None, copy=False, dtype=None):
19-
"""
20-
Represents a 4 dimensonal structured
21-
22-
Parameters
23-
----------
24-
data : ndarray (labels x items x major x minor), or dict of Panels
25-
26-
labels : Index or array-like : axis=0
27-
items : Index or array-like : axis=1
28-
major_axis : Index or array-like: axis=2
29-
minor_axis : Index or array-like: axis=3
30-
31-
dtype : dtype, default None
32-
Data type to force, otherwise infer
33-
copy : boolean, default False
34-
Copy data from inputs. Only affects DataFrame / 2d ndarray input
35-
"""
36-
self._init_data(data=data, labels=labels, items=items,
37-
major_axis=major_axis, minor_axis=minor_axis,
38-
copy=copy, dtype=dtype)
39-
40-
Panel4D.__init__ = panel4d_init
1+
""" Panel4D: a 4-d dict like collection of panels """
2+
3+
from pandas.core.panelnd import create_nd_panel_factory
4+
from pandas.core.panel import Panel
5+
6+
Panel4D = create_nd_panel_factory(
7+
klass_name='Panel4D',
8+
axis_orders=['labels', 'items', 'major_axis', 'minor_axis'],
9+
axis_slices={'labels': 'labels', 'items': 'items',
10+
'major_axis': 'major_axis',
11+
'minor_axis': 'minor_axis'},
12+
slicer=Panel,
13+
axis_aliases={'major': 'major_axis', 'minor': 'minor_axis'},
14+
stat_axis=2)
15+
16+
17+
def panel4d_init(self, data=None, labels=None, items=None, major_axis=None,
18+
minor_axis=None, copy=False, dtype=None):
19+
"""
20+
Represents a 4 dimensonal structured
21+
22+
Parameters
23+
----------
24+
data : ndarray (labels x items x major x minor), or dict of Panels
25+
26+
labels : Index or array-like : axis=0
27+
items : Index or array-like : axis=1
28+
major_axis : Index or array-like: axis=2
29+
minor_axis : Index or array-like: axis=3
30+
31+
dtype : dtype, default None
32+
Data type to force, otherwise infer
33+
copy : boolean, default False
34+
Copy data from inputs. Only affects DataFrame / 2d ndarray input
35+
"""
36+
self._init_data(data=data, labels=labels, items=items,
37+
major_axis=major_axis, minor_axis=minor_axis,
38+
copy=copy, dtype=dtype)
39+
40+
Panel4D.__init__ = panel4d_init

pandas/core/panelnd.py

+116-116
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,116 @@
1-
""" Factory methods to create N-D panels """
2-
3-
import pandas.lib as lib
4-
5-
6-
def create_nd_panel_factory(klass_name, axis_orders, axis_slices, slicer, axis_aliases=None, stat_axis=2):
7-
""" manufacture a n-d class:
8-
9-
parameters
10-
----------
11-
klass_name : the klass name
12-
axis_orders : the names of the axes in order (highest to lowest)
13-
axis_slices : a dictionary that defines how the axes map to the sliced axis
14-
slicer : the class representing a slice of this panel
15-
axis_aliases: a dictionary defining aliases for various axes
16-
default = { major : major_axis, minor : minor_axis }
17-
stat_axis : the default statistic axis
18-
default = 2
19-
het_axis : the info axis
20-
21-
22-
returns
23-
-------
24-
a class object reprsenting this panel
25-
26-
27-
"""
28-
29-
# if slicer is a name, get the object
30-
if isinstance(slicer, basestring):
31-
import pandas
32-
try:
33-
slicer = getattr(pandas, slicer)
34-
except:
35-
raise Exception("cannot create this slicer [%s]" % slicer)
36-
37-
# build the klass
38-
klass = type(klass_name, (slicer,), {})
39-
40-
# add the class variables
41-
klass._AXIS_ORDERS = axis_orders
42-
klass._AXIS_NUMBERS = dict([(a, i) for i, a in enumerate(axis_orders)])
43-
klass._AXIS_ALIASES = axis_aliases or dict()
44-
klass._AXIS_NAMES = dict([(i, a) for i, a in enumerate(axis_orders)])
45-
klass._AXIS_SLICEMAP = axis_slices
46-
klass._AXIS_LEN = len(axis_orders)
47-
klass._default_stat_axis = stat_axis
48-
klass._het_axis = 0
49-
klass._info_axis = axis_orders[klass._het_axis]
50-
51-
klass._constructor_sliced = slicer
52-
53-
# add the axes
54-
for i, a in enumerate(axis_orders):
55-
setattr(klass, a, lib.AxisProperty(i))
56-
57-
#### define the methods ####
58-
def __init__(self, *args, **kwargs):
59-
if not (kwargs.get('data') or len(args)):
60-
raise Exception(
61-
"must supply at least a data argument to [%s]" % klass_name)
62-
if 'copy' not in kwargs:
63-
kwargs['copy'] = False
64-
if 'dtype' not in kwargs:
65-
kwargs['dtype'] = None
66-
self._init_data(*args, **kwargs)
67-
klass.__init__ = __init__
68-
69-
def _get_plane_axes(self, axis):
70-
71-
axis = self._get_axis_name(axis)
72-
index = self._AXIS_ORDERS.index(axis)
73-
74-
planes = []
75-
if index:
76-
planes.extend(self._AXIS_ORDERS[0:index])
77-
if index != self._AXIS_LEN:
78-
planes.extend(self._AXIS_ORDERS[index + 1:])
79-
80-
return [getattr(self, p) for p in planes]
81-
klass._get_plane_axes = _get_plane_axes
82-
83-
def _combine(self, other, func, axis=0):
84-
if isinstance(other, klass):
85-
return self._combine_with_constructor(other, func)
86-
return super(klass, self)._combine(other, func, axis=axis)
87-
klass._combine = _combine
88-
89-
def _combine_with_constructor(self, other, func):
90-
91-
# combine labels to form new axes
92-
new_axes = []
93-
for a in self._AXIS_ORDERS:
94-
new_axes.append(getattr(self, a) + getattr(other, a))
95-
96-
# reindex: could check that everything's the same size, but forget it
97-
d = dict([(a, ax) for a, ax in zip(self._AXIS_ORDERS, new_axes)])
98-
d['copy'] = False
99-
this = self.reindex(**d)
100-
other = other.reindex(**d)
101-
102-
result_values = func(this.values, other.values)
103-
104-
return self._constructor(result_values, **d)
105-
klass._combine_with_constructor = _combine_with_constructor
106-
107-
# set as NonImplemented operations which we don't support
108-
for f in ['to_frame', 'to_excel', 'to_sparse', 'groupby', 'join', 'filter', 'dropna', 'shift', 'take']:
109-
def func(self, *args, **kwargs):
110-
raise NotImplementedError
111-
setattr(klass, f, func)
112-
113-
# add the aggregate operations
114-
klass._add_aggregate_operations()
115-
116-
return klass
1+
""" Factory methods to create N-D panels """
2+
3+
import pandas.lib as lib
4+
5+
6+
def create_nd_panel_factory(klass_name, axis_orders, axis_slices, slicer, axis_aliases=None, stat_axis=2):
7+
""" manufacture a n-d class:
8+
9+
parameters
10+
----------
11+
klass_name : the klass name
12+
axis_orders : the names of the axes in order (highest to lowest)
13+
axis_slices : a dictionary that defines how the axes map to the sliced axis
14+
slicer : the class representing a slice of this panel
15+
axis_aliases: a dictionary defining aliases for various axes
16+
default = { major : major_axis, minor : minor_axis }
17+
stat_axis : the default statistic axis
18+
default = 2
19+
het_axis : the info axis
20+
21+
22+
returns
23+
-------
24+
a class object reprsenting this panel
25+
26+
27+
"""
28+
29+
# if slicer is a name, get the object
30+
if isinstance(slicer, basestring):
31+
import pandas
32+
try:
33+
slicer = getattr(pandas, slicer)
34+
except:
35+
raise Exception("cannot create this slicer [%s]" % slicer)
36+
37+
# build the klass
38+
klass = type(klass_name, (slicer,), {})
39+
40+
# add the class variables
41+
klass._AXIS_ORDERS = axis_orders
42+
klass._AXIS_NUMBERS = dict([(a, i) for i, a in enumerate(axis_orders)])
43+
klass._AXIS_ALIASES = axis_aliases or dict()
44+
klass._AXIS_NAMES = dict([(i, a) for i, a in enumerate(axis_orders)])
45+
klass._AXIS_SLICEMAP = axis_slices
46+
klass._AXIS_LEN = len(axis_orders)
47+
klass._default_stat_axis = stat_axis
48+
klass._het_axis = 0
49+
klass._info_axis = axis_orders[klass._het_axis]
50+
51+
klass._constructor_sliced = slicer
52+
53+
# add the axes
54+
for i, a in enumerate(axis_orders):
55+
setattr(klass, a, lib.AxisProperty(i))
56+
57+
#### define the methods ####
58+
def __init__(self, *args, **kwargs):
59+
if not (kwargs.get('data') or len(args)):
60+
raise Exception(
61+
"must supply at least a data argument to [%s]" % klass_name)
62+
if 'copy' not in kwargs:
63+
kwargs['copy'] = False
64+
if 'dtype' not in kwargs:
65+
kwargs['dtype'] = None
66+
self._init_data(*args, **kwargs)
67+
klass.__init__ = __init__
68+
69+
def _get_plane_axes(self, axis):
70+
71+
axis = self._get_axis_name(axis)
72+
index = self._AXIS_ORDERS.index(axis)
73+
74+
planes = []
75+
if index:
76+
planes.extend(self._AXIS_ORDERS[0:index])
77+
if index != self._AXIS_LEN:
78+
planes.extend(self._AXIS_ORDERS[index + 1:])
79+
80+
return [getattr(self, p) for p in planes]
81+
klass._get_plane_axes = _get_plane_axes
82+
83+
def _combine(self, other, func, axis=0):
84+
if isinstance(other, klass):
85+
return self._combine_with_constructor(other, func)
86+
return super(klass, self)._combine(other, func, axis=axis)
87+
klass._combine = _combine
88+
89+
def _combine_with_constructor(self, other, func):
90+
91+
# combine labels to form new axes
92+
new_axes = []
93+
for a in self._AXIS_ORDERS:
94+
new_axes.append(getattr(self, a) + getattr(other, a))
95+
96+
# reindex: could check that everything's the same size, but forget it
97+
d = dict([(a, ax) for a, ax in zip(self._AXIS_ORDERS, new_axes)])
98+
d['copy'] = False
99+
this = self.reindex(**d)
100+
other = other.reindex(**d)
101+
102+
result_values = func(this.values, other.values)
103+
104+
return self._constructor(result_values, **d)
105+
klass._combine_with_constructor = _combine_with_constructor
106+
107+
# set as NonImplemented operations which we don't support
108+
for f in ['to_frame', 'to_excel', 'to_sparse', 'groupby', 'join', 'filter', 'dropna', 'shift', 'take']:
109+
def func(self, *args, **kwargs):
110+
raise NotImplementedError
111+
setattr(klass, f, func)
112+
113+
# add the aggregate operations
114+
klass._add_aggregate_operations()
115+
116+
return klass

0 commit comments

Comments
 (0)