9
9
10
10
import numpy as np
11
11
12
- from pandas .core .common import (PandasError , _mut_exclusive ,
13
- _ensure_index , _pfixed )
12
+ from pandas .core .common import (PandasError , _mut_exclusive , _ensure_index ,
13
+ _pfixed , _default_index )
14
14
from pandas .core .index import Index
15
15
from pandas .core .internals import BlockManager , make_block
16
16
from pandas .core .frame import DataFrame
@@ -210,38 +210,20 @@ def __init__(self, data, items=None, major_axis=None, minor_axis=None,
210
210
elif isinstance (data , np .ndarray ):
211
211
mgr = self ._init_matrix (data , [items , major_axis , minor_axis ],
212
212
dtype = dtype , copy = copy )
213
- else :
213
+ else : # pragma: no cover
214
214
raise PandasError ('Panel constructor not properly called!' )
215
215
216
216
self .factors = {}
217
217
self ._data = mgr
218
218
219
- def _consolidate_inplace (self ):
220
- self ._data = self ._data .consolidate ()
221
-
222
- def consolidate (self ):
223
- """
224
- Compute DataFrame with "consolidated" internals (data of each dtype
225
- grouped together in a single ndarray). Mainly an internal API function,
226
- but available here to the savvy user
227
-
228
- Returns
229
- -------
230
- consolidated : DataFrame
231
- """
232
- cons_data = self ._data .consolidate ()
233
- if cons_data is self ._data :
234
- cons_data = cons_data .copy ()
235
- return type (self )(cons_data )
236
-
237
219
def _init_matrix (self , data , axes , dtype = None , copy = False ):
238
220
values = _prep_ndarray (data , copy = copy )
239
221
240
222
if dtype is not None :
241
223
try :
242
224
values = values .astype (dtype )
243
225
except Exception :
244
- pass
226
+ raise ValueError ( 'failed to cast to %s' % dtype )
245
227
246
228
shape = values .shape
247
229
fixed_axes = []
@@ -254,7 +236,7 @@ def _init_matrix(self, data, axes, dtype=None, copy=False):
254
236
255
237
items = fixed_axes [0 ]
256
238
block = make_block (values , items , items )
257
- return BlockManager ([block ], axes )
239
+ return BlockManager ([block ], fixed_axes )
258
240
259
241
def _get_plane_axes (self , axis ):
260
242
"""
@@ -487,47 +469,39 @@ def reindex_like(self, other, method=None):
487
469
return self .reindex (major = other .major_axis , items = other .items ,
488
470
minor = other .minor_axis , method = method )
489
471
490
- def _reindex_axis (self , new_index , fill_method , axis ):
491
- if axis == 0 :
492
- new_data = self ._data .reindex_items (new_index )
493
- else :
494
- new_data = self ._data .reindex_axis (new_index , axis = axis ,
495
- method = fill_method )
496
- return WidePanel (new_data )
497
-
498
472
def _combine (self , other , func , axis = 0 ):
499
473
if isinstance (other , DataFrame ):
500
- return self ._combineFrame (other , func , axis = axis )
474
+ return self ._combine_frame (other , func , axis = axis )
501
475
elif isinstance (other , Panel ):
502
- return self ._combinePanel (other , func )
476
+ return self ._combine_panel (other , func )
503
477
elif np .isscalar (other ):
504
- newValues = func (self .values , other )
478
+ new_values = func (self .values , other )
505
479
506
- return WidePanel (newValues , self .items , self .major_axis ,
480
+ return WidePanel (new_values , self .items , self .major_axis ,
507
481
self .minor_axis )
508
482
509
483
def __neg__ (self ):
510
484
return - 1 * self
511
485
512
- def _combineFrame (self , other , func , axis = 0 ):
486
+ def _combine_frame (self , other , func , axis = 0 ):
513
487
index , columns = self ._get_plane_axes (axis )
514
488
axis = self ._get_axis_number (axis )
515
489
516
490
other = other .reindex (index = index , columns = columns )
517
491
518
492
if axis == 0 :
519
- newValues = func (self .values , other .values )
493
+ new_values = func (self .values , other .values )
520
494
elif axis == 1 :
521
- newValues = func (self .values .swapaxes (0 , 1 ), other .values .T )
522
- newValues = newValues .swapaxes (0 , 1 )
495
+ new_values = func (self .values .swapaxes (0 , 1 ), other .values .T )
496
+ new_values = new_values .swapaxes (0 , 1 )
523
497
elif axis == 2 :
524
- newValues = func (self .values .swapaxes (0 , 2 ), other .values )
525
- newValues = newValues .swapaxes (0 , 2 )
498
+ new_values = func (self .values .swapaxes (0 , 2 ), other .values )
499
+ new_values = new_values .swapaxes (0 , 2 )
526
500
527
- return WidePanel (newValues , self .items , self .major_axis ,
501
+ return WidePanel (new_values , self .items , self .major_axis ,
528
502
self .minor_axis )
529
503
530
- def _combinePanel (self , other , func ):
504
+ def _combine_panel (self , other , func ):
531
505
if isinstance (other , LongPanel ):
532
506
other = other .to_wide ()
533
507
@@ -1240,14 +1214,14 @@ def __setstate__(self, state):
1240
1214
1241
1215
def _combine (self , other , func , axis = 'items' ):
1242
1216
if isinstance (other , DataFrame ):
1243
- return self ._combineFrame (other , func , axis = axis )
1217
+ return self ._combine_frame (other , func , axis = axis )
1244
1218
elif isinstance (other , Panel ):
1245
- return self ._combinePanel (other , func )
1219
+ return self ._combine_panel (other , func )
1246
1220
elif np .isscalar (other ):
1247
1221
return LongPanel (func (self .values , other ), self .items ,
1248
1222
self .index , factors = self .factors )
1249
1223
1250
- def _combineFrame (self , other , func , axis = 'items' ):
1224
+ def _combine_frame (self , other , func , axis = 'items' ):
1251
1225
"""
1252
1226
Arithmetic op
1253
1227
@@ -1262,10 +1236,10 @@ def _combineFrame(self, other, func, axis='items'):
1262
1236
y : LongPanel
1263
1237
"""
1264
1238
wide = self .to_wide ()
1265
- result = wide ._combineFrame (other , func , axis = axis )
1239
+ result = wide ._combine_frame (other , func , axis = axis )
1266
1240
return result .to_long ()
1267
1241
1268
- def _combinePanel (self , other , func ):
1242
+ def _combine_panel (self , other , func ):
1269
1243
"""
1270
1244
Arithmetic operation between panels
1271
1245
"""
0 commit comments