Skip to content
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

BUG: concat coercing arrow to object with null type #53702

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ Groupby/resample/rolling

Reshaping
^^^^^^^^^
- Bug in :func:`concat` coercing to ``object`` dtype when one column has ``pa.null()`` dtype (:issue:`53702`)
- Bug in :func:`crosstab` when ``dropna=False`` would not keep ``np.nan`` in the result (:issue:`10772`)
- Bug in :func:`merge_asof` raising ``KeyError`` for extension dtypes (:issue:`52904`)
- Bug in :func:`merge_asof` raising ``ValueError`` for data backed by read-only ndarrays (:issue:`53513`)
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2214,10 +2214,13 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None:
# Mirrors BaseMaskedDtype
from pandas.core.dtypes.cast import find_common_type

null_dtype = type(self)(pa.null())

new_dtype = find_common_type(
[
dtype.numpy_dtype if isinstance(dtype, ArrowDtype) else dtype
for dtype in dtypes
if dtype != null_dtype
]
)
if not isinstance(new_dtype, np.dtype):
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2872,6 +2872,15 @@ def test_conversion_large_dtypes_from_numpy_array(data, arrow_dtype):
tm.assert_extension_array_equal(result, expected)


def test_concat_null_array():
df = pd.DataFrame({"a": [None, None]}, dtype=ArrowDtype(pa.null()))
df2 = pd.DataFrame({"a": [0, 1]}, dtype="int64[pyarrow]")

result = pd.concat([df, df2], ignore_index=True)
expected = pd.DataFrame({"a": [None, None, 0, 1]}, dtype="int64[pyarrow]")
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize("pa_type", tm.ALL_INT_PYARROW_DTYPES + tm.FLOAT_PYARROW_DTYPES)
def test_describe_numeric_data(pa_type):
# GH 52470
Expand Down