Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/src/whatsnew/3.16/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ v3.16 (13 Aug 2026)

- :fa:`code-pull-request` :pull:`7223`: :user:`trexfeathers` updated Iris to be compatible with Matplotlib version 3.11.

- :fa:`code-pull-request` :pull:`7262`: :user:`trexfeathers` updated Iris' metadata handling to be compatible with python-xxhash version 4.0 .



📚 Documentation
Expand Down
6 changes: 5 additions & 1 deletion lib/iris/common/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def hexdigest(item):
parts = (item.shape, xxh64_hexdigest(item))
item = str(parts)

# xxhash 4.0+: str is no longer accepted; encode to bytes first.
if isinstance(item, str):
item = item.encode()

try:
# Calculate single-shot hash to avoid allocating state on the heap
result = xxh64_hexdigest(item)
Expand All @@ -104,7 +108,7 @@ def hexdigest(item):
# string representation of the provided item instead, but
# also fold in the object type...
parts = (type(item), item)
result = xxh64_hexdigest(str(parts))
result = xxh64_hexdigest(str(parts).encode())

return result

Expand Down
8 changes: 4 additions & 4 deletions lib/iris/tests/unit/common/metadata/test_hexdigest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _setup(self):
@staticmethod
def _ndarray(value):
parts = str((value.shape, xxh64_hexdigest(value)))
return xxh64_hexdigest(parts)
return xxh64_hexdigest(parts.encode())

@staticmethod
def _masked(value):
Expand All @@ -32,11 +32,11 @@ def _masked(value):
xxh64_hexdigest(value.mask),
)
)
return xxh64_hexdigest(parts)
return xxh64_hexdigest(parts.encode())

def test_string(self):
value = "hello world"
self.hasher.update(value)
self.hasher.update(value.encode())
expected = self.hasher.hexdigest()
assert hexdigest(value) == expected

Expand Down Expand Up @@ -111,7 +111,7 @@ def test_masked_array_reshape_not_flat(self):
class TestNotBytesLikeObject:
def _expected(self, value):
parts = str((type(value), value))
return xxh64_hexdigest(parts)
return xxh64_hexdigest(parts.encode())

def test_int(self):
value = 123
Expand Down
Loading