Skip to content

Commit 86f0209

Browse files
committed
preserve boolean-dtype within encoding, adapt test
1 parent 3efeb16 commit 86f0209

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
@@ -422,7 +422,8 @@ def encode(self, variable: Variable, name: T_Name = None) -> Variable:
422422
def decode(self, variable: Variable, name: T_Name = None) -> Variable:
423423
if variable.attrs.get("dtype", False) == "bool":
424424
dims, data, attrs, encoding = unpack_for_decoding(variable)
425-
del attrs["dtype"]
425+
# overwrite encoding accordingly and remove from attrs
426+
encoding["dtype"] = attrs.pop("dtype")
426427
data = BoolTypeArray(data)
427428
return Variable(dims, data, attrs, encoding, fastpath=True)
428429
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)