MCPcopy
hub / github.com/pydata/xarray / drop_indexes

Method drop_indexes

xarray/core/dataset.py:5948–6002  ·  view source on GitHub ↗

Drop the indexes assigned to the given coordinates. Parameters ---------- coord_names : hashable or iterable of hashable Name(s) of the coordinate(s) for which to drop the index. errors : {"raise", "ignore"}, default: "raise" If 'raise', raise

(
        self,
        coord_names: Hashable | Iterable[Hashable],
        *,
        errors: ErrorOptions = "raise",
    )

Source from the content-addressed store, hash-verified

5946 )
5947
5948 def drop_indexes(
5949 self,
5950 coord_names: Hashable | Iterable[Hashable],
5951 *,
5952 errors: ErrorOptions = "raise",
5953 ) -> Self:
5954 """Drop the indexes assigned to the given coordinates.
5955
5956 Parameters
5957 ----------
5958 coord_names : hashable or iterable of hashable
5959 Name(s) of the coordinate(s) for which to drop the index.
5960 errors : {"raise", "ignore"}, default: "raise"
5961 If 'raise', raises a ValueError error if any of the coordinates
5962 passed have no index or are not in the dataset.
5963 If 'ignore', no error is raised.
5964
5965 Returns
5966 -------
5967 dropped : Dataset
5968 A new dataset with dropped indexes.
5969
5970 """
5971 # the Iterable check is required for mypy
5972 if is_scalar(coord_names) or not isinstance(coord_names, Iterable):
5973 coord_names = {coord_names}
5974 else:
5975 coord_names = set(coord_names)
5976
5977 if errors == "raise":
5978 invalid_coords = coord_names - self._coord_names
5979 if invalid_coords:
5980 raise ValueError(
5981 f"The coordinates {tuple(invalid_coords)} are not found in the "
5982 f"dataset coordinates {tuple(self.coords.keys())}"
5983 )
5984
5985 unindexed_coords = set(coord_names) - set(self._indexes)
5986 if unindexed_coords:
5987 raise ValueError(
5988 f"those coordinates do not have an index: {unindexed_coords}"
5989 )
5990
5991 assert_no_index_corrupted(self.xindexes, coord_names, action="remove index(es)")
5992
5993 variables = {}
5994 for name, var in self._variables.items():
5995 if name in coord_names:
5996 variables[name] = var.to_base_variable()
5997 else:
5998 variables[name] = var
5999
6000 indexes = {k: v for k, v in self._indexes.items() if k not in coord_names}
6001
6002 return self._replace(variables=variables, indexes=indexes)
6003
6004 def drop(
6005 self,

Calls 6

_replaceMethod · 0.95
is_scalarFunction · 0.90
keysMethod · 0.80
itemsMethod · 0.80
to_base_variableMethod · 0.80