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

Method drop_sel

xarray/core/dataset.py:6060–6137  ·  view source on GitHub ↗

Drop index labels from this dataset. Parameters ---------- labels : mapping of hashable to Any Index labels to drop errors : {"raise", "ignore"}, default: "raise" If 'raise', raises a ValueError error if any of the index labels pas

(
        self, labels=None, *, errors: ErrorOptions = "raise", **labels_kwargs
    )

Source from the content-addressed store, hash-verified

6058 return self.drop_sel(labels, errors=errors)
6059
6060 def drop_sel(
6061 self, labels=None, *, errors: ErrorOptions = "raise", **labels_kwargs
6062 ) -> Self:
6063 """Drop index labels from this dataset.
6064
6065 Parameters
6066 ----------
6067 labels : mapping of hashable to Any
6068 Index labels to drop
6069 errors : {"raise", "ignore"}, default: "raise"
6070 If 'raise', raises a ValueError error if
6071 any of the index labels passed are not
6072 in the dataset. If 'ignore', any given labels that are in the
6073 dataset are dropped and no error is raised.
6074 **labels_kwargs : {dim: label, ...}, optional
6075 The keyword arguments form of ``dim`` and ``labels``
6076
6077 Returns
6078 -------
6079 dropped : Dataset
6080
6081 Examples
6082 --------
6083 >>> data = np.arange(6).reshape(2, 3)
6084 >>> labels = ["a", "b", "c"]
6085 >>> ds = xr.Dataset({"A": (["x", "y"], data), "y": labels})
6086 >>> ds
6087 <xarray.Dataset> Size: 60B
6088 Dimensions: (x: 2, y: 3)
6089 Coordinates:
6090 * y (y) <U1 12B 'a' 'b' 'c'
6091 Dimensions without coordinates: x
6092 Data variables:
6093 A (x, y) int64 48B 0 1 2 3 4 5
6094 >>> ds.drop_sel(y=["a", "c"])
6095 <xarray.Dataset> Size: 20B
6096 Dimensions: (x: 2, y: 1)
6097 Coordinates:
6098 * y (y) <U1 4B 'b'
6099 Dimensions without coordinates: x
6100 Data variables:
6101 A (x, y) int64 16B 1 4
6102 >>> ds.drop_sel(y="b")
6103 <xarray.Dataset> Size: 40B
6104 Dimensions: (x: 2, y: 2)
6105 Coordinates:
6106 * y (y) <U1 8B 'a' 'c'
6107 Dimensions without coordinates: x
6108 Data variables:
6109 A (x, y) int64 32B 0 2 3 5
6110 """
6111 from xarray.core.dataarray import DataArray
6112
6113 if errors not in ["raise", "ignore"]:
6114 raise ValueError('errors must be either "raise" or "ignore"')
6115
6116 labels = either_dict_or_kwargs(labels, labels_kwargs, "drop_sel")
6117

Callers 8

dropMethod · 0.95
test_drop_selMethod · 0.95
test_drop_selMethod · 0.45

Calls 4

either_dict_or_kwargsFunction · 0.90
itemsMethod · 0.80
get_indexMethod · 0.80
dropMethod · 0.45

Tested by 7

test_drop_selMethod · 0.76
test_drop_selMethod · 0.36