1
- from operator import attrgetter
2
1
import itertools
3
2
4
3
from numpy import nan
5
4
import numpy as np
6
5
7
- from pandas .core .index import Index , NULL_INDEX
8
- from pandas .core .common import _ensure_index , _try_sort
6
+ from pandas .core .index import Index
7
+ from pandas .core .common import _ensure_index
9
8
import pandas .core .common as common
10
9
import pandas ._tseries as _tseries
11
10
@@ -375,7 +374,6 @@ def get_series_dict(self):
375
374
def from_blocks (cls , blocks , index ):
376
375
# also checks for overlap
377
376
items = _union_block_items (blocks )
378
- ndim = blocks [0 ].ndim
379
377
return BlockManager (blocks , [items , index ])
380
378
381
379
def __contains__ (self , item ):
@@ -429,8 +427,6 @@ def _interleave(self, items):
429
427
return result
430
428
431
429
def xs (self , key , axis = 1 , copy = True ):
432
- from pandas .core .series import Series
433
-
434
430
assert (axis >= 1 )
435
431
436
432
i = self .axes [axis ].get_loc (key )
@@ -441,15 +437,15 @@ def xs(self, key, axis=1, copy=True):
441
437
new_axes = list (self .axes )
442
438
new_axes .pop (axis )
443
439
440
+ new_blocks = []
444
441
if len (self .blocks ) > 1 :
445
442
if not copy :
446
443
raise Exception ('cannot get view of mixed-type or '
447
444
'non-consolidated DataFrame' )
448
- new_blocks = []
449
445
for blk in self .blocks :
450
446
newb = make_block (blk .values [slicer ], blk .items , blk .ref_items )
451
447
new_blocks .append (newb )
452
- else :
448
+ elif len ( self . blocks ) == 1 :
453
449
vals = self .blocks [0 ].values [slicer ]
454
450
if copy :
455
451
vals = vals .copy ()
0 commit comments