AlenkaF commented on code in PR #45818: URL: https://github.com/apache/arrow/pull/45818#discussion_r2063547272
########## python/pyarrow/scalar.pxi: ########## @@ -1064,13 +1126,26 @@ cdef class MapScalar(ListScalar): def __getitem__(self, i): """ - Return the value at the given index. + Return the value at the given index or key. """ + arr = self.values if arr is None: - raise IndexError(i) - dct = arr[_normalize_index(i, len(arr))] - return (dct[self.type.key_field.name], dct[self.type.item_field.name]) + raise IndexError(i) if isinstance(i, int) else KeyError(i) + + key_field = self.type.key_field.name + item_field = self.type.item_field.name + + if isinstance(i, int): + if arr is None: + raise IndexError(i) + dct = arr[_normalize_index(i, len(arr))] + return (dct[key_field], dct[item_field]) + else: + for dct in arr: + if dct[key_field].as_py() == i: + return dct[item_field] + raise KeyError(i) Review Comment: Never mind, got it! :) I would then suggest a bit of a code shift - will create a separate suggestion comment. -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org