Skip to content

Commit

Permalink
Enforce ruff/pygrep-hooks rules (PGH) (#9729)
Browse files Browse the repository at this point in the history
* Apply ruff/pygrep-hooks rule PGH004

PGH004 Use specific rule codes when using `noqa`

* Enforce ruff/pygrep-hooks rules (PGH)

---------

Co-authored-by: Deepak Cherian <[email protected]>
DimitriPapadopoulos and dcherian authored Nov 6, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent adc2ae3 commit ff41525
Showing 6 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion asv_bench/benchmarks/groupby.py
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -253,6 +253,7 @@ extend-select = [
"W",
"TID", # flake8-tidy-imports (absolute imports)
"I", # isort
"PGH", # pygrep-hooks
"UP", # Pyupgrade
]

8 changes: 4 additions & 4 deletions xarray/core/duck_array_ops.py
Original file line number Diff line number Diff line change
@@ -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

4 changes: 2 additions & 2 deletions xarray/tests/test_datatree.py
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 1 addition & 1 deletion xarray/tests/test_units.py
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions xarray/tutorial.py
Original file line number Diff line number Diff line change
@@ -56,21 +56,21 @@ 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 "
"netCDF4 to be installed."
) 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."

0 comments on commit ff41525

Please sign in to comment.