Skip to content

Commit 2e91693

Browse files
committed
Allow appending datetime and boolean data variables to zarr stores.
1 parent ffc3275 commit 2e91693

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Bug fixes
8484
- Fix :py:meth:`xarray.core.groupby.DataArrayGroupBy.reduce` and
8585
:py:meth:`xarray.core.groupby.DatasetGroupBy.reduce` when reducing over multiple dimensions.
8686
(:issue:`3402`). By `Deepak Cherian <https://github.com/dcherian/>`_
87+
- Allow appending datetime and bool data variables to zarr stores.
88+
(:issue:`3480`). By `Akihiro Matsukawa <https://github.com/amatsukawa/>`_.
8789

8890
Documentation
8991
~~~~~~~~~~~~~

xarray/backends/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,8 @@ def _validate_datatypes_for_zarr_append(dataset):
12341234
def check_dtype(var):
12351235
if (
12361236
not np.issubdtype(var.dtype, np.number)
1237+
and not np.issubdtype(var.dtype, np.datetime64)
1238+
and not np.issubdtype(var.dtype, np.bool)
12371239
and not coding.strings.is_unicode_dtype(var.dtype)
12381240
and not var.dtype == object
12391241
):

xarray/tests/test_dataset.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def create_append_test_data(seed=None):
9090
string_var = np.array(["ae", "bc", "df"], dtype=object)
9191
string_var_to_append = np.array(["asdf", "asdfg"], dtype=object)
9292
unicode_var = ["áó", "áó", "áó"]
93+
datetime_var = np.array(['2019-01-01', '2019-01-02', '2019-01-03'], dtype='datetime64[s]')
94+
datetime_var_to_append = np.array(['2019-01-04', '2019-01-05'], dtype='datetime64[s]')
95+
bool_var = np.array([True, False, True], dtype=np.bool)
96+
bool_var_to_append = np.array([False, True], dtype=np.bool)
9397

9498
ds = xr.Dataset(
9599
data_vars={
@@ -102,6 +106,8 @@ def create_append_test_data(seed=None):
102106
"unicode_var": xr.DataArray(
103107
unicode_var, coords=[time1], dims=["time"]
104108
).astype(np.unicode_),
109+
"datetime_var": xr.DataArray(datetime_var, coords=[time1], dims=["time"]),
110+
"bool_var": xr.DataArray(bool_var, coords=[time1], dims=["time"]),
105111
}
106112
)
107113

@@ -118,6 +124,12 @@ def create_append_test_data(seed=None):
118124
"unicode_var": xr.DataArray(
119125
unicode_var[:nt2], coords=[time2], dims=["time"]
120126
).astype(np.unicode_),
127+
"datetime_var": xr.DataArray(
128+
datetime_var_to_append, coords=[time2], dims=["time"]
129+
),
130+
"bool_var": xr.DataArray(
131+
bool_var_to_append, coords=[time2], dims=["time"]
132+
),
121133
}
122134
)
123135

@@ -127,7 +139,7 @@ def create_append_test_data(seed=None):
127139
rs.rand(3, 3, nt1 + nt2),
128140
coords=[lat, lon, time1.append(time2)],
129141
dims=["lat", "lon", "time"],
130-
)
142+
),
131143
}
132144
)
133145

0 commit comments

Comments
 (0)