Skip to content

Commit 5359d90

Browse files
committed
preserve boolean-dtype within encoding, adapt test
1 parent f1ff956 commit 5359d90

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

xarray/conventions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def decode_cf_variable(
400400
encoding.setdefault("dtype", original_dtype)
401401

402402
if "dtype" in attributes and attributes["dtype"] == "bool":
403-
del attributes["dtype"]
403+
encoding["dtype"] = attributes.pop("dtype")
404404
data = BoolTypeArray(data)
405405

406406
if not is_duck_dask_array(data):

xarray/tests/test_backends.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ def test_roundtrip_boolean_dtype(self) -> None:
632632
with self.roundtrip(original) as actual:
633633
assert_identical(original, actual)
634634
assert actual["x"].dtype == "bool"
635+
assert actual["x"].encoding["dtype"] == "bool"
635636

636637
def test_orthogonal_indexing(self) -> None:
637638
in_memory = create_test_data()

0 commit comments

Comments
 (0)