Skip to content

Commit 1161f7b

Browse files
Document how to find unlimited_dims via encoding (#11618)
* Document how to check unlimited_dims in encoding * [pre-commit.ci] auto fixes from pre-commit.com hooks * Fix unlimited_dims example and formatting * Set unlimited_dims when writing example file * Add whats-new entry for unlimited_dims docs --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 17c982a commit 1161f7b

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎doc/user-guide/io.md‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ ds = xr.Dataset(
358358
},
359359
)
360360
361-
ds.to_netcdf(nc_filename)
361+
ds.to_netcdf(nc_filename, unlimited_dims=["y"])
362362
```
363363

364364
By default, the file is saved as netCDF4 (assuming netCDF4-Python is
@@ -510,6 +510,19 @@ ds_disk["y"].encoding
510510
ds_disk.encoding
511511
```
512512

513+
One key piece of information you can find in the encoding is whether a
514+
dimension is unlimited. Unlimited dimensions can grow in size, and are
515+
commonly used for a dimension like `time` that is appended to over
516+
time:
517+
518+
```{code-cell}
519+
ds_disk.encoding["unlimited_dims"]
520+
```
521+
522+
This information can also be set explicitly when writing a file with
523+
{py:meth}`Dataset.to_netcdf` using the `unlimited_dims` keyword
524+
argument.
525+
513526
Note that all operations that manipulate variables other than indexing
514527
will remove encoding information.
515528

‎doc/whats-new.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ Documentation
172172
- Migrated from nbsphinx/jupyter-execute to myst-nb (:issue:`7924`, :pull:`11456`).
173173
By `Nick Hodgskin <https://github.com/VeckoTheGecko>`_.
174174

175+
- Added an example to the netCDF section of the IO user guide showing how to
176+
check which dimensions are unlimited via ``Dataset.encoding``
177+
(:issue:`7517`, :pull:`11618`).
178+
By `Anirban Mandal <https://github.com/CoderAnirban71>`_.
179+
175180

176181
Internal Changes
177182
~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)