@@ -17,8 +17,6 @@ class Block(object):
17
17
Index-ignorant; let the container take care of that
18
18
"""
19
19
def __init__ (self , values , items , ref_items , ndim = 2 ):
20
- # values = _convert_if_1d(values)
21
-
22
20
if issubclass (values .dtype .type , basestring ):
23
21
values = np .array (values , dtype = object )
24
22
@@ -161,12 +159,6 @@ def _cast_if_bool_int(values):
161
159
values = values .astype (object )
162
160
return values
163
161
164
- def _convert_if_1d (values ):
165
- if values .ndim == 1 :
166
- values = np .atleast_2d (values )
167
-
168
- return values
169
-
170
162
#-------------------------------------------------------------------------------
171
163
# Is this even possible?
172
164
@@ -224,17 +216,13 @@ class BlockManager(object):
224
216
-----
225
217
This is *not* a public API class
226
218
"""
227
- def __init__ (self , blocks , axes , skip_integrity_check = False , ndim = None ):
219
+ def __init__ (self , blocks , axes , skip_integrity_check = False ):
228
220
self .axes = [_ensure_index (ax ) for ax in axes ]
229
221
self .blocks = blocks
230
222
231
- if ndim is None and len (blocks ) == 0 :
232
- raise ValueError ('must specify dimension if no input blocks' )
233
- elif ndim is None :
234
- ndim = blocks [0 ].ndim
235
- else :
236
- for block in blocks :
237
- assert (ndim == block .values .ndim )
223
+ ndim = len (axes )
224
+ for block in blocks :
225
+ assert (ndim == block .values .ndim )
238
226
239
227
self .ndim = ndim
240
228
@@ -325,7 +313,7 @@ def cast(self, dtype):
325
313
block .ref_items )
326
314
new_blocks .append (newb )
327
315
328
- new_mgr = BlockManager (new_blocks , self .axes , ndim = self . ndim )
316
+ new_mgr = BlockManager (new_blocks , self .axes )
329
317
return new_mgr .consolidate ()
330
318
331
319
def is_consolidated (self ):
@@ -340,7 +328,7 @@ def get_slice(self, slice_obj, axis=0):
340
328
341
329
new_axes = list (self .axes )
342
330
new_axes [axis ] = new_axes [axis ][slice_obj ]
343
- return BlockManager (new_blocks , new_axes , ndim = self . ndim )
331
+ return BlockManager (new_blocks , new_axes )
344
332
345
333
def _slice_blocks (self , slice_obj , axis ):
346
334
new_blocks = []
@@ -364,7 +352,7 @@ def from_blocks(cls, blocks, index):
364
352
# also checks for overlap
365
353
items = _union_block_items (blocks )
366
354
ndim = blocks [0 ].ndim
367
- return BlockManager (blocks , [items , index ], ndim = ndim )
355
+ return BlockManager (blocks , [items , index ])
368
356
369
357
def __contains__ (self , item ):
370
358
return item in self .items
@@ -375,7 +363,7 @@ def nblocks(self):
375
363
376
364
def copy (self ):
377
365
copy_blocks = [block .copy () for block in self .blocks ]
378
- return BlockManager (copy_blocks , self .axes , ndim = self . ndim )
366
+ return BlockManager (copy_blocks , self .axes )
379
367
380
368
def as_matrix (self , items = None ):
381
369
if len (self .blocks ) == 0 :
@@ -530,7 +518,7 @@ def reindex_axis(self, new_axis, method=None, axis=0):
530
518
531
519
new_axes = list (self .axes )
532
520
new_axes [axis ] = new_axis
533
- return BlockManager (new_blocks , new_axes , ndim = self . ndim )
521
+ return BlockManager (new_blocks , new_axes )
534
522
535
523
def reindex_items (self , new_items ):
536
524
"""
@@ -566,7 +554,7 @@ def reindex_items(self, new_items):
566
554
new_axes = list (self .axes )
567
555
new_axes [0 ] = new_items
568
556
569
- return BlockManager (new_blocks , new_axes , ndim = self . ndim )
557
+ return BlockManager (new_blocks , new_axes )
570
558
571
559
def merge (self , other ):
572
560
assert (self ._is_indexed_like (other ))
@@ -677,8 +665,6 @@ def form_blocks(data, index, items):
677
665
678
666
blocks = []
679
667
680
- ndim = 2
681
-
682
668
if len (num_dict ) > 0 :
683
669
num_dtypes = set (v .dtype for v in num_dict .values ())
684
670
if len (num_dtypes ) > 1 :
@@ -688,15 +674,15 @@ def form_blocks(data, index, items):
688
674
689
675
# TODO: find corner cases
690
676
# TODO: check type inference
691
- num_block = _simple_blockify (num_dict , items , num_dtype , ndim )
677
+ num_block = _simple_blockify (num_dict , items , num_dtype )
692
678
blocks .append (num_block )
693
679
694
680
if len (bool_dict ):
695
- bool_block = _simple_blockify (bool_dict , items , np .bool_ , ndim )
681
+ bool_block = _simple_blockify (bool_dict , items , np .bool_ )
696
682
blocks .append (bool_block )
697
683
698
684
if len (object_dict ) > 0 :
699
- object_block = _simple_blockify (object_dict , items , np .object_ , ndim )
685
+ object_block = _simple_blockify (object_dict , items , np .object_ )
700
686
blocks .append (object_block )
701
687
702
688
if len (extra_items ):
@@ -709,10 +695,10 @@ def form_blocks(data, index, items):
709
695
710
696
return blocks , items
711
697
712
- def _simple_blockify (dct , ref_items , dtype , ndim ):
698
+ def _simple_blockify (dct , ref_items , dtype ):
713
699
block_items , values = _stack_dict (dct )
714
700
# CHECK DTYPE?
715
- if values .dtype != dtype :
701
+ if values .dtype != dtype : # pragma: no cover
716
702
values = values .astype (dtype )
717
703
718
704
return make_block (values , block_items , ref_items )
@@ -732,26 +718,6 @@ def _blocks_to_series_dict(blocks, index=None):
732
718
series_dict [item ] = Series (vec , index = index )
733
719
return series_dict
734
720
735
- def _interleave (blocks , items ):
736
- """
737
- Return ndarray from blocks with specified item order
738
- Items must be contained in the blocks
739
- """
740
- dtype = _interleaved_dtype (blocks )
741
- items = _ensure_index (items )
742
-
743
- result = np .empty ((len (blocks [0 ]), len (items )), dtype = dtype )
744
- itemmask = np .zeros (len (items ), dtype = bool )
745
-
746
- # By construction, all of the item should be covered by one of the blocks
747
- for block in blocks :
748
- indexer , mask = items .get_indexer (block .items )
749
- assert (mask .all ())
750
- result [:, indexer ] = block .values
751
- itemmask [indexer ] = 1
752
- assert (itemmask .all ())
753
- return result
754
-
755
721
def _interleaved_dtype (blocks ):
756
722
have_int = False
757
723
have_bool = False
0 commit comments