Skip to content

concat with ExtensionArray and object upcasting fails #20832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TomAugspurger opened this issue Apr 26, 2018 · 2 comments
Closed

concat with ExtensionArray and object upcasting fails #20832

TomAugspurger opened this issue Apr 26, 2018 · 2 comments
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@TomAugspurger
Copy link
Contributor

In [1]: import pandas as pd

In [2]: from pandas.tests.extension.decimal.array import *

In [3]: result = pd.concat([pd.Series(DecimalArray([decimal.Decimal(1)])), pd.Series([1])])

In [4]: result.shape
Out[4]: (2, 1)

and the repr fails, since things are messed up.

@TomAugspurger TomAugspurger added Reshaping Concat, Merge/Join, Stack/Unstack, Explode ExtensionArray Extending pandas with custom dtypes or arrays. labels Apr 26, 2018
@TomAugspurger
Copy link
Contributor Author

This can be fixed after the RC if things are tricky.

@jorisvandenbossche
Copy link
Member

I think the fix is:

diff --git a/pandas/core/dtypes/concat.py b/pandas/core/dtypes/concat.py
index 377ef7a..cf54212 100644
--- a/pandas/core/dtypes/concat.py
+++ b/pandas/core/dtypes/concat.py
@@ -176,7 +176,8 @@ def _concat_compat(to_concat, axis=0):
 
     extensions = [is_extension_array_dtype(x) for x in to_concat]
     if any(extensions):
-        to_concat = [np.atleast_2d(x.astype('object')) for x in to_concat]
+        if axis == 1:
+            to_concat = [np.atleast_2d(x.astype('object')) for x in to_concat]
 

can do a PR tomorrow morning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ExtensionArray Extending pandas with custom dtypes or arrays. Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

3 participants