@@ -68,15 +68,15 @@ def create_block(typestr, placement, item_shape=None, num_offset=0):
6868 elif typestr in ('object' , 'string' , 'O' ):
6969 values = np .reshape (['A%d' % i for i in mat .ravel () + num_offset ],
7070 shape )
71- elif typestr in ('bool' ):
71+ elif typestr in ('b' , ' bool', ):
7272 values = np .ones (shape , dtype = np .bool_ )
7373 elif typestr in ('datetime' , 'dt' , 'M8[ns]' ):
7474 values = (mat * 1e9 ).astype ('M8[ns]' )
7575 elif typestr in ('timedelta' , 'td' , 'm8[ns]' ):
7676 values = (mat * 1 ).astype ('m8[ns]' )
77- elif typestr in ('category' ):
77+ elif typestr in ('category' , ):
7878 values = Categorical ([1 ,1 ,2 ,2 ,3 ,3 ,3 ,3 ,4 ,4 ])
79- elif typestr in ('category2' ):
79+ elif typestr in ('category2' , ):
8080 values = Categorical (['a' ,'a' ,'a' ,'a' ,'b' ,'b' ,'c' ,'c' ,'c' ,'d' ])
8181 elif typestr in ('sparse' , 'sparse_na' ):
8282 # FIXME: doesn't support num_rows != 10
@@ -751,6 +751,25 @@ def test_equals(self):
751751 bm2 = BlockManager (bm1 .blocks [::- 1 ], bm1 .axes )
752752 self .assertTrue (bm1 .equals (bm2 ))
753753
754+ def test_equals_block_order_different_dtypes (self ):
755+ # GH 9330
756+
757+ mgr_strings = [
758+ "a:i8;b:f8" , # basic case
759+ "a:i8;b:f8;c:c8;d:b" , # many types
760+ "a:i8;e:dt;f:td;g:string" , # more types
761+ "a:i8;b:category;c:category2;d:category2" , # categories
762+ "c:sparse;d:sparse_na;b:f8" , # sparse
763+ ]
764+
765+ for mgr_string in mgr_strings :
766+ bm = create_mgr (mgr_string )
767+ block_perms = itertools .permutations (bm .blocks )
768+ for bm_perm in block_perms :
769+ bm_this = BlockManager (bm_perm , bm .axes )
770+ self .assertTrue (bm .equals (bm_this ))
771+ self .assertTrue (bm_this .equals (bm ))
772+
754773 def test_single_mgr_ctor (self ):
755774 mgr = create_single_mgr ('f8' , num_rows = 5 )
756775 self .assertEqual (mgr .as_matrix ().tolist (), [0. , 1. , 2. , 3. , 4. ])
0 commit comments