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

Method drop_vars

xarray/core/dataset.py:5789–5946  ·  view source on GitHub ↗

Drop variables from this dataset. Parameters ---------- names : Hashable or iterable of Hashable or Callable Name(s) of variables to drop. If a Callable, this object is passed as its only argument and its result is used. errors : {"raise", "ig

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

Source from the content-addressed store, hash-verified

5787 )
5788
5789 def drop_vars(
5790 self,
5791 names: str | Iterable[Hashable] | Callable[[Self], str | Iterable[Hashable]],
5792 *,
5793 errors: ErrorOptions = "raise",
5794 ) -> Self:
5795 """Drop variables from this dataset.
5796
5797 Parameters
5798 ----------
5799 names : Hashable or iterable of Hashable or Callable
5800 Name(s) of variables to drop. If a Callable, this object is passed as its
5801 only argument and its result is used.
5802 errors : {"raise", "ignore"}, default: "raise"
5803 If 'raise', raises a ValueError error if any of the variable
5804 passed are not in the dataset. If 'ignore', any given names that are in the
5805 dataset are dropped and no error is raised.
5806
5807 Examples
5808 --------
5809
5810 >>> dataset = xr.Dataset(
5811 ... {
5812 ... "temperature": (
5813 ... ["time", "latitude", "longitude"],
5814 ... [[[25.5, 26.3], [27.1, 28.0]]],
5815 ... ),
5816 ... "humidity": (
5817 ... ["time", "latitude", "longitude"],
5818 ... [[[65.0, 63.8], [58.2, 59.6]]],
5819 ... ),
5820 ... "wind_speed": (
5821 ... ["time", "latitude", "longitude"],
5822 ... [[[10.2, 8.5], [12.1, 9.8]]],
5823 ... ),
5824 ... },
5825 ... coords={
5826 ... "time": pd.date_range("2023-07-01", periods=1),
5827 ... "latitude": [40.0, 40.2],
5828 ... "longitude": [-75.0, -74.8],
5829 ... },
5830 ... )
5831 >>> dataset
5832 <xarray.Dataset> Size: 136B
5833 Dimensions: (time: 1, latitude: 2, longitude: 2)
5834 Coordinates:
5835 * time (time) datetime64[us] 8B 2023-07-01
5836 * latitude (latitude) float64 16B 40.0 40.2
5837 * longitude (longitude) float64 16B -75.0 -74.8
5838 Data variables:
5839 temperature (time, latitude, longitude) float64 32B 25.5 26.3 27.1 28.0
5840 humidity (time, latitude, longitude) float64 32B 65.0 63.8 58.2 59.6
5841 wind_speed (time, latitude, longitude) float64 32B 10.2 8.5 12.1 9.8
5842
5843 Drop the 'humidity' variable
5844
5845 >>> dataset.drop_vars(["humidity"])
5846 <xarray.Dataset> Size: 104B

Callers 15

dropMethod · 0.95
drop_dimsMethod · 0.95
test_apply_missing_dimsFunction · 0.95
test_coords_setMethod · 0.95
test_drop_dimsMethod · 0.95
shuffle_to_chunksMethod · 0.45
_drop_coordsMethod · 0.45
mapMethod · 0.45

Calls 9

is_scalarFunction · 0.90
emit_user_level_warningFunction · 0.90
namesFunction · 0.85
itemsMethod · 0.80
getMethod · 0.45
updateMethod · 0.45

Tested by 15

test_apply_missing_dimsFunction · 0.76
test_coords_setMethod · 0.76
test_drop_dimsMethod · 0.76
test_test_empty_cellMethod · 0.36
test_unify_chunksFunction · 0.36
test_argmin_maxFunction · 0.36
test_interpolate_nd_ndFunction · 0.36