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

Method drop_dims

xarray/core/dataset.py:6204–6243  ·  view source on GitHub ↗

Drop dimensions and associated variables from this dataset. Parameters ---------- drop_dims : str or Iterable of Hashable Dimension or dimensions to drop. errors : {"raise", "ignore"}, default: "raise" If 'raise', raises a ValueError error if

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

Source from the content-addressed store, hash-verified

6202 return ds
6203
6204 def drop_dims(
6205 self,
6206 drop_dims: str | Iterable[Hashable],
6207 *,
6208 errors: ErrorOptions = "raise",
6209 ) -> Self:
6210 """Drop dimensions and associated variables from this dataset.
6211
6212 Parameters
6213 ----------
6214 drop_dims : str or Iterable of Hashable
6215 Dimension or dimensions to drop.
6216 errors : {"raise", "ignore"}, default: "raise"
6217 If 'raise', raises a ValueError error if any of the
6218 dimensions passed are not in the dataset. If 'ignore', any given
6219 dimensions that are in the dataset are dropped and no error is raised.
6220
6221 Returns
6222 -------
6223 obj : Dataset
6224 The dataset without the given dimensions (or any variables
6225 containing those dimensions).
6226 """
6227 if errors not in ["raise", "ignore"]:
6228 raise ValueError('errors must be either "raise" or "ignore"')
6229
6230 if isinstance(drop_dims, str) or not isinstance(drop_dims, Iterable):
6231 drop_dims = {drop_dims}
6232 else:
6233 drop_dims = set(drop_dims)
6234
6235 if errors == "raise":
6236 missing_dims = drop_dims - set(self.dims)
6237 if missing_dims:
6238 raise ValueError(
6239 f"Dimensions {tuple(missing_dims)} not found in data dimensions {tuple(self.dims)}"
6240 )
6241
6242 drop_vars = {k for k, v in self._variables.items() if set(v.dims) & drop_dims}
6243 return self.drop_vars(drop_vars)
6244
6245 @deprecate_dims
6246 def transpose(

Callers 4

test_drop_dimsMethod · 0.95
_temp_dataarrayFunction · 0.45
dataMethod · 0.45

Calls 2

drop_varsMethod · 0.95
itemsMethod · 0.80

Tested by 3

test_drop_dimsMethod · 0.76
dataMethod · 0.36