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,
)
| 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: |