@@ -304,28 +304,28 @@ def _choose_float_dtype(
304304 # see https://github.com/pydata/xarray/issues/5597#issuecomment-879561954
305305 scale_factor = mapping .get ("scale_factor" )
306306 add_offset = mapping .get ("add_offset" )
307- if scale_factor or add_offset :
307+ if scale_factor is not None or add_offset is not None :
308308 # get the type from scale_factor/add_offset to determine
309309 # the needed floating point type
310- if scale_factor :
310+ if scale_factor is not None :
311311 scale_type = type (scale_factor )
312- if add_offset :
312+ if add_offset is not None :
313313 offset_type = type (add_offset )
314314 # CF conforming, both scale_factor and add-offset are given and
315- # of same floating point type
315+ # of same floating point type (float32/64)
316316 if (
317- add_offset
318- and scale_factor
317+ add_offset is not None
318+ and scale_factor is not None
319319 and offset_type == scale_type
320- and np .issubdtype ( scale_type , np .floating )
320+ and scale_type in [ np .float32 , np .float64 ]
321321 ):
322322 return np .dtype (scale_type ).type
323323 # Not CF conforming and add_offset given:
324324 # A scale factor is entirely safe (vanishing into the mantissa),
325325 # but a large integer offset could lead to loss of precision.
326326 # Sensitivity analysis can be tricky, so we just use a float64
327327 # if there's any offset at all - better unoptimised than wrong!
328- if add_offset :
328+ if add_offset is not None :
329329 return np .float64
330330 # return float32 in other cases where only scale_factor is given
331331 return np .float32
0 commit comments