Skip to content

Commit

Permalink
preserve boolean-dtype within encoding, adapt test
Browse files Browse the repository at this point in the history
  • Loading branch information
kmuehlbauer committed Mar 31, 2023
1 parent d464bba commit 2b63d92
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion xarray/coding/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,8 @@ def encode(self, variable: Variable, name: T_Name = None) -> Variable:
def decode(self, variable: Variable, name: T_Name = None) -> Variable:
if variable.attrs.get("dtype", False) == "bool":
dims, data, attrs, encoding = unpack_for_decoding(variable)
del attrs["dtype"]
# overwrite encoding accordingly and remove from attrs
encoding["dtype"] = attrs.pop("dtype")
data = BoolTypeArray(data)
return Variable(dims, data, attrs, encoding, fastpath=True)
else:
Expand Down
3 changes: 3 additions & 0 deletions xarray/tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ def test_roundtrip_boolean_dtype(self) -> None:
with self.roundtrip(original) as actual:
assert_identical(original, actual)
assert actual["x"].dtype == "bool"
with self.roundtrip(actual) as actual2:
assert_identical(original, actual2)
assert actual2["x"].dtype == "bool"

def test_orthogonal_indexing(self) -> None:
in_memory = create_test_data()
Expand Down

0 comments on commit 2b63d92

Please sign in to comment.