Skip to content

Commit 1d925b9

Browse files
author
Guido Imperiale
committed
Fix distributed.Client.compute applied to DataArray
1 parent 1757dff commit 1d925b9

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

doc/whats-new.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ Bug fixes
5555
due to a ``datetime`` issue in NumPy (:issue:`2334`).
5656
By `Graham Inggs <https://github.com/ginggs>`_.
5757
- Fixed bug in ``combine_by_coords()`` causing a `ValueError` if the input had
58-
an unused dimension with coordinates which were not monotonic (:issue`3150`).
58+
an unused dimension with coordinates which were not monotonic (:issue:`3150`).
5959
By `Tom Nicholas <http://github.com/TomNicholas>`_.
60+
- Fixed crash when applying ``distributed.Client.compute()`` to a DataArray
61+
(:issue:`3171`). By `Guido Imperiale <https://github.com/crusaderky>`_.
62+
6063

6164
.. _whats-new.0.12.3:
6265

xarray/core/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,22 @@ def __repr__(self: Any) -> str:
462462
class ReprObject:
463463
"""Object that prints as the given value, for use with sentinel values.
464464
"""
465+
__slots__ = ('_value', )
466+
465467
def __init__(self, value: str):
466468
self._value = value
467469

468470
def __repr__(self) -> str:
469471
return self._value
470472

473+
def __eq__(self, other) -> bool:
474+
if isinstance(other, ReprObject):
475+
return self._value == other._value
476+
return False
477+
478+
def __hash__(self) -> int:
479+
return hash((ReprObject, self._value))
480+
471481

472482
@contextlib.contextmanager
473483
def close_on_error(f):

xarray/tests/test_utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,19 @@ def test_repr_object():
181181
assert repr(obj) == 'foo'
182182

183183

184+
def test_repr_object_magic_methods():
185+
o1 = utils.ReprObject('foo')
186+
o2 = utils.ReprObject('foo')
187+
o3 = utils.ReprObject('bar')
188+
o4 = 'foo'
189+
assert o1 == o2
190+
assert o1 != o3
191+
assert o1 != o4
192+
assert hash(o1) == hash(o2)
193+
assert hash(o1) != hash(o3)
194+
assert hash(o1) != hash(o4)
195+
196+
184197
def test_is_remote_uri():
185198
assert utils.is_remote_uri('http://example.com')
186199
assert utils.is_remote_uri('https://example.com')

0 commit comments

Comments
 (0)