Skip to content

Commit 9f97f00

Browse files
committed
add explanatory comment for zarr append dtype checks
1 parent bd03da7 commit 9f97f00

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

xarray/backends/api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,15 @@ def check_dtype(vname, var):
12921292
or np.issubdtype(var.dtype, np.bool_)
12931293
or var.dtype == object
12941294
):
1295+
# We can skip dtype equality checks under two conditions: (1) if the var to append is
1296+
# new to the dataset, because in this case there is no existing var to compare it to;
1297+
# or (2) if var to append's dtype is known to be easy-to-append, because in this case
1298+
# we can be confident appending won't cause problems. Examples of dtypes which are not
1299+
# easy-to-append include length-specified strings of type `|S*` or `<U*` (where * is a
1300+
# positive integer character length). For these dtypes, appending dissimilar lengths
1301+
# can result in truncation of appended data. Therefore, variables which already exist
1302+
# in the dataset, and with dtypes which are not known to be easy-to-append, necessitate
1303+
# exact dtype equality, as checked below.
12951304
pass
12961305
elif not var.dtype == existing_vars[vname].dtype:
12971306
raise ValueError(

0 commit comments

Comments
 (0)