viirya commented on code in PR #50430:
URL: https://github.com/apache/arrow/pull/50430#discussion_r3640025863
##########
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:
Right — `ListScalar.as_py` delegates to `Array.to_pylist`, so that reference
wasn't independent for the `list<map>` case. Fixed in ffbb17c41a by writing the
expected rows out literally for all five cases, which keeps the oracle fully
independent of the code under test.
--
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]