@@ -145,6 +145,7 @@ def f(self, other):
145
145
146
146
147
147
class Panel (NDFrame ):
148
+
148
149
"""
149
150
Represents wide format panel data, stored as 3-dimensional array
150
151
@@ -163,72 +164,9 @@ class Panel(NDFrame):
163
164
Copy data from inputs. Only affects DataFrame / 2d ndarray input
164
165
"""
165
166
166
- < << << << HEAD
167
- _AXIS_ORDERS = ['items' , 'major_axis' , 'minor_axis' ]
168
- _AXIS_NUMBERS = dict ((a , i ) for i , a in enumerate (_AXIS_ORDERS ))
169
- _AXIS_ALIASES = {
170
- 'major' : 'major_axis' ,
171
- 'minor' : 'minor_axis'
172
- }
173
- _AXIS_NAMES = dict (enumerate (_AXIS_ORDERS ))
174
- _AXIS_SLICEMAP = {
175
- 'major_axis' : 'index' ,
176
- 'minor_axis' : 'columns'
177
- }
178
- _AXIS_LEN = len (_AXIS_ORDERS )
179
-
180
- # major
181
- _default_stat_axis = 1
182
-
183
- # info axis
184
- _het_axis = 0
185
- _info_axis = _AXIS_ORDERS [_het_axis ]
186
-
187
- items = lib .AxisProperty (0 )
188
- major_axis = lib .AxisProperty (1 )
189
- minor_axis = lib .AxisProperty (2 )
190
-
191
- # return the type of the slice constructor
192
- _constructor_sliced = DataFrame
193
-
194
- def _construct_axes_dict (self , axes = None , ** kwargs ):
195
- """ Return an axes dictionary for myself """
196
- d = dict ([(a , getattr (self , a )) for a in (axes or self ._AXIS_ORDERS )])
197
- d .update (kwargs )
198
- return d
199
-
200
- @staticmethod
201
- def _construct_axes_dict_from (self , axes , ** kwargs ):
202
- """ Return an axes dictionary for the passed axes """
203
- d = dict ([(a , ax ) for a , ax in zip (self ._AXIS_ORDERS , axes )])
204
- d .update (kwargs )
205
- return d
206
-
207
- def _construct_axes_dict_for_slice (self , axes = None , ** kwargs ):
208
- """ Return an axes dictionary for myself """
209
- d = dict ([(self ._AXIS_SLICEMAP [a ], getattr (self , a ))
210
- for a in (axes or self ._AXIS_ORDERS )])
211
- d .update (kwargs )
212
- return d
213
-
214
- __add__ = _arith_method (operator .add , '__add__' )
215
- __sub__ = _arith_method (operator .sub , '__sub__' )
216
- __truediv__ = _arith_method (operator .truediv , '__truediv__' )
217
- __floordiv__ = _arith_method (operator .floordiv , '__floordiv__' )
218
- __mul__ = _arith_method (operator .mul , '__mul__' )
219
- __pow__ = _arith_method (operator .pow , '__pow__' )
220
-
221
- __radd__ = _arith_method (operator .add , '__radd__' )
222
- __rmul__ = _arith_method (operator .mul , '__rmul__' )
223
- __rsub__ = _arith_method (lambda x , y : y - x , '__rsub__' )
224
- __rtruediv__ = _arith_method (lambda x , y : y / x , '__rtruediv__' )
225
- __rfloordiv__ = _arith_method (lambda x , y : y // x , '__rfloordiv__' )
226
- __rpow__ = _arith_method (lambda x , y : y ** x , '__rpow__' )
227
- == == == =
228
167
@property
229
168
def _constructor (self ):
230
169
return type (self )
231
- >> >> >> > ENH / CLN : refactor of common code from frame / panel to generic .py
232
170
233
171
_constructor_sliced = DataFrame
234
172
@@ -267,12 +205,7 @@ def _init_data(self, data, copy, dtype, **kwargs):
267
205
NDFrame .__init__ (self , mgr , axes = axes , copy = copy , dtype = dtype )
268
206
269
207
def _init_dict (self , data , axes , dtype = None ):
270
- < << << << HEAD
271
- haxis = axes .pop (self ._het_axis )
272
- == == == =
273
- from pandas .util .compat import OrderedDict
274
208
haxis = axes .pop (self ._info_axis_number )
275
- >> >> >> > ENH / CLN : refactor of common code from frame / panel to generic .py
276
209
277
210
# prefilter if haxis passed
278
211
if haxis is not None :
@@ -281,7 +214,7 @@ def _init_dict(self, data, axes, dtype=None):
281
214
in compat .iteritems (data ) if k in haxis )
282
215
else :
283
216
ks = list (data .keys ())
284
- if not isinstance (data ,OrderedDict ):
217
+ if not isinstance (data , OrderedDict ):
285
218
ks = _try_sort (ks )
286
219
haxis = Index (ks )
287
220
@@ -339,7 +272,6 @@ def from_dict(cls, data, intersect=False, orient='items', dtype=None):
339
272
-------
340
273
Panel
341
274
"""
342
-
343
275
orient = orient .lower ()
344
276
if orient == 'minor' :
345
277
new_data = OrderedDefaultdict (dict )
@@ -352,7 +284,7 @@ def from_dict(cls, data, intersect=False, orient='items', dtype=None):
352
284
353
285
d = cls ._homogenize_dict (cls , data , intersect = intersect , dtype = dtype )
354
286
ks = list (d ['data' ].keys ())
355
- if not isinstance (d ['data' ],OrderedDict ):
287
+ if not isinstance (d ['data' ], OrderedDict ):
356
288
ks = list (sorted (ks ))
357
289
d [cls ._info_axis_name ] = Index (ks )
358
290
return cls (** d )
@@ -416,7 +348,7 @@ def _init_matrix(self, data, axes, dtype=None, copy=False):
416
348
ax = _ensure_index (ax )
417
349
fixed_axes .append (ax )
418
350
419
- return create_block_manager_from_blocks ([ values ], fixed_axes )
351
+ return create_block_manager_from_blocks ([values ], fixed_axes )
420
352
421
353
#----------------------------------------------------------------------
422
354
# Comparison methods
@@ -602,7 +534,7 @@ def set_value(self, *args):
602
534
axes = self ._expand_axes (args )
603
535
d = self ._construct_axes_dict_from (self , axes , copy = False )
604
536
result = self .reindex (** d )
605
- args = list (args )
537
+ args = list (args )
606
538
likely_dtype , args [- 1 ] = _infer_dtype_from_scalar (args [- 1 ])
607
539
made_bigger = not np .array_equal (
608
540
axes [0 ], self ._info_axis )
@@ -906,7 +838,7 @@ def _ixs(self, i, axis=0):
906
838
907
839
# xs cannot handle a non-scalar key, so just reindex here
908
840
if _is_list_like (key ):
909
- return self .reindex (** { self ._get_axis_name (axis ) : key })
841
+ return self .reindex (** {self ._get_axis_name (axis ): key })
910
842
911
843
return self .xs (key , axis = axis )
912
844
@@ -1192,7 +1124,7 @@ def update(self, other, join='left', overwrite=True, filter_func=None,
1192
1124
if not isinstance (other , self ._constructor ):
1193
1125
other = self ._constructor (other )
1194
1126
1195
- axis_name = self ._info_axis_name
1127
+ axis_name = self ._info_axis_name
1196
1128
axis_values = self ._info_axis
1197
1129
other = other .reindex (** {axis_name : axis_values })
1198
1130
@@ -1257,7 +1189,8 @@ def _homogenize_dict(self, frames, intersect=True, dtype=None):
1257
1189
"""
1258
1190
1259
1191
result = dict ()
1260
- if isinstance (frames ,OrderedDict ): # caller differs dict/ODict, presered type
1192
+ # caller differs dict/ODict, presered type
1193
+ if isinstance (frames , OrderedDict ):
1261
1194
result = OrderedDict ()
1262
1195
1263
1196
adj_frames = OrderedDict ()
@@ -1366,7 +1299,7 @@ def f(self, other, axis=0):
1366
1299
Parameters
1367
1300
----------
1368
1301
axis : {""" + ', ' .join (cls ._AXIS_ORDERS ) + "} or {" \
1369
- + ', ' .join ([str (i ) for i in range (cls ._AXIS_LEN )]) + """}
1302
+ + ', ' .join ([str (i ) for i in range (cls ._AXIS_LEN )]) + """}
1370
1303
skipna : boolean, default True
1371
1304
Exclude NA/null values. If an entire row/column is NA, the result
1372
1305
will be NA
@@ -1440,13 +1373,13 @@ def min(self, axis='major', skipna=True):
1440
1373
return self ._reduce (nanops .nanmin , axis = axis , skipna = skipna )
1441
1374
cls .min = min
1442
1375
1443
- Panel ._setup_axes (axes = ['items' , 'major_axis' , 'minor_axis' ],
1444
- info_axis = 0 ,
1445
- stat_axis = 1 ,
1446
- aliases = { 'major' : 'major_axis' ,
1447
- 'minor' : 'minor_axis' },
1448
- slicers = { 'major_axis' : 'index' ,
1449
- 'minor_axis' : 'columns' })
1376
+ Panel ._setup_axes (axes = ['items' , 'major_axis' , 'minor_axis' ],
1377
+ info_axis = 0 ,
1378
+ stat_axis = 1 ,
1379
+ aliases = { 'major' : 'major_axis' ,
1380
+ 'minor' : 'minor_axis' },
1381
+ slicers = { 'major_axis' : 'index' ,
1382
+ 'minor_axis' : 'columns' })
1450
1383
Panel ._add_aggregate_operations ()
1451
1384
1452
1385
WidePanel = Panel
0 commit comments