From e154cdf9ebba47fd6618fb76be29876b6e6f3531 Mon Sep 17 00:00:00 2001 From: Harshith J Date: Fri, 6 Feb 2026 14:21:10 +0530 Subject: [PATCH 1/3] Fix masked array deserialization overflow for integer dtypes NumPy masked arrays default to a fill value of 999999, which cannot be represented by small integer dtypes such as uint8 or uint16. During distributed deserialization this raises a TypeError when reconstructing the masked array and may cause tasks to hang indefinitely. Ensure that fill values are cast safely to the target dtype, falling back to NumPy's default fill value when necessary. --- distributed/protocol/numpy.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/distributed/protocol/numpy.py b/distributed/protocol/numpy.py index b25d6a756f5..dccc8cc7db7 100644 --- a/distributed/protocol/numpy.py +++ b/distributed/protocol/numpy.py @@ -216,4 +216,12 @@ def deserialize_numpy_maskedarray(header, frames): if pickled_fv: fill_value = pickle.loads(fill_value) + # Ensure fill_value is compatible with dtype + if fill_value is not None: + try: + fill_value = np.array(fill_value, dtype=data.dtype).item() + except (OverflowError, ValueError, TypeError): + fill_value = np.ma.default_fill_value(data.dtype) + return np.ma.masked_array(data, mask=mask, fill_value=fill_value) + From 2243e71da3ee37867551b8f44a3f8276c72d9ff3 Mon Sep 17 00:00:00 2001 From: Harshith J Date: Fri, 6 Feb 2026 14:29:33 +0530 Subject: [PATCH 2/3] Update numpy.py --- distributed/protocol/numpy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distributed/protocol/numpy.py b/distributed/protocol/numpy.py index dccc8cc7db7..5921e611767 100644 --- a/distributed/protocol/numpy.py +++ b/distributed/protocol/numpy.py @@ -216,7 +216,7 @@ def deserialize_numpy_maskedarray(header, frames): if pickled_fv: fill_value = pickle.loads(fill_value) - # Ensure fill_value is compatible with dtype + # Ensure fill_value is compatible with dtype if fill_value is not None: try: fill_value = np.array(fill_value, dtype=data.dtype).item() From 886607499e7b3a0c875542d63bec11643cf270b0 Mon Sep 17 00:00:00 2001 From: Harshith J Date: Fri, 6 Feb 2026 14:33:47 +0530 Subject: [PATCH 3/3] Apply black formatting --- distributed/protocol/numpy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/distributed/protocol/numpy.py b/distributed/protocol/numpy.py index 5921e611767..43a0f13ada1 100644 --- a/distributed/protocol/numpy.py +++ b/distributed/protocol/numpy.py @@ -224,4 +224,3 @@ def deserialize_numpy_maskedarray(header, frames): fill_value = np.ma.default_fill_value(data.dtype) return np.ma.masked_array(data, mask=mask, fill_value=fill_value) -