Skip to content

Commit

Permalink
Allow appending datetime and boolean data variables to zarr stores.
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsukawa committed Nov 9, 2019
1 parent ffc3275 commit 2e91693
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Bug fixes
- Fix :py:meth:`xarray.core.groupby.DataArrayGroupBy.reduce` and
:py:meth:`xarray.core.groupby.DatasetGroupBy.reduce` when reducing over multiple dimensions.
(:issue:`3402`). By `Deepak Cherian <https://github.com/dcherian/>`_
- Allow appending datetime and bool data variables to zarr stores.
(:issue:`3480`). By `Akihiro Matsukawa <https://github.com/amatsukawa/>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
2 changes: 2 additions & 0 deletions xarray/backends/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,8 @@ def _validate_datatypes_for_zarr_append(dataset):
def check_dtype(var):
if (
not np.issubdtype(var.dtype, np.number)
and not np.issubdtype(var.dtype, np.datetime64)
and not np.issubdtype(var.dtype, np.bool)
and not coding.strings.is_unicode_dtype(var.dtype)
and not var.dtype == object
):
Expand Down
14 changes: 13 additions & 1 deletion xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def create_append_test_data(seed=None):
string_var = np.array(["ae", "bc", "df"], dtype=object)
string_var_to_append = np.array(["asdf", "asdfg"], dtype=object)
unicode_var = ["áó", "áó", "áó"]
datetime_var = np.array(['2019-01-01', '2019-01-02', '2019-01-03'], dtype='datetime64[s]')
datetime_var_to_append = np.array(['2019-01-04', '2019-01-05'], dtype='datetime64[s]')
bool_var = np.array([True, False, True], dtype=np.bool)
bool_var_to_append = np.array([False, True], dtype=np.bool)

ds = xr.Dataset(
data_vars={
Expand All @@ -102,6 +106,8 @@ def create_append_test_data(seed=None):
"unicode_var": xr.DataArray(
unicode_var, coords=[time1], dims=["time"]
).astype(np.unicode_),
"datetime_var": xr.DataArray(datetime_var, coords=[time1], dims=["time"]),
"bool_var": xr.DataArray(bool_var, coords=[time1], dims=["time"]),
}
)

Expand All @@ -118,6 +124,12 @@ def create_append_test_data(seed=None):
"unicode_var": xr.DataArray(
unicode_var[:nt2], coords=[time2], dims=["time"]
).astype(np.unicode_),
"datetime_var": xr.DataArray(
datetime_var_to_append, coords=[time2], dims=["time"]
),
"bool_var": xr.DataArray(
bool_var_to_append, coords=[time2], dims=["time"]
),
}
)

Expand All @@ -127,7 +139,7 @@ def create_append_test_data(seed=None):
rs.rand(3, 3, nt1 + nt2),
coords=[lat, lon, time1.append(time2)],
dims=["lat", "lon", "time"],
)
),
}
)

Expand Down

0 comments on commit 2e91693

Please sign in to comment.