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

Method to_dataset

xarray/core/dataarray.py:656–696  ·  view source on GitHub ↗

Convert a DataArray to a Dataset. Parameters ---------- dim : Hashable, optional Name of the dimension on this array along which to split this array into separate variables. If not provided, this array is converted into a Dataset of one va

(
        self,
        dim: Hashable = None,
        *,
        name: Hashable = None,
        promote_attrs: bool = False,
    )

Source from the content-addressed store, hash-verified

654 return Dataset._construct_direct(variables, coord_names, indexes=indexes)
655
656 def to_dataset(
657 self,
658 dim: Hashable = None,
659 *,
660 name: Hashable = None,
661 promote_attrs: bool = False,
662 ) -> Dataset:
663 """Convert a DataArray to a Dataset.
664
665 Parameters
666 ----------
667 dim : Hashable, optional
668 Name of the dimension on this array along which to split this array
669 into separate variables. If not provided, this array is converted
670 into a Dataset of one variable.
671 name : Hashable, optional
672 Name to substitute for this array's name. Only valid if ``dim`` is
673 not provided.
674 promote_attrs : bool, default: False
675 Set to True to shallow copy attrs of DataArray to returned Dataset.
676
677 Returns
678 -------
679 dataset : Dataset
680 """
681 if dim is not None and dim not in self.dims:
682 raise TypeError(
683 f"{dim} is not a dim. If supplying a ``name``, pass as a kwarg."
684 )
685
686 if dim is not None:
687 if name is not None:
688 raise TypeError("cannot supply both dim and name arguments")
689 result = self._to_dataset_split(dim)
690 else:
691 result = self._to_dataset_whole(name)
692
693 if promote_attrs:
694 result.attrs = dict(self.attrs)
695
696 return result
697
698 @property
699 def name(self) -> Hashable | None:

Callers 15

to_netcdfMethod · 0.95
to_zarrMethod · 0.95
setUpMethod · 0.95
test_dotFunction · 0.95
test_recursive_tokenFunction · 0.95

Calls 2

_to_dataset_splitMethod · 0.95
_to_dataset_wholeMethod · 0.95