From c65b8a60f222205cf989c640ef8c325758966d1b Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 7 Nov 2024 18:04:56 +0100 Subject: [PATCH] Enforce ruff/flake8-pie rules (PIE) (#9740) * Apply ruff/flake8-pie rule PIE800 PIE800 Unnecessary spread `**` * Apply ruff/flake8-pie rule PIE804 PIE804 Unnecessary `dict` kwargs * Apply ruff/flake8-pie rule PIE808 PIE808 Unnecessary `start` argument in `range` * Enforce ruff/flake8-pie rules (PIE) --- asv_bench/benchmarks/dataset_io.py | 2 +- pyproject.toml | 2 ++ xarray/plot/facetgrid.py | 6 +++--- xarray/tests/test_computation.py | 2 +- xarray/tests/test_concat.py | 2 +- xarray/tests/test_groupby.py | 4 ++-- xarray/tests/test_interp.py | 2 +- xarray/tests/test_units.py | 2 +- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/asv_bench/benchmarks/dataset_io.py b/asv_bench/benchmarks/dataset_io.py index 527a2d41138..3a09288c8dc 100644 --- a/asv_bench/benchmarks/dataset_io.py +++ b/asv_bench/benchmarks/dataset_io.py @@ -712,7 +712,7 @@ def load(self) -> tuple: dims=("time",), fastpath=True, ) - for v in range(0, n_variables) + for v in range(n_variables) } attributes = {} diff --git a/pyproject.toml b/pyproject.toml index 8f165f2749a..b886ee78b6f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -247,6 +247,7 @@ ignore = [ "E731", "UP007", "PERF20", + "PIE790", # unnecessary pass statement "RUF001", "RUF002", "RUF003", @@ -262,6 +263,7 @@ extend-select = [ "TID", # flake8-tidy-imports (absolute imports) "I", # isort "PERF", # Perflint + "PIE", # flake8-pie "PGH", # pygrep-hooks "RUF", "UP", # Pyupgrade diff --git a/xarray/plot/facetgrid.py b/xarray/plot/facetgrid.py index b83f05a35a5..82105d5fb6a 100644 --- a/xarray/plot/facetgrid.py +++ b/xarray/plot/facetgrid.py @@ -495,14 +495,14 @@ def map_plot1d( if self._single_group: full = tuple( {self._single_group: x} - for x in range(0, self.data[self._single_group].size) + for x in range(self.data[self._single_group].size) ) empty = tuple(None for x in range(self._nrow * self._ncol - len(full))) name_d = full + empty else: rowcols = itertools.product( - range(0, self.data[self._row_var].size), - range(0, self.data[self._col_var].size), + range(self.data[self._row_var].size), + range(self.data[self._col_var].size), ) name_d = tuple({self._row_var: r, self._col_var: c} for r, c in rowcols) name_dicts = np.array(name_d).reshape(self._nrow, self._ncol) diff --git a/xarray/tests/test_computation.py b/xarray/tests/test_computation.py index 3a50a3f1724..4610aa62f64 100644 --- a/xarray/tests/test_computation.py +++ b/xarray/tests/test_computation.py @@ -1561,7 +1561,7 @@ def arrays(): ) return [ - da.isel(time=range(0, 18)), + da.isel(time=range(18)), da.isel(time=range(2, 20)).rolling(time=3, center=True).mean(), xr.DataArray([[1, 2], [1, np.nan]], dims=["x", "time"]), xr.DataArray([[1, 2], [np.nan, np.nan]], dims=["x", "time"]), diff --git a/xarray/tests/test_concat.py b/xarray/tests/test_concat.py index 32ebb0760c0..c3caab4e125 100644 --- a/xarray/tests/test_concat.py +++ b/xarray/tests/test_concat.py @@ -394,7 +394,7 @@ def concat_var_names() -> Callable: def get_varnames(var_cnt: int = 10, list_cnt: int = 10) -> list[list[str]]: orig = [f"d{i:02d}" for i in range(var_cnt)] var_names = [] - for _i in range(0, list_cnt): + for _i in range(list_cnt): l1 = orig.copy() var_names.append(l1) return var_names diff --git a/xarray/tests/test_groupby.py b/xarray/tests/test_groupby.py index 52cefe79237..88b8afa07fe 100644 --- a/xarray/tests/test_groupby.py +++ b/xarray/tests/test_groupby.py @@ -1273,7 +1273,7 @@ def test_groupby_iter(self) -> None: def test_groupby_properties(self) -> None: grouped = self.da.groupby("abc") - expected_groups = {"a": range(0, 9), "c": [9], "b": range(10, 20)} + expected_groups = {"a": range(9), "c": [9], "b": range(10, 20)} assert expected_groups.keys() == grouped.groups.keys() for key in expected_groups: expected_group = expected_groups[key] @@ -1936,7 +1936,7 @@ def test_resample_bad_resample_dim(self) -> None: times = pd.date_range("2000-01-01", freq="6h", periods=10) array = DataArray(np.arange(10), [("__resample_dim__", times)]) with pytest.raises(ValueError, match=r"Proxy resampling dimension"): - array.resample(**{"__resample_dim__": "1D"}).first() # type: ignore[arg-type] + array.resample(__resample_dim__="1D").first() @requires_scipy def test_resample_drop_nondim_coords(self) -> None: diff --git a/xarray/tests/test_interp.py b/xarray/tests/test_interp.py index b661cfb0b3a..d602cb96a6a 100644 --- a/xarray/tests/test_interp.py +++ b/xarray/tests/test_interp.py @@ -889,7 +889,7 @@ def test_decompose(method: InterpOptions) -> None: (data_ndim, interp_ndim, nscalar) for data_ndim in range(1, 4) for interp_ndim in range(1, data_ndim + 1) - for nscalar in range(0, interp_ndim + 1) + for nscalar in range(interp_ndim + 1) ], ) def test_interpolate_chunk_1d( diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index 2c334c18179..3999ae1a57c 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -3934,7 +3934,7 @@ def test_grouped_operations(self, func, variant, dtype, compute_backend): data_array = xr.DataArray( data=array, coords={"x": x, "y": y, "u": ("x", u)}, dims=("x", "y") ) - units = {**extract_units(data_array), **{"z": unit_registry.s, "q": None}} + units = {**extract_units(data_array), "z": unit_registry.s, "q": None} stripped_kwargs = { key: (