Copilot commented on code in PR #50430:
URL: https://github.com/apache/arrow/pull/50430#discussion_r3640009469
##########
python/pyarrow/tests/test_array.py:
##########
@@ -523,6 +523,71 @@ def test_to_pylist_bulk_paths():
dup.to_pylist()
+def test_to_pylist_maps_as_pydicts():
+ # GH-50429: maps_as_pydicts converts through the scalar-free path; the
+ # semantics must match MapScalar.as_py exactly.
+ map_type = pa.map_(pa.string(), pa.int32())
+ flat = pa.array(
+ [None, [("k1", 1), ("k2", None)], []], type=map_type)
+ arrays = [
+ flat,
+ flat.slice(1),
+ pa.array([[[('k', 1)], None], None], type=pa.list_(map_type)),
+ pa.array([[("o", [("i", 5)])]],
+ type=pa.map_(pa.string(), map_type)),
+ pa.array([{"m": [("k", 1)]}, None],
+ type=pa.struct([("m", map_type)])),
+ ]
+ for arr in arrays:
+ expected = [x.as_py(maps_as_pydicts="strict") for x in arr]
+ assert arr.to_pylist(maps_as_pydicts="strict") == expected
+
Review Comment:
In this test loop, `expected = [x.as_py(... ) for x in arr]` is intended as
a scalar-based reference, but for the `list<map<...>>` case
`ListScalar.as_py()` delegates to the array-level
`to_pylist(maps_as_pydicts=...)`. That makes `expected` depend on the same
implementation under test and can hide regressions in nested propagation.
Consider computing `expected` for list-of-map explicitly by iterating nested
MapScalars so it stays independent of `Array.to_pylist()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]