@@ -16,7 +16,8 @@ class Block(object):
16
16
"""
17
17
__slots__ = ['items' , 'ref_items' , '_ref_locs' , 'values' , 'ndim' ]
18
18
19
- def __init__ (self , values , items , ref_items , ndim = 2 ):
19
+ def __init__ (self , values , items , ref_items , ndim = 2 ,
20
+ do_integrity_check = False ):
20
21
if issubclass (values .dtype .type , basestring ):
21
22
values = np .array (values , dtype = object )
22
23
@@ -27,7 +28,9 @@ def __init__(self, values, items, ref_items, ndim=2):
27
28
self .ndim = ndim
28
29
self .items = _ensure_index (items )
29
30
self .ref_items = _ensure_index (ref_items )
30
- self ._check_integrity ()
31
+
32
+ if do_integrity_check :
33
+ self ._check_integrity ()
31
34
32
35
def _check_integrity (self ):
33
36
if len (self .items ) < 2 :
@@ -186,7 +189,7 @@ def can_store(self, value):
186
189
return not issubclass (value .dtype .type ,
187
190
(np .integer , np .floating , np .bool_ ))
188
191
189
- def make_block (values , items , ref_items ):
192
+ def make_block (values , items , ref_items , do_integrity_check = False ):
190
193
dtype = values .dtype
191
194
vtype = dtype .type
192
195
@@ -199,7 +202,8 @@ def make_block(values, items, ref_items):
199
202
else :
200
203
klass = ObjectBlock
201
204
202
- return klass (values , items , ref_items , ndim = values .ndim )
205
+ return klass (values , items , ref_items , ndim = values .ndim ,
206
+ do_integrity_check = do_integrity_check )
203
207
204
208
# TODO: flexible with index=None and/or items=None
205
209
@@ -221,15 +225,15 @@ class BlockManager(object):
221
225
"""
222
226
__slots__ = ['axes' , 'blocks' , 'ndim' ]
223
227
224
- def __init__ (self , blocks , axes , skip_integrity_check = False ):
228
+ def __init__ (self , blocks , axes , do_integrity_check = True ):
225
229
self .axes = [_ensure_index (ax ) for ax in axes ]
226
230
self .blocks = blocks
227
231
228
232
ndim = len (axes )
229
233
for block in blocks :
230
234
assert (ndim == block .values .ndim )
231
235
232
- if not skip_integrity_check :
236
+ if do_integrity_check :
233
237
self ._verify_integrity ()
234
238
235
239
@property
@@ -281,7 +285,8 @@ def __setstate__(self, state):
281
285
self .axes = [_ensure_index (ax ) for ax in ax_arrays ]
282
286
blocks = []
283
287
for values , items in zip (bvalues , bitems ):
284
- blk = make_block (values , items , self .axes [0 ])
288
+ blk = make_block (values , items , self .axes [0 ],
289
+ do_integrity_check = True )
285
290
blocks .append (blk )
286
291
self .blocks = blocks
287
292
@@ -346,7 +351,7 @@ def get_slice(self, slobj, axis=0):
346
351
else :
347
352
new_blocks = self ._slice_blocks (slobj , axis )
348
353
349
- return BlockManager (new_blocks , new_axes )
354
+ return BlockManager (new_blocks , new_axes , do_integrity_check = False )
350
355
351
356
def _slice_blocks (self , slobj , axis ):
352
357
new_blocks = []
@@ -589,7 +594,8 @@ def reindex_items(self, new_items):
589
594
block_shape [0 ] = len (extra_items )
590
595
block_values = np .empty (block_shape , dtype = np .float64 )
591
596
block_values .fill (nan )
592
- na_block = make_block (block_values , extra_items , new_items )
597
+ na_block = make_block (block_values , extra_items , new_items ,
598
+ do_integrity_check = True )
593
599
new_blocks .append (na_block )
594
600
new_blocks = _consolidate (new_blocks , new_items )
595
601
@@ -780,7 +786,8 @@ def form_blocks(data, axes):
780
786
block_values = np .empty (shape , dtype = float )
781
787
block_values .fill (nan )
782
788
783
- na_block = make_block (block_values , extra_items , items )
789
+ na_block = make_block (block_values , extra_items , items ,
790
+ do_integrity_check = True )
784
791
blocks .append (na_block )
785
792
blocks = _consolidate (blocks , items )
786
793
@@ -792,7 +799,7 @@ def _simple_blockify(dct, ref_items, dtype):
792
799
if values .dtype != dtype : # pragma: no cover
793
800
values = values .astype (dtype )
794
801
795
- return make_block (values , block_items , ref_items )
802
+ return make_block (values , block_items , ref_items , do_integrity_check = True )
796
803
797
804
def _stack_dict (dct , ref_items ):
798
805
items = [x for x in ref_items if x in dct ]
@@ -857,12 +864,15 @@ def _consolidate(blocks, items):
857
864
858
865
return new_blocks
859
866
867
+ # TODO: this could be much optimized
868
+
860
869
def _merge_blocks (blocks , items ):
861
870
if len (blocks ) == 1 :
862
871
return blocks [0 ]
863
872
new_values = np .vstack ([b .values for b in blocks ])
864
873
new_items = np .concatenate ([b .items for b in blocks ])
865
- new_block = make_block (new_values , new_items , items )
874
+ new_block = make_block (new_values , new_items , items ,
875
+ do_integrity_check = True )
866
876
return new_block .reindex_items_from (items )
867
877
868
878
def _union_block_items (blocks ):
0 commit comments