44
55from typing import TYPE_CHECKING
66
7- import guidata .io
87import numpy as np
98import numpy .ma as ma
109from qtpy import QtCore as QC
1110
11+ import guidata .io
1212from plotpy import io
1313from plotpy ._scaler import INTERP_NEAREST , _scale_rect , _scale_xy
1414from plotpy .config import _
2323from plotpy .styles .image import MaskedImageParam , MaskedXYImageParam
2424
2525if TYPE_CHECKING :
26- import guidata .io
2726 import qwt .scale_map
2827 from qtpy .QtCore import QRectF
2928 from qtpy .QtGui import QPainter
3029
30+ import guidata .io
3131 from plotpy .plot import BasePlot
3232
3333
@@ -150,10 +150,6 @@ def deserialize(
150150 def update_mask (self ) -> None :
151151 """Update mask"""
152152 if isinstance (self .data , np .ma .MaskedArray ):
153- # Casting filling_value to data dtype, otherwise this may raise an error
154- # in future versions of NumPy (at the time of writing, this raises a
155- # DeprecationWarning "NumPy will stop allowing conversion of out-of-bound
156- # Python integers to integer arrays.")
157153 filling_value = self .param .filling_value
158154 if filling_value is None or (
159155 isinstance (filling_value , float ) and np .isnan (filling_value )
@@ -164,8 +160,15 @@ def update_mask(self) -> None:
164160 else :
165161 val = np .array (np .nan , dtype = self .data .dtype )
166162 else :
163+ # If filling_value is out of bounds for data dtype, get the default
164+ # fill value for that dtype
165+ if np .issubdtype (self .data .dtype , np .integer ):
166+ info = np .iinfo (self .data .dtype )
167+ if filling_value < info .min or filling_value > info .max :
168+ # Using the default fill value thanks to the get_fill_value()
169+ # method of MaskedArray:
170+ filling_value = self .data .get_fill_value ()
167171 val = np .array (filling_value ).astype (self .data .dtype )
168-
169172 self .data .set_fill_value (val )
170173
171174 def set_mask (self , mask : ma .MaskedArray ) -> None :
0 commit comments