Commits


Joris Van den Bossche authored and Antoine Pitrou committed 835de65411c
ARROW-13158: [Python] Fix StructScalar contains and repr with duplicate field names This PR does several small things: - Fix `__contains__` to not check the actual keys (and not rely on `__getitem__` since that also supports integers) - Add tests for the case of StructScalar with duplicate field names, and ensure some behaviours that already worked (`__getitem__` with integers, `__iter__`, `keys()`) - Changed `list(scalar)` (`__iter__`) to also return the keys for a "null" scalar (since we do allow `s["key"]` in that case, that seems most consistent?) - Changed the `repr` to use a tuple instead of dict representation. I know this just postpones a bit the `as_py()` discussion (should it return dict vs tuple?), but at least this ensures that the `repr` doesn't fail on the short term, and so you can inspect the object. - I added an explicit `items()` method (overriding the ones from Mapping), because the return value of this can in theory support duplicate fields, and this can be a way to get a list of tuples already. But, this doesn't fully follows the Mapping API as the return value is different (not a `dict_items` object). Closes #10591 from jorisvandenbossche/ARROW-13158 Authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com> Signed-off-by: Antoine Pitrou <antoine@python.org>