@@ -1634,21 +1634,17 @@ def fast_xs(self, loc):
1634
1634
1635
1635
1636
1636
def create_block_manager_from_blocks (blocks , axes : List [Index ]) -> BlockManager :
1637
- try :
1638
- if len (blocks ) == 1 and not isinstance (blocks [0 ], Block ):
1639
- # if blocks[0] is of length 0, return empty blocks
1640
- if not len (blocks [0 ]):
1641
- blocks = []
1642
- else :
1643
- # It's OK if a single block is passed as values, its placement
1644
- # is basically "all items", but if there're many, don't bother
1645
- # converting, it's an error anyway.
1646
- blocks = [
1647
- make_block (
1648
- values = blocks [0 ], placement = slice (0 , len (axes [0 ])), ndim = 2
1649
- )
1650
- ]
1637
+ if len (blocks ) == 1 and not isinstance (blocks [0 ], Block ):
1638
+ # if blocks[0] is of length 0, return empty blocks
1639
+ if not len (blocks [0 ]):
1640
+ blocks = []
1641
+ else :
1642
+ # It's OK if a single block is passed as values, its placement
1643
+ # is basically "all items", but if there're many, don't bother
1644
+ # converting, it's an error anyway.
1645
+ return create_block_manager_from_array (blocks [0 ], axes )
1651
1646
1647
+ try :
1652
1648
mgr = BlockManager (blocks , axes )
1653
1649
mgr ._consolidate_inplace ()
1654
1650
return mgr
@@ -1678,6 +1674,19 @@ def create_block_manager_from_arrays(
1678
1674
raise construction_error (len (arrays ), arrays [0 ].shape , axes , e )
1679
1675
1680
1676
1677
+ def create_block_manager_from_array (
1678
+ array ,
1679
+ axes : List [Index ],
1680
+ ) -> BlockManager :
1681
+ try :
1682
+ block = make_block (values = array , placement = slice (0 , len (axes [0 ])), ndim = 2 )
1683
+ mgr = BlockManager ([block ], axes )
1684
+ mgr ._consolidate_inplace ()
1685
+ except ValueError as e :
1686
+ raise construction_error (array .shape [0 ], array .shape [1 :], axes , e )
1687
+ return mgr
1688
+
1689
+
1681
1690
def construction_error (tot_items , block_shape , axes , e = None ):
1682
1691
""" raise a helpful message about our construction """
1683
1692
passed = tuple (map (int , [tot_items ] + list (block_shape )))
0 commit comments