Skip to content

Commit f1d2bf7

Browse files
committed
remove dtype from encoding for datetime64/timedelta64 variables to prevent unnecessary casts
1 parent b08a9d8 commit f1d2bf7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

xarray/coding/times.py

+10
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,11 @@ def encode(self, variable: Variable, name: T_Name = None) -> Variable:
777777
safe_setitem(attrs, "units", units, name=name)
778778
safe_setitem(attrs, "calendar", calendar, name=name)
779779

780+
# remove dtype from encoding to prevent unnecessary casts
781+
# see GH #1064
782+
if "dtype" in encoding:
783+
encoding.pop("dtype")
784+
780785
return Variable(dims, data, attrs, encoding, fastpath=True)
781786
else:
782787
return variable
@@ -810,6 +815,11 @@ def encode(self, variable: Variable, name: T_Name = None) -> Variable:
810815
data, units = encode_cf_timedelta(data, encoding.pop("units", None))
811816
safe_setitem(attrs, "units", units, name=name)
812817

818+
# remove dtype from encoding to prevent unnecessary casts
819+
# see GH #1064
820+
if "dtype" in encoding:
821+
encoding.pop("dtype")
822+
813823
return Variable(dims, data, attrs, encoding, fastpath=True)
814824
else:
815825
return variable

0 commit comments

Comments
 (0)