jonded94 commented on code in PR #47454:
URL: https://github.com/apache/arrow/pull/47454#discussion_r2405730488
##########
python/pyarrow/scalar.pxi:
##########
@@ -1173,7 +1173,7 @@ cdef class MapScalar(ListScalar, Mapping):
if not maps_as_pydicts:
return list(self)
result_dict = {}
- for key, value in self:
+ for key, value in zip(self.keys(),
self.values.field(self.type.item_field.name)):
Review Comment:
Not the author of the MR, but the previous `for key, value in self` would
result in a call of `self.__iter__()`.
That thing is defined above this function, and does yield `(k.as_py(),
v.as_py())` directly. So it's *hardcoded* to the default `maps_as_pydicts`
behaviour, which is incompatible to what we want here. The values, if they
happen to be map types, basically would be yielded in the non-dict way (as the
list of (key, value) tuples).
It's also not possible to adjust the `__iter__()` function because by
definition it has to have no parameters, so it has to be opinionated in some
sense about how to handle maps.
So in this case, we have to loop over the keys and values manually and
*then* do the `as_py()` call on the value type with the correct
`maps_as_pydicts` parameter ourselves.
--
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]