diff --git a/asv_bench/benchmarks/groupby.py b/asv_bench/benchmarks/groupby.py index a5261d5106a..681fd6ed734 100644 --- a/asv_bench/benchmarks/groupby.py +++ b/asv_bench/benchmarks/groupby.py @@ -1,6 +1,6 @@ # import flox to avoid the cost of first import import cftime -import flox.xarray # noqa +import flox.xarray # noqa: F401 import numpy as np import pandas as pd diff --git a/pyproject.toml b/pyproject.toml index 7c0126399bd..83e575bebef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -253,6 +253,7 @@ extend-select = [ "W", "TID", # flake8-tidy-imports (absolute imports) "I", # isort + "PGH", # pygrep-hooks "UP", # Pyupgrade ] diff --git a/xarray/core/duck_array_ops.py b/xarray/core/duck_array_ops.py index 95aba0441e2..4d01e5bc345 100644 --- a/xarray/core/duck_array_ops.py +++ b/xarray/core/duck_array_ops.py @@ -16,10 +16,10 @@ import numpy as np import pandas as pd -from numpy import all as array_all # noqa -from numpy import any as array_any # noqa +from numpy import all as array_all # noqa: F401 +from numpy import any as array_any # noqa: F401 from numpy import concatenate as _concatenate -from numpy import ( # noqa +from numpy import ( # noqa: F401 full_like, gradient, isclose, @@ -30,7 +30,7 @@ transpose, unravel_index, ) -from numpy.lib.stride_tricks import sliding_window_view # noqa +from numpy.lib.stride_tricks import sliding_window_view # noqa: F401 from packaging.version import Version from pandas.api.types import is_extension_array_dtype diff --git a/xarray/tests/test_datatree.py b/xarray/tests/test_datatree.py index 2e0ab2be73e..7b295128d63 100644 --- a/xarray/tests/test_datatree.py +++ b/xarray/tests/test_datatree.py @@ -119,7 +119,7 @@ def test_create_full_tree(self, simple_datatree) -> None: class TestNames: def test_child_gets_named_on_attach(self) -> None: sue = DataTree() - mary = DataTree(children={"Sue": sue}) # noqa + mary = DataTree(children={"Sue": sue}) assert mary.children["Sue"].name == "Sue" def test_dataset_containing_slashes(self) -> None: @@ -515,7 +515,7 @@ def test_setitem_new_grandchild_node(self) -> None: def test_grafted_subtree_retains_name(self) -> None: subtree = DataTree(name="original_subtree_name") root = DataTree(name="root") - root["new_subtree_name"] = subtree # noqa + root["new_subtree_name"] = subtree assert subtree.name == "original_subtree_name" def test_setitem_new_empty_node(self) -> None: diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index ced569ffeab..2c334c18179 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -5638,7 +5638,7 @@ def test_duck_array_ops(self): assert_units_equal(expected, actual) # Don't use isinstance b/c we don't want to allow subclasses through - assert type(expected.data) == type(actual.data) # noqa + assert type(expected.data) == type(actual.data) # noqa: E721 @requires_matplotlib diff --git a/xarray/tutorial.py b/xarray/tutorial.py index 0472584028a..6f57a7b1b42 100644 --- a/xarray/tutorial.py +++ b/xarray/tutorial.py @@ -56,10 +56,10 @@ def _check_netcdf_engine_installed(name): version = file_formats.get(name) if version == 3: try: - import scipy # noqa + import scipy # noqa: F401 except ImportError: try: - import netCDF4 # noqa + import netCDF4 # noqa: F401 except ImportError as err: raise ImportError( f"opening tutorial dataset {name} requires either scipy or " @@ -67,10 +67,10 @@ def _check_netcdf_engine_installed(name): ) from err if version == 4: try: - import h5netcdf # noqa + import h5netcdf # noqa: F401 except ImportError: try: - import netCDF4 # noqa + import netCDF4 # noqa: F401 except ImportError as err: raise ImportError( f"opening tutorial dataset {name} requires either h5netcdf " @@ -149,7 +149,7 @@ def open_dataset( if engine is None: engine = "cfgrib" try: - import cfgrib # noqa + import cfgrib # noqa: F401 except ImportError as e: raise ImportError( "Reading this tutorial dataset requires the cfgrib package."