diff --git a/pandas/core/dtypes/concat.py b/pandas/core/dtypes/concat.py index 377ef7ad7e4f8..4aa74cdbbc2c0 100644 --- a/pandas/core/dtypes/concat.py +++ b/pandas/core/dtypes/concat.py @@ -175,7 +175,7 @@ def is_nonempty(x): return _concat_sparse(to_concat, axis=axis, typs=typs) extensions = [is_extension_array_dtype(x) for x in to_concat] - if any(extensions): + if any(extensions) and axis == 1: to_concat = [np.atleast_2d(x.astype('object')) for x in to_concat] if not nonempty: diff --git a/pandas/tests/extension/base/reshaping.py b/pandas/tests/extension/base/reshaping.py index cc78321dea7af..fe920a47ab740 100644 --- a/pandas/tests/extension/base/reshaping.py +++ b/pandas/tests/extension/base/reshaping.py @@ -64,6 +64,31 @@ def test_concat_mixed_dtypes(self, data): expected = pd.concat([df1.astype('object'), df2.astype('object')]) self.assert_frame_equal(result, expected) + result = pd.concat([df1['A'], df2['A']]) + expected = pd.concat([df1['A'].astype('object'), + df2['A'].astype('object')]) + self.assert_series_equal(result, expected) + + def test_concat_columns(self, data, na_value): + df1 = pd.DataFrame({'A': data[:3]}) + df2 = pd.DataFrame({'B': [1, 2, 3]}) + + expected = pd.DataFrame({'A': data[:3], 'B': [1, 2, 3]}) + result = pd.concat([df1, df2], axis=1) + self.assert_frame_equal(result, expected) + result = pd.concat([df1['A'], df2['B']], axis=1) + self.assert_frame_equal(result, expected) + + # non-aligned + df2 = pd.DataFrame({'B': [1, 2, 3]}, index=[1, 2, 3]) + expected = pd.DataFrame({ + 'A': data._from_sequence(list(data[:3]) + [na_value]), + 'B': [np.nan, 1, 2, 3]}) + result = pd.concat([df1, df2], axis=1) + self.assert_frame_equal(result, expected) + result = pd.concat([df1['A'], df2['B']], axis=1) + self.assert_frame_equal(result, expected) + def test_align(self, data, na_value): a = data[:3] b = data[2:5] diff --git a/pandas/tests/extension/category/test_categorical.py b/pandas/tests/extension/category/test_categorical.py index c34339c99322d..366666bf31f70 100644 --- a/pandas/tests/extension/category/test_categorical.py +++ b/pandas/tests/extension/category/test_categorical.py @@ -67,6 +67,10 @@ class TestConstructors(base.BaseConstructorsTests): class TestReshaping(base.BaseReshapingTests): + @pytest.mark.skip(reason="Unobserved categories preseved in concat.") + def test_concat_columns(self, data, na_value): + pass + @pytest.mark.skip(reason="Unobserved categories preseved in concat.") def test_align(self, data, na_value): pass