@@ -168,7 +168,7 @@ def reindex_items_from(self, new_ref_items, copy=True):
168
168
reindexed : Block
169
169
"""
170
170
new_ref_items , indexer = self .items .reindex (new_ref_items )
171
-
171
+
172
172
if indexer is None :
173
173
new_items = new_ref_items
174
174
new_values = self .values .copy () if copy else self .values
@@ -1074,7 +1074,7 @@ def _set_ref_locs(self, labels=None, do_refs=False):
1074
1074
if we have a non-unique index on this axis, set the indexers
1075
1075
we need to set an absolute indexer for the blocks
1076
1076
return the indexer if we are not unique
1077
-
1077
+
1078
1078
labels : the (new) labels for this manager
1079
1079
ref : boolean, whether to set the labels (one a 1-1 mapping)
1080
1080
@@ -1088,7 +1088,7 @@ def _set_ref_locs(self, labels=None, do_refs=False):
1088
1088
if is_unique and not do_refs :
1089
1089
1090
1090
if not self .items .is_unique :
1091
-
1091
+
1092
1092
# reset our ref locs
1093
1093
self ._ref_locs = None
1094
1094
for b in self .blocks :
@@ -1130,12 +1130,12 @@ def _set_ref_locs(self, labels=None, do_refs=False):
1130
1130
self ._ref_locs = rl
1131
1131
return rl
1132
1132
1133
- # return our cached _ref_locs (or will compute again
1133
+ # return our cached _ref_locs (or will compute again
1134
1134
# when we recreate the block manager if needed
1135
1135
return getattr (self ,'_ref_locs' ,None )
1136
1136
1137
1137
def get_items_map (self , use_cached = True ):
1138
- """
1138
+ """
1139
1139
return an inverted ref_loc map for an item index
1140
1140
block -> item (in that block) location -> column location
1141
1141
@@ -1166,7 +1166,7 @@ def get_items_map(self, use_cached=True):
1166
1166
else :
1167
1167
1168
1168
for i , (block , idx ) in enumerate (rl ):
1169
-
1169
+
1170
1170
m = maybe_create_block_in_items_map (im ,block )
1171
1171
m [idx ] = i
1172
1172
@@ -1362,11 +1362,13 @@ def _consolidate_check(self):
1362
1362
1363
1363
@property
1364
1364
def is_mixed_type (self ):
1365
+ # Warning, consolidation needs to get checked upstairs
1365
1366
self ._consolidate_inplace ()
1366
1367
return len (self .blocks ) > 1
1367
1368
1368
1369
@property
1369
1370
def is_numeric_mixed_type (self ):
1371
+ # Warning, consolidation needs to get checked upstairs
1370
1372
self ._consolidate_inplace ()
1371
1373
return all ([ block .is_numeric for block in self .blocks ])
1372
1374
@@ -1438,9 +1440,9 @@ def get_slice(self, slobj, axis=0, raise_on_error=False):
1438
1440
new_items = new_axes [0 ]
1439
1441
if len (self .blocks ) == 1 :
1440
1442
blk = self .blocks [0 ]
1441
- newb = make_block (blk .values [slobj ],
1443
+ newb = make_block (blk .values [slobj ],
1444
+ new_items ,
1442
1445
new_items ,
1443
- new_items ,
1444
1446
klass = blk .__class__ ,
1445
1447
fastpath = True ,
1446
1448
placement = blk ._ref_locs )
@@ -1462,9 +1464,9 @@ def _slice_blocks(self, slobj, axis):
1462
1464
slicer = tuple (slicer )
1463
1465
1464
1466
for block in self .blocks :
1465
- newb = make_block (block .values [slicer ],
1467
+ newb = make_block (block .values [slicer ],
1466
1468
block .items ,
1467
- block .ref_items ,
1469
+ block .ref_items ,
1468
1470
klass = block .__class__ ,
1469
1471
fastpath = True ,
1470
1472
placement = block ._ref_locs )
@@ -1576,9 +1578,9 @@ def xs(self, key, axis=1, copy=True):
1576
1578
raise Exception ('cannot get view of mixed-type or '
1577
1579
'non-consolidated DataFrame' )
1578
1580
for blk in self .blocks :
1579
- newb = make_block (blk .values [slicer ],
1580
- blk .items ,
1581
- blk .ref_items ,
1581
+ newb = make_block (blk .values [slicer ],
1582
+ blk .items ,
1583
+ blk .ref_items ,
1582
1584
klass = blk .__class__ ,
1583
1585
fastpath = True )
1584
1586
new_blocks .append (newb )
@@ -1587,8 +1589,8 @@ def xs(self, key, axis=1, copy=True):
1587
1589
vals = block .values [slicer ]
1588
1590
if copy :
1589
1591
vals = vals .copy ()
1590
- new_blocks = [make_block (vals ,
1591
- self .items ,
1592
+ new_blocks = [make_block (vals ,
1593
+ self .items ,
1592
1594
self .items ,
1593
1595
klass = block .__class__ ,
1594
1596
fastpath = True )]
@@ -1637,7 +1639,6 @@ def consolidate(self):
1637
1639
1638
1640
def _consolidate_inplace (self ):
1639
1641
if not self .is_consolidated ():
1640
-
1641
1642
self .blocks = _consolidate (self .blocks , self .items )
1642
1643
1643
1644
# reset our mappings
@@ -1703,7 +1704,7 @@ def delete(self, item):
1703
1704
# dupe keys may return mask
1704
1705
loc = _possibly_convert_to_indexer (loc )
1705
1706
self ._delete_from_all_blocks (loc , item )
1706
-
1707
+
1707
1708
# _ref_locs, and _items_map are good here
1708
1709
new_items = self .items .delete (loc )
1709
1710
self .set_items_norename (new_items )
@@ -1763,7 +1764,7 @@ def _set_item(item, arr):
1763
1764
if self .items .is_unique :
1764
1765
self ._reset_ref_locs ()
1765
1766
self ._set_ref_locs (do_refs = 'force' )
1766
-
1767
+
1767
1768
self ._rebuild_ref_locs ()
1768
1769
1769
1770
@@ -1893,7 +1894,7 @@ def _delete_from_block(self, i, item):
1893
1894
1894
1895
# reset the ref_locs based on the now good block._ref_locs
1895
1896
self ._reset_ref_locs ()
1896
-
1897
+
1897
1898
def _add_new_block (self , item , value , loc = None ):
1898
1899
# Do we care about dtype at the moment?
1899
1900
@@ -1919,7 +1920,7 @@ def _add_new_block(self, item, value, loc=None):
1919
1920
self ._ref_locs [i ] = self ._ref_locs [i - 1 ]
1920
1921
1921
1922
self ._ref_locs [loc ] = (new_block , 0 )
1922
-
1923
+
1923
1924
# and reset
1924
1925
self ._reset_ref_locs ()
1925
1926
self ._set_ref_locs (do_refs = True )
@@ -2081,7 +2082,7 @@ def take(self, indexer, new_index=None, axis=1, verify=True):
2081
2082
if new_index is None :
2082
2083
new_index = self .axes [axis ].take (indexer )
2083
2084
2084
- new_axes [axis ] = new_index
2085
+ new_axes [axis ] = new_index
2085
2086
return self .apply ('take' ,axes = new_axes ,indexer = indexer ,ref_items = new_axes [0 ],axis = axis )
2086
2087
2087
2088
def merge (self , other , lsuffix = None , rsuffix = None ):
@@ -2453,7 +2454,7 @@ def _lcd_dtype(l):
2453
2454
if lcd .kind == 'u' :
2454
2455
return np .dtype ('int%s' % (lcd .itemsize * 8 * 2 ))
2455
2456
return lcd
2456
-
2457
+
2457
2458
elif have_dt64 and not have_float and not have_complex :
2458
2459
return np .dtype ('M8[ns]' )
2459
2460
elif have_complex :
@@ -2500,7 +2501,7 @@ def _merge_blocks(blocks, items, dtype=None):
2500
2501
new_ref_locs = [ b ._ref_locs for b in blocks ]
2501
2502
if all ([ x is not None for x in new_ref_locs ]):
2502
2503
new_block .set_ref_locs (np .concatenate (new_ref_locs ))
2503
- return new_block
2504
+ return new_block
2504
2505
2505
2506
2506
2507
def _block_shape (values , ndim = 1 , shape = None ):
0 commit comments