@@ -1521,42 +1521,6 @@ def save_mfdataset(
1521
1521
)
1522
1522
1523
1523
1524
- def _validate_datatypes_for_zarr_append (zstore , dataset ):
1525
- """If variable exists in the store, confirm dtype of the data to append is compatible with
1526
- existing dtype.
1527
- """
1528
-
1529
- existing_vars = zstore .get_variables ()
1530
-
1531
- def check_dtype (vname , var ):
1532
- if (
1533
- vname not in existing_vars
1534
- or np .issubdtype (var .dtype , np .number )
1535
- or np .issubdtype (var .dtype , np .datetime64 )
1536
- or np .issubdtype (var .dtype , np .bool_ )
1537
- or var .dtype == object
1538
- ):
1539
- # We can skip dtype equality checks under two conditions: (1) if the var to append is
1540
- # new to the dataset, because in this case there is no existing var to compare it to;
1541
- # or (2) if var to append's dtype is known to be easy-to-append, because in this case
1542
- # we can be confident appending won't cause problems. Examples of dtypes which are not
1543
- # easy-to-append include length-specified strings of type `|S*` or `<U*` (where * is a
1544
- # positive integer character length). For these dtypes, appending dissimilar lengths
1545
- # can result in truncation of appended data. Therefore, variables which already exist
1546
- # in the dataset, and with dtypes which are not known to be easy-to-append, necessitate
1547
- # exact dtype equality, as checked below.
1548
- pass
1549
- elif not var .dtype == existing_vars [vname ].dtype :
1550
- raise ValueError (
1551
- f"Mismatched dtypes for variable { vname } between Zarr store on disk "
1552
- f"and dataset to append. Store has dtype { existing_vars [vname ].dtype } but "
1553
- f"dataset to append has dtype { var .dtype } ."
1554
- )
1555
-
1556
- for vname , var in dataset .data_vars .items ():
1557
- check_dtype (vname , var )
1558
-
1559
-
1560
1524
# compute=True returns ZarrStore
1561
1525
@overload
1562
1526
def to_zarr (
@@ -1721,17 +1685,16 @@ def to_zarr(
1721
1685
)
1722
1686
1723
1687
if mode in ["a" , "a-" , "r+" ]:
1724
- _validate_datatypes_for_zarr_append (zstore , dataset )
1725
- if append_dim is not None :
1688
+ existing_var_names = set (zstore . zarr_group . array_keys () )
1689
+ if append_dim is not None and append_dim not in existing_var_names :
1726
1690
existing_dims = zstore .get_dimensions ()
1727
1691
if append_dim not in existing_dims :
1728
1692
raise ValueError (
1729
1693
f"append_dim={ append_dim !r} does not match any existing "
1730
1694
f"dataset dimensions { existing_dims } "
1731
1695
)
1732
- existing_var_names = set (zstore .zarr_group .array_keys ())
1733
1696
for var_name in existing_var_names :
1734
- if var_name in encoding . keys () :
1697
+ if var_name in encoding :
1735
1698
raise ValueError (
1736
1699
f"variable { var_name !r} already exists, but encoding was provided"
1737
1700
)
0 commit comments