diff --git a/xarray/backends/api.py b/xarray/backends/api.py index 199516116b0..d23594fc675 100644 --- a/xarray/backends/api.py +++ b/xarray/backends/api.py @@ -677,7 +677,7 @@ def open_dataarray( "then select the variable you want." ) else: - data_array, = dataset.data_vars.values() + (data_array,) = dataset.data_vars.values() data_array._file_obj = dataset._file_obj diff --git a/xarray/core/alignment.py b/xarray/core/alignment.py index 1a33cb955c3..41ff5a3b32d 100644 --- a/xarray/core/alignment.py +++ b/xarray/core/alignment.py @@ -252,7 +252,7 @@ def align( if not indexes and len(objects) == 1: # fast path for the trivial case - obj, = objects + (obj,) = objects return (obj.copy(deep=copy),) all_indexes = defaultdict(list) diff --git a/xarray/core/combine.py b/xarray/core/combine.py index 19c327ec597..3308dcef285 100644 --- a/xarray/core/combine.py +++ b/xarray/core/combine.py @@ -954,7 +954,7 @@ def _auto_concat( "supply the ``concat_dim`` argument " "explicitly" ) - dim, = concat_dims + (dim,) = concat_dims return concat( datasets, dim=dim, diff --git a/xarray/core/computation.py b/xarray/core/computation.py index 1393d76f283..2ab2ab78416 100644 --- a/xarray/core/computation.py +++ b/xarray/core/computation.py @@ -145,7 +145,7 @@ def result_name(objects: list) -> Any: names = {getattr(obj, "name", _DEFAULT_NAME) for obj in objects} names.discard(_DEFAULT_NAME) if len(names) == 1: - name, = names + (name,) = names else: name = None return name @@ -187,7 +187,7 @@ def build_output_coords( if len(coords_list) == 1 and not exclude_dims: # we can skip the expensive merge - unpacked_coords, = coords_list + (unpacked_coords,) = coords_list merged_vars = dict(unpacked_coords.variables) else: # TODO: save these merged indexes, instead of re-computing them later @@ -237,7 +237,7 @@ def apply_dataarray_vfunc( for variable, coords in zip(result_var, result_coords) ) else: - coords, = result_coords + (coords,) = result_coords out = DataArray(result_var, coords, name=name, fastpath=True) return out @@ -384,7 +384,7 @@ def apply_dataset_vfunc( if signature.num_outputs > 1: out = tuple(_fast_dataset(*args) for args in zip(result_vars, list_of_coords)) else: - coord_vars, = list_of_coords + (coord_vars,) = list_of_coords out = _fast_dataset(result_vars, coord_vars) if keep_attrs and isinstance(first_obj, Dataset): diff --git a/xarray/core/concat.py b/xarray/core/concat.py index bcab136de8d..0d19990bdd0 100644 --- a/xarray/core/concat.py +++ b/xarray/core/concat.py @@ -148,10 +148,10 @@ def _calc_concat_dim_coord(dim): dim = dim_name elif not isinstance(dim, DataArray): coord = as_variable(dim).to_index_variable() - dim, = coord.dims + (dim,) = coord.dims else: coord = dim - dim, = coord.dims + (dim,) = coord.dims return dim, coord diff --git a/xarray/core/dataarray.py b/xarray/core/dataarray.py index 33dcad13204..0c220acaee0 100644 --- a/xarray/core/dataarray.py +++ b/xarray/core/dataarray.py @@ -616,7 +616,7 @@ def _level_coords(self) -> Dict[Hashable, Hashable]: if var.ndim == 1 and isinstance(var, IndexVariable): level_names = var.level_names if level_names is not None: - dim, = var.dims + (dim,) = var.dims level_coords.update({lname: dim for lname in level_names}) return level_coords diff --git a/xarray/core/dataset.py b/xarray/core/dataset.py index 3ca9dd14fae..05d9772cb7a 100644 --- a/xarray/core/dataset.py +++ b/xarray/core/dataset.py @@ -4066,7 +4066,7 @@ def reduce( if len(reduce_dims) == 1: # unpack dimensions for the benefit of functions # like np.argmin which can't handle tuple arguments - reduce_dims, = reduce_dims + (reduce_dims,) = reduce_dims elif len(reduce_dims) == var.ndim: # prefer to aggregate over axis=None rather than # axis=(0, 1) if they will be equivalent, because diff --git a/xarray/core/groupby.py b/xarray/core/groupby.py index c3f712b31ac..353566eb345 100644 --- a/xarray/core/groupby.py +++ b/xarray/core/groupby.py @@ -321,7 +321,7 @@ def __init__( raise ValueError("`group` must have a name") group, obj, stacked_dim, inserted_dims = _ensure_1d(group, obj) - group_dim, = group.dims + (group_dim,) = group.dims expected_size = obj.sizes[group_dim] if group.size != expected_size: @@ -470,7 +470,7 @@ def _infer_concat_args(self, applied_example): else: coord = self._unique_coord positions = None - dim, = coord.dims + (dim,) = coord.dims if isinstance(coord, _DummyGroup): coord = None return coord, dim, positions @@ -644,7 +644,7 @@ def _concat_shortcut(self, applied, dim, positions=None): def _restore_dim_order(self, stacked): def lookup_order(dimension): if dimension == self._group.name: - dimension, = self._group.dims + (dimension,) = self._group.dims if dimension in self._obj.dims: axis = self._obj.get_axis_num(dimension) else: diff --git a/xarray/core/indexing.py b/xarray/core/indexing.py index b9809a8d2b9..f48c9e72af1 100644 --- a/xarray/core/indexing.py +++ b/xarray/core/indexing.py @@ -212,7 +212,7 @@ def get_dim_indexers(data_obj, indexers): level_indexers = defaultdict(dict) dim_indexers = {} for key, label in indexers.items(): - dim, = data_obj[key].dims + (dim,) = data_obj[key].dims if key != dim: # assume here multi-index level indexer level_indexers[dim][key] = label @@ -1368,7 +1368,7 @@ def __getitem__( if isinstance(key, tuple) and len(key) == 1: # unpack key so it can index a pandas.Index object (pandas.Index # objects don't like tuples) - key, = key + (key,) = key if getattr(key, "ndim", 0) > 1: # Return np-array if multidimensional return NumpyIndexingAdapter(self.array.values)[indexer] diff --git a/xarray/core/merge.py b/xarray/core/merge.py index db5ef9531df..389ceb155f7 100644 --- a/xarray/core/merge.py +++ b/xarray/core/merge.py @@ -277,7 +277,7 @@ def append_all(variables, indexes): def collect_from_coordinates( - list_of_coords: "List[Coordinates]" + list_of_coords: "List[Coordinates]", ) -> Dict[Hashable, List[MergeElement]]: """Collect variables and indexes to be merged from Coordinate objects.""" grouped: Dict[Hashable, List[Tuple[Variable, pd.Index]]] = {} @@ -320,7 +320,7 @@ def merge_coordinates_without_align( def determine_coords( - list_of_mappings: Iterable["DatasetLike"] + list_of_mappings: Iterable["DatasetLike"], ) -> Tuple[Set[Hashable], Set[Hashable]]: """Given a list of dicts with xarray object values, identify coordinates. diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 7d03fd58d39..b7abdc7c462 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -1526,7 +1526,7 @@ def concat(cls, variables, dim="concat_dim", positions=None, shortcut=False): along the given dimension. """ if not isinstance(dim, str): - dim, = dim.dims + (dim,) = dim.dims # can't do this lazily: we need to loop through variables at least # twice @@ -1996,7 +1996,7 @@ def concat(cls, variables, dim="concat_dim", positions=None, shortcut=False): arrays, if possible. """ if not isinstance(dim, str): - dim, = dim.dims + (dim,) = dim.dims variables = list(variables) first_var = variables[0] diff --git a/xarray/plot/plot.py b/xarray/plot/plot.py index a288f195e32..ca68f617144 100644 --- a/xarray/plot/plot.py +++ b/xarray/plot/plot.py @@ -83,8 +83,8 @@ def _infer_line_data(darray, x, y, hue): ) else: - xdim, = darray[xname].dims - huedim, = darray[huename].dims + (xdim,) = darray[xname].dims + (huedim,) = darray[huename].dims yplt = darray.transpose(xdim, huedim) else: @@ -102,8 +102,8 @@ def _infer_line_data(darray, x, y, hue): ) else: - ydim, = darray[yname].dims - huedim, = darray[huename].dims + (ydim,) = darray[yname].dims + (huedim,) = darray[huename].dims xplt = darray.transpose(ydim, huedim) huelabel = label_from_attrs(darray[huename]) diff --git a/xarray/tests/test_cftime_offsets.py b/xarray/tests/test_cftime_offsets.py index 142769dbbe7..343e059f53c 100644 --- a/xarray/tests/test_cftime_offsets.py +++ b/xarray/tests/test_cftime_offsets.py @@ -1187,5 +1187,5 @@ def test_dayofyear_after_cftime_range(freq): def test_cftime_range_standard_calendar_refers_to_gregorian(): from cftime import DatetimeGregorian - result, = cftime_range("2000", periods=1) + (result,) = cftime_range("2000", periods=1) assert isinstance(result, DatetimeGregorian) diff --git a/xarray/tests/test_dataarray.py b/xarray/tests/test_dataarray.py index ad474d533be..4b3ffdc021a 100644 --- a/xarray/tests/test_dataarray.py +++ b/xarray/tests/test_dataarray.py @@ -3125,11 +3125,11 @@ def test_align_copy(self): # Trivial align - 1 element x = DataArray([1, 2, 3], coords=[("a", [1, 2, 3])]) - x2, = align(x, copy=False) + (x2,) = align(x, copy=False) assert_identical(x, x2) assert source_ndarray(x2.data) is source_ndarray(x.data) - x2, = align(x, copy=True) + (x2,) = align(x, copy=True) assert_identical(x, x2) assert source_ndarray(x2.data) is not source_ndarray(x.data) @@ -3214,7 +3214,7 @@ def test_align_indexes(self): assert_identical(expected_x2, x2) assert_identical(expected_y2, y2) - x2, = align(x, join="outer", indexes={"a": [-2, 7, 10, -1]}) + (x2,) = align(x, join="outer", indexes={"a": [-2, 7, 10, -1]}) expected_x2 = DataArray([3, np.nan, 2, 1], coords=[("a", [-2, 7, 10, -1])]) assert_identical(expected_x2, x2) @@ -3293,7 +3293,7 @@ def test_broadcast_arrays_nocopy(self): assert source_ndarray(x2.data) is source_ndarray(x.data) # single-element broadcast (trivial case) - x2, = broadcast(x) + (x2,) = broadcast(x) assert_identical(x, x2) assert source_ndarray(x2.data) is source_ndarray(x.data) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index dfb3da89569..eab6040e17e 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -1945,7 +1945,7 @@ def test_align_nocopy(self): def test_align_indexes(self): x = Dataset({"foo": DataArray([1, 2, 3], dims="x", coords=[("x", [1, 2, 3])])}) - x2, = align(x, indexes={"x": [2, 3, 1]}) + (x2,) = align(x, indexes={"x": [2, 3, 1]}) expected_x2 = Dataset( {"foo": DataArray([2, 3, 1], dims="x", coords={"x": [2, 3, 1]})} ) @@ -1973,7 +1973,7 @@ def test_broadcast(self): }, {"c": ("x", [4])}, ) - actual, = broadcast(ds) + (actual,) = broadcast(ds) assert_identical(expected, actual) ds_x = Dataset({"foo": ("x", [1])}) @@ -1995,7 +1995,7 @@ def test_broadcast_nocopy(self): x = Dataset({"foo": (("x", "y"), [[1, 1]])}) y = Dataset({"bar": ("y", [2, 3])}) - actual_x, = broadcast(x) + (actual_x,) = broadcast(x) assert_identical(x, actual_x) assert source_ndarray(actual_x["foo"].data) is source_ndarray(x["foo"].data)