| 627 | return dataset |
| 628 | |
| 629 | def _to_dataset_whole( |
| 630 | self, name: Hashable = None, shallow_copy: bool = True |
| 631 | ) -> Dataset: |
| 632 | if name is None: |
| 633 | name = self.name |
| 634 | if name is None: |
| 635 | raise ValueError( |
| 636 | "unable to convert unnamed DataArray to a " |
| 637 | "Dataset without providing an explicit name" |
| 638 | ) |
| 639 | if name in self.coords: |
| 640 | raise ValueError( |
| 641 | "cannot create a Dataset from a DataArray with " |
| 642 | "the same name as one of its coordinates" |
| 643 | ) |
| 644 | # use private APIs for speed: this is called by _to_temp_dataset(), |
| 645 | # which is used in the guts of a lot of operations (e.g., reindex) |
| 646 | variables = self._coords.copy() |
| 647 | variables[name] = self.variable |
| 648 | if shallow_copy: |
| 649 | for k in variables: |
| 650 | variables[k] = variables[k].copy(deep=False) |
| 651 | indexes = self._indexes |
| 652 | |
| 653 | coord_names = set(self._coords) |
| 654 | return Dataset._construct_direct(variables, coord_names, indexes=indexes) |
| 655 | |
| 656 | def to_dataset( |
| 657 | self, |