MCPcopy Index your code
hub / github.com/pydata/xarray / DatasetCoordinates

Class DatasetCoordinates

xarray/core/coordinates.py:876–979  ·  view source on GitHub ↗

Dictionary like container for Dataset coordinates (variables + indexes). This collection can be passed directly to the :py:class:`~xarray.Dataset` and :py:class:`~xarray.DataArray` constructors via their `coords` argument. This will add both the coordinates variables and their index.

Source from the content-addressed store, hash-verified

874
875
876class DatasetCoordinates(Coordinates):
877 """Dictionary like container for Dataset coordinates (variables + indexes).
878
879 This collection can be passed directly to the :py:class:`~xarray.Dataset`
880 and :py:class:`~xarray.DataArray` constructors via their `coords` argument.
881 This will add both the coordinates variables and their index.
882 """
883
884 _data: Dataset
885
886 __slots__ = ("_data",)
887
888 def __init__(self, dataset: Dataset):
889 self._data = dataset
890
891 @property
892 def _names(self) -> set[Hashable]:
893 return self._data._coord_names
894
895 @property
896 def dims(self) -> Frozen[Hashable, int]:
897 # deliberately display all dims, not just those on coordinate variables - see https://github.com/pydata/xarray/issues/9466
898 return self._data.dims
899
900 @property
901 def dtypes(self) -> Frozen[Hashable, np.dtype]:
902 """Mapping from coordinate names to dtypes.
903
904 Cannot be modified directly, but is updated when adding new variables.
905
906 See Also
907 --------
908 Dataset.dtypes
909 """
910 return Frozen(
911 {
912 n: v.dtype
913 for n, v in self._data._variables.items()
914 if n in self._data._coord_names
915 }
916 )
917
918 @property
919 def variables(self) -> Mapping[Hashable, Variable]:
920 return Frozen(
921 {k: v for k, v in self._data.variables.items() if k in self._names}
922 )
923
924 def __getitem__(self, key: Hashable) -> DataArray:
925 if key in self._data.data_vars:
926 raise KeyError(key)
927 return self._data[key]
928
929 def to_dataset(self) -> Dataset:
930 """Convert these coordinates into a new Dataset"""
931
932 names = [name for name in self._data._variables if name in self._names]
933 return self._data._copy_listed(names)

Callers 1

coordsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…