@@ -1355,20 +1355,15 @@ def encode(self, variable: Variable, name: T_Name = None) -> Variable:
13551355
13561356 units = encoding .pop ("units" , None )
13571357 calendar = encoding .pop ("calendar" , None )
1358- dtype = encoding .pop ("dtype" , None )
1358+ dtype = encoding .get ("dtype" , None )
13591359
13601360 # in the case of packed data we need to encode into
13611361 # float first, the correct dtype will be established
13621362 # via CFScaleOffsetCoder/CFMaskCoder
1363- set_dtype_encoding = None
13641363 if "add_offset" in encoding or "scale_factor" in encoding :
1365- set_dtype_encoding = dtype
13661364 dtype = data .dtype if data .dtype .kind == "f" else "float64"
13671365 (data , units , calendar ) = encode_cf_datetime (data , units , calendar , dtype )
13681366
1369- # retain dtype for packed data
1370- if set_dtype_encoding is not None :
1371- safe_setitem (encoding , "dtype" , set_dtype_encoding , name = name )
13721367 safe_setitem (attrs , "units" , units , name = name )
13731368 safe_setitem (attrs , "calendar" , calendar , name = name )
13741369
@@ -1420,22 +1415,16 @@ def encode(self, variable: Variable, name: T_Name = None) -> Variable:
14201415 if np .issubdtype (variable .data .dtype , np .timedelta64 ):
14211416 dims , data , attrs , encoding = unpack_for_encoding (variable )
14221417
1423- dtype = encoding .pop ("dtype" , None )
1418+ dtype = encoding .get ("dtype" , None )
14241419
14251420 # in the case of packed data we need to encode into
14261421 # float first, the correct dtype will be established
14271422 # via CFScaleOffsetCoder/CFMaskCoder
1428- set_dtype_encoding = None
14291423 if "add_offset" in encoding or "scale_factor" in encoding :
1430- set_dtype_encoding = dtype
14311424 dtype = data .dtype if data .dtype .kind == "f" else "float64"
14321425
14331426 data , units = encode_cf_timedelta (data , encoding .pop ("units" , None ), dtype )
14341427
1435- # retain dtype for packed data
1436- if set_dtype_encoding is not None :
1437- safe_setitem (encoding , "dtype" , set_dtype_encoding , name = name )
1438-
14391428 safe_setitem (attrs , "units" , units , name = name )
14401429
14411430 return Variable (dims , data , attrs , encoding , fastpath = True )
0 commit comments