concat doesn't work with mixed Series/DataFrames · Issue #2385 · pandas-dev/pandas (original) (raw)

concat thows an AssertionError when passed a ciollection of mixed Series and Dataframes e.g.

s1 = pd.TimeSeries(np.sin(linspace(0, 2*pi, 100)), index=pd.date_range('01-Jan-2013', periods=100, freq='H'))

s2 = pd.TimeSeries(np.cos(linspace(0, 2*pi, 100)), index=pd.date_range('01-Jan-2013', periods=100, freq='H'))

df = pd.DataFrame(np.cos(linspace(0, 2*pi, 100)).reshape(-1,1), index=pd.date_range('01-Jan-2013', periods=100, freq='H'))

In [23]: pd.concat([df,df], axis=1).shape Out[23]: (100, 2)

In [24]: pd.concat([s1,s2], axis=1).shape Out[24]: (100, 2)

In [25]: pd.concat([s1,s2,s1], axis=1).shape Out[25]: (100, 3)

In [26]: pd.concat([s1,df,s2], axis=1).shape Traceback (most recent call last):

File "", line 1, in pd.concat([s1,df,s2], axis=1).shape

File "c:\dev\code\pandas\pandas\tools\merge.py", line 881, in concat return op.get_result()

File "c:\dev\code\pandas\pandas\tools\merge.py", line 960, in get_result columns=self.new_axes[1])

File "c:\dev\code\pandas\pandas\core\frame.py", line 376, in init mgr = self._init_dict(data, index, columns, dtype=dtype)

File "c:\dev\code\pandas\pandas\core\frame.py", line 505, in _init_dict dtype=dtype)

File "c:\dev\code\pandas\pandas\core\frame.py", line 5181, in _arrays_to_mgr mgr = BlockManager(blocks, axes)

File "c:\dev\code\pandas\pandas\core\internals.py", line 499, in init self._verify_integrity()

File "c:\dev\code\pandas\pandas\core\internals.py", line 584, in _verify_integrity raise AssertionError('Block shape incompatible with manager')

AssertionError: Block shape incompatible with manager

In [27]: pd.version Out[27]: '0.10.0.dev-fbd77d5'