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: DataFrame.explode doesn't work for pyarrow.large_list type #61105

Merged
merged 1 commit into from
Mar 11, 2025
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/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ Reshaping
^^^^^^^^^
- Bug in :func:`qcut` where values at the quantile boundaries could be incorrectly assigned (:issue:`59355`)
- Bug in :meth:`DataFrame.combine_first` not preserving the column order (:issue:`60427`)
- Bug in :meth:`DataFrame.explode` producing incorrect result for :class:`pyarrow.large_list` type (:issue:`61091`)
- Bug in :meth:`DataFrame.join` inconsistently setting result index name (:issue:`55815`)
- Bug in :meth:`DataFrame.join` when a :class:`DataFrame` with a :class:`MultiIndex` would raise an ``AssertionError`` when :attr:`MultiIndex.names` contained ``None``. (:issue:`58721`)
- Bug in :meth:`DataFrame.merge` where merging on a column containing only ``NaN`` values resulted in an out-of-bounds array access (:issue:`59421`)
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1938,7 +1938,10 @@ def _explode(self):
"""
# child class explode method supports only list types; return
# default implementation for non list types.
if not pa.types.is_list(self.dtype.pyarrow_dtype):
if not (
pa.types.is_list(self.dtype.pyarrow_dtype)
or pa.types.is_large_list(self.dtype.pyarrow_dtype)
):
return super()._explode()
values = self
counts = pa.compute.list_value_length(values._pa_array)
Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/series/methods/test_explode.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ def test_explode_scalars_can_ignore_index():


@pytest.mark.parametrize("ignore_index", [True, False])
def test_explode_pyarrow_list_type(ignore_index):
# GH 53602
@pytest.mark.parametrize("list_type", ["list_", "large_list"])
def test_explode_pyarrow_list_type(ignore_index, list_type):
# GH 53602, 61091
pa = pytest.importorskip("pyarrow")

data = [
Expand All @@ -156,7 +157,7 @@ def test_explode_pyarrow_list_type(ignore_index):
[2, 3],
None,
]
ser = pd.Series(data, dtype=pd.ArrowDtype(pa.list_(pa.int64())))
ser = pd.Series(data, dtype=pd.ArrowDtype(getattr(pa, list_type)(pa.int64())))
result = ser.explode(ignore_index=ignore_index)
expected = pd.Series(
data=[None, None, 1, None, 2, 3, None],
Expand Down
Loading