Skip to content

Commit 1a42c6c

Browse files
committed
[minor] add comments
1 parent 0abe242 commit 1a42c6c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

doc/io.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ like ``'days'`` for ``timedelta64`` data. ``calendar`` should be one of the cale
437437
supported by netCDF4-python: 'standard', 'gregorian', 'proleptic_gregorian' 'noleap',
438438
'365_day', '360_day', 'julian', 'all_leap', '366_day'.
439439

440-
By default, xarray uses the 'proleptic_gregorian' calendar and units of the smallest time
440+
By default, xarray uses the ``'proleptic_gregorian'`` calendar and units of the smallest time
441441
difference between values, with a reference time of the first time value.
442442

443443

@@ -448,9 +448,9 @@ Coordinates
448448

449449
You can control the ``coordinates`` attribute written to disk by specifying ``DataArray.encoding["coordinates"]``.
450450
If not specified, xarray automatically sets ``DataArray.encoding["coordinates"]`` to a space-delimited list
451-
of names of coordinate variables that share dimensions with the variable.
451+
of names of coordinate variables that share dimensions with the ``DataArray`` being written.
452452
This allows perfect roundtripping of xarray datasets but may not be desirable.
453-
When an xarray dataset contains non-dimensional coordinates that do not share dimensions with any of
453+
When an xarray ``Dataset`` contains non-dimensional coordinates that do not share dimensions with any of
454454
the variables, these coordinate variable names are saved under a "global" ``"coordinates"`` attribute.
455455
This is not CF-compliant but again facilitates roundtripping of xarray datasets.
456456

xarray/conventions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,8 @@ def _encode_coordinates(variables, attributes, non_dim_coord_names):
662662
variable_coordinates[k].add(coord_name)
663663

664664
variables = {k: v.copy(deep=False) for k, v in variables.items()}
665+
666+
# keep track of variable names written to file under the "coordinates" attributes
665667
written_coords = set()
666668
for name, var in variables.items():
667669
encoding = var.encoding
@@ -676,14 +678,13 @@ def _encode_coordinates(variables, attributes, non_dim_coord_names):
676678
if "coordinates" in attrs:
677679
written_coords.update(attrs["coordinates"].split())
678680

679-
global_coordinates.difference_update(written_coords)
680-
681681
# These coordinates are not associated with any particular variables, so we
682682
# save them under a global 'coordinates' attribute so xarray can roundtrip
683683
# the dataset faithfully. Because this serialization goes beyond CF
684684
# conventions, only do it if necessary.
685685
# Reference discussion:
686686
# http://mailman.cgd.ucar.edu/pipermail/cf-metadata/2014/007571.html
687+
global_coordinates.difference_update(written_coords)
687688
if global_coordinates:
688689
attributes = dict(attributes)
689690
if "coordinates" in attributes:

0 commit comments

Comments
 (0)