7
7
from pandas .core .internals import (
8
8
Block , BlockManager , SingleBlockManager , NonConsolidatableMixIn )
9
9
10
+ import pytest
11
+
10
12
11
13
class CustomBlock (NonConsolidatableMixIn , Block ):
12
14
@@ -25,6 +27,17 @@ def concat_same_type(self, to_concat, placement=None):
25
27
values , placement = placement or slice (0 , len (values ), 1 ))
26
28
27
29
30
+ @pytest .fixture
31
+ def df ():
32
+ df1 = pd .DataFrame ({'a' : [1 , 2 , 3 ]})
33
+ blocks = df1 ._data .blocks
34
+ values = np .arange (3 , dtype = 'int64' )
35
+ custom_block = CustomBlock (values , placement = slice (1 , 2 ))
36
+ blocks = blocks + (custom_block ,)
37
+ block_manager = BlockManager (blocks , [pd .Index (['a' , 'b' ]), df1 .index ])
38
+ return pd .DataFrame (block_manager )
39
+
40
+
28
41
def test_custom_repr ():
29
42
values = np .arange (3 , dtype = 'int64' )
30
43
@@ -51,14 +64,14 @@ def test_concat_series():
51
64
assert isinstance (res ._data .blocks [0 ], CustomBlock )
52
65
53
66
54
- def test_concat_dataframe ():
67
+ def test_concat_dataframe (df ):
55
68
# GH17728
56
- df = pd .DataFrame ({'a' : [1 , 2 , 3 ]})
57
- blocks = df ._data .blocks
58
- values = np .arange (3 , dtype = 'int64' )
59
- custom_block = CustomBlock (values , placement = slice (1 , 2 ))
60
- blocks = blocks + (custom_block , )
61
- block_manager = BlockManager (blocks , [pd .Index (['a' , 'b' ]), df .index ])
62
- df = pd .DataFrame (block_manager )
63
69
res = pd .concat ([df , df ])
64
70
assert isinstance (res ._data .blocks [1 ], CustomBlock )
71
+
72
+
73
+ def test_concat_axis1 (df ):
74
+ # GH17954
75
+ df2 = pd .DataFrame ({'c' : [.1 , .2 , .3 ]})
76
+ res = pd .concat ([df , df2 ], axis = 1 )
77
+ assert isinstance (res ._data .blocks [1 ], CustomBlock )
0 commit comments