Skip to content

Commit 7d7474d

Browse files
committed
preserve boolean-dtype within encoding, adapt test
1 parent bcd8b6e commit 7d7474d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

xarray/coding/variables.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ def encode(self, variable: Variable, name: T_Name = None) -> Variable:
456456
def decode(self, variable: Variable, name: T_Name = None) -> Variable:
457457
if variable.attrs.get("dtype", False) == "bool":
458458
dims, data, attrs, encoding = unpack_for_decoding(variable)
459-
del attrs["dtype"]
459+
# overwrite encoding accordingly and remove from attrs
460+
encoding["dtype"] = attrs.pop("dtype")
460461
data = BoolTypeArray(data)
461462
return Variable(dims, data, attrs, encoding, fastpath=True)
462463
else:

xarray/tests/test_backends.py

+3
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,9 @@ def test_roundtrip_boolean_dtype(self) -> None:
630630
with self.roundtrip(original) as actual:
631631
assert_identical(original, actual)
632632
assert actual["x"].dtype == "bool"
633+
with self.roundtrip(actual) as actual2:
634+
assert_identical(original, actual2)
635+
assert actual2["x"].dtype == "bool"
633636

634637
def test_orthogonal_indexing(self) -> None:
635638
in_memory = create_test_data()

0 commit comments

Comments
 (0)