html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue
https://github.com/pydata/xarray/issues/7403#issuecomment-1379504132,https://api.github.com/repos/pydata/xarray/issues/7403,1379504132,IC_kwDOAMm_X85SOZAE,39069044,2023-01-11T21:26:10Z,2023-01-11T21:26:10Z,CONTRIBUTOR,"> Personally, I'll make the argument that we should switch (carefully) from `-w` to `w` for the default case.
This makes sense in principal for consistency with other i/o methods, but I think could go very wrong in practice, especially for inexperienced users.
For example, a misplaced command of `ds.to_zarr(""gs://bucket_name"")` with default `mode=""w""` overwrites a user's entire bucket, and same thing for local storage. `to_netcdf` doesn't have the capability to `rm -r` a directory, so I would argue `to_zarr(mode=""w"")` is **much** more dangerous.
","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1512290017
https://github.com/pydata/xarray/issues/7403#issuecomment-1371540921,https://api.github.com/repos/pydata/xarray/issues/7403,1371540921,IC_kwDOAMm_X85RwA25,2443309,2023-01-04T23:24:46Z,2023-01-04T23:24:46Z,MEMBER,"I think the above example can be reduced to just:
```python
ds = xr.Dataset()
ds.to_zarr('test.zarr')
ds.to_zarr('test.zarr')
```
An interesting data point here is that `to_netcdf` defaults to `w` mode. And this works fine:
```python
ds = xr.Dataset()
ds.to_netcdf('test.nc')
ds.to_netcdf('test.nc')
```
Personally, I'll make the argument that we should switch (carefully) from `-w` to `w` for the default case.","{""total_count"": 1, ""+1"": 1, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,1512290017
https://github.com/pydata/xarray/issues/7403#issuecomment-1366882900,https://api.github.com/repos/pydata/xarray/issues/7403,1366882900,IC_kwDOAMm_X85RePpU,39069044,2022-12-28T19:53:05Z,2022-12-28T19:53:05Z,CONTRIBUTOR,"Your MCVE has `mode=""a""`, is that intentional? As far as defaults, what the docstring says is:
> The default mode is “a” if append_dim is set. Otherwise, it is “r+” if region is set and w- otherwise.
So without specifying mode, you get `mode=""w-""` which will not overwrite anything. With `mode=""a""`, your MCVE runs fine for me.
From using these a bit, my understanding is:
- `mode=""w-""` is the safe default that won't overwrite anything
- `mode=""w""` is only if you want to rewrite the **entire** zarr store, not for rewriting a subset of existing data
- `mode=""r+""` is for modifying values on some subset of the existing store specified by the index with `region`, but doesn't allow changing any dimension sizes
- `mode=""a""` is for completely overwriting existing variables*, appending new variables, or appending data along an existing dimension, paired with `append_dim`
\* I actually didn't realize this behavior until testing it out just now, but it is described in the docstring
","{""total_count"": 1, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 1}",,1512290017