You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
GH-47602: [Python] Make Schema hashable even when it has metadata (#47601)
### Rationale for this change
In Python, `pyarrow.Schema` before was not hashable when it has `metadata` set.
```
>>> import pyarrow
>>> schema = pyarrow.schema([], metadata={b"1": b"1"})
>>> hash(schema)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyarrow/types.pxi", line 2921, in pyarrow.lib.Schema.__hash__
TypeError: unhashable type: 'dict'
```
This is because the metadata (which is a dict) was tried to be hashed as-is, which doesn't work.
### What changes are included in this PR?
Slightly change how hashes are computed for Schema, by converting the `dict[str, str]` to the frozenset of key- and value tuples.
For reference, this is faster than computing the hash of a sorted tuple of key- and value tuples (https://stackoverflow.com/a/6014481/10070873).
### Are these changes tested?
Yes.
### Are there any user-facing changes?
Besides that `Schema` now correctly is hashable, no.
* GitHub Issue: #47602
Lead-authored-by: Jonas Dedden <[email protected]>
Co-authored-by: Alenka Frim <[email protected]>
Signed-off-by: Raúl Cumplido <[email protected]>
0 commit comments