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

Method sel

xarray/core/dataset.py:2944–3034  ·  view source on GitHub ↗

Returns a new dataset with each array indexed by tick labels along the specified dimension(s). In contrast to `Dataset.isel`, indexers for this method should use labels instead of integers. Under the hood, this method is powered by using pandas's powerful Index

(
        self,
        indexers: Mapping[Any, Any] | None = None,
        method: str | None = None,
        tolerance: int | float | Iterable[int | float] | None = None,
        drop: bool = False,
        **indexers_kwargs: Any,
    )

Source from the content-addressed store, hash-verified

2942 return self._replace_with_new_dims(variables, coord_names, indexes=indexes)
2943
2944 def sel(
2945 self,
2946 indexers: Mapping[Any, Any] | None = None,
2947 method: str | None = None,
2948 tolerance: int | float | Iterable[int | float] | None = None,
2949 drop: bool = False,
2950 **indexers_kwargs: Any,
2951 ) -> Self:
2952 """Returns a new dataset with each array indexed by tick labels
2953 along the specified dimension(s).
2954
2955 In contrast to `Dataset.isel`, indexers for this method should use
2956 labels instead of integers.
2957
2958 Under the hood, this method is powered by using pandas's powerful Index
2959 objects. This makes label based indexing essentially just as fast as
2960 using integer indexing.
2961
2962 It also means this method uses pandas's (well documented) logic for
2963 indexing. This means you can use string shortcuts for datetime indexes
2964 (e.g., '2000-01' to select all values in January 2000). It also means
2965 that slices are treated as inclusive of both the start and stop values,
2966 unlike normal Python indexing.
2967
2968 Parameters
2969 ----------
2970 indexers : dict, optional
2971 A dict with keys matching dimensions and values given
2972 by scalars, slices or arrays of tick labels. For dimensions with
2973 multi-index, the indexer may also be a dict-like object with keys
2974 matching index level names.
2975 If DataArrays are passed as indexers, xarray-style indexing will be
2976 carried out. See :ref:`indexing` for the details.
2977 One of indexers or indexers_kwargs must be provided.
2978 method : {None, "nearest", "pad", "ffill", "backfill", "bfill"}, optional
2979 Method to use for inexact matches:
2980
2981 * None (default): only exact matches
2982 * pad / ffill: propagate last valid index value forward
2983 * backfill / bfill: propagate next valid index value backward
2984 * nearest: use nearest valid index value
2985 tolerance : optional
2986 Maximum distance between original and new labels for inexact
2987 matches. The values of the index at the matching locations must
2988 satisfy the equation ``abs(index[indexer] - target) <= tolerance``.
2989 drop : bool, optional
2990 If ``drop=True``, drop coordinates variables in `indexers` instead
2991 of making them scalar.
2992 **indexers_kwargs : {dim: indexer, ...}, optional
2993 The keyword arguments form of ``indexers``.
2994 One of indexers or indexers_kwargs must be provided.
2995
2996 Returns
2997 -------
2998 obj : Dataset
2999 A new Dataset with the same contents as this dataset, except each
3000 variable and dimension is indexed by the appropriate indexers.
3001 If indexer DataArrays have coordinates that do not conflict with

Callers 10

test_selMethod · 0.95
test_sel_dropMethod · 0.95
test_sel_drop_mindexMethod · 0.95
test_sel_fancyMethod · 0.95
test_selMethod · 0.95

Calls 6

iselMethod · 0.95
either_dict_or_kwargsFunction · 0.90
map_index_queriesFunction · 0.90
itemsMethod · 0.80
as_tupleMethod · 0.80
_overwrite_indexesMethod · 0.45

Tested by 10

test_selMethod · 0.76
test_sel_dropMethod · 0.76
test_sel_drop_mindexMethod · 0.76
test_sel_fancyMethod · 0.76
test_selMethod · 0.76