Skip to content

Commit d193826

Browse files
committed
NestedExtensionArray.chunked_array
1 parent a932d18 commit d193826

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/nested_pandas/series/ext_array.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,11 @@ def _pyarrow_dtype(self) -> pa.DataType:
558558
"""PyArrow data type of the extension array"""
559559
return self._dtype.pyarrow_dtype
560560

561+
@property
562+
def chunked_array(self) -> pa.ChunkedArray:
563+
"""The underlying PyArrow ChunkedArray"""
564+
return self._chunked_array
565+
561566
@staticmethod
562567
def _validate(array: pa.ChunkedArray) -> None:
563568
"""Raises ValueError if the input array is not a struct array with all fields being

tests/nested_pandas/series/test_ext_array.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_from_sequence_with_arrow_array_and_dtype():
204204
type=pa_type,
205205
)
206206

207-
actual = NestedExtensionArray.from_sequence(pa_array, dtype=new_pa_type)._chunked_array
207+
actual = NestedExtensionArray.from_sequence(pa_array, dtype=new_pa_type).chunked_array
208208
desired = pa.chunked_array([pa_array.cast(new_pa_type)])
209209
# pyarrow doesn't convert pandas boxed missing values to nulls in nested arrays
210210
assert actual == desired
@@ -525,7 +525,7 @@ def test___setitem___series_of_dfs():
525525
)
526526
desired = NestedExtensionArray(desired_struct_array)
527527

528-
assert ext_array._chunked_array == desired._chunked_array
528+
assert ext_array.chunked_array == desired.chunked_array
529529
assert ext_array.equals(desired)
530530

531531

@@ -588,6 +588,21 @@ def test_series_built_raises(data):
588588
_array = NestedExtensionArray(pa_array)
589589

590590

591+
def test_chunked_array():
592+
"""Test that the .chunked_array property is correct."""
593+
struct_array = pa.StructArray.from_arrays(
594+
arrays=[
595+
pa.array([np.array([1, 2, 3]), np.array([1, 2, 1])]),
596+
pa.array([-np.array([4.0, 5.0, 6.0]), -np.array([3.0, 4.0, 5.0])]),
597+
],
598+
names=["a", "b"],
599+
)
600+
ext_array = NestedExtensionArray(struct_array)
601+
602+
# pyarrow returns a single bool for ==
603+
assert ext_array.chunked_array == pa.chunked_array(struct_array)
604+
605+
591606
def test_list_offsets_single_chunk():
592607
"""Test that the .list_offset property is correct for a single chunk."""
593608
struct_array = pa.StructArray.from_arrays(

0 commit comments

Comments
 (0)