Skip to content

Commit 474af0a

Browse files
authored
Bump to ruff>=0.12.0 and fix violations (#3980)
* pandas-df-variable-name (PD901) is deprecated * Silent some PLC0415 violations * Fix PT031 violations Reference: https://docs.pytest.org/en/stable/how-to/capture-warnings.html#recwarn * Bump to ruff>=0.12.0
1 parent 93f74df commit 474af0a

16 files changed

+31
-31
lines changed

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies:
2626
# Dev dependencies (style checks)
2727
- codespell
2828
- pre-commit
29-
- ruff>=0.10.0
29+
- ruff>=0.12.0
3030
# Dev dependencies (unit testing)
3131
- matplotlib-base
3232
- pytest>=6.0

pygmt/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def _repr_html_(self) -> str:
419419
html = '<img src="data:image/png;base64,{image}" width="{width}px">'
420420
return html.format(image=base64_png.decode("utf-8"), width=500)
421421

422-
from pygmt.src import ( # type: ignore[misc]
422+
from pygmt.src import ( # type: ignore[misc] # noqa: PLC0415
423423
basemap,
424424
coast,
425425
colorbar,

pygmt/helpers/tempfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def tempfile_from_geojson(geojson):
132132
E.g. '1a2b3c4d5e6.gmt'.
133133
"""
134134
with GMTTempFile(suffix=".gmt") as tmpfile:
135-
import geopandas as gpd
135+
import geopandas as gpd # noqa: PLC0415
136136

137137
Path(tmpfile.name).unlink() # Ensure file is deleted first
138138
ogrgmt_kwargs = {"filename": tmpfile.name, "driver": "OGR_GMT", "mode": "w"}
@@ -157,7 +157,7 @@ def tempfile_from_geojson(geojson):
157157
geojson.to_file(**ogrgmt_kwargs)
158158
except AttributeError:
159159
# Other 'geo' formats which implement __geo_interface__
160-
import json
160+
import json # noqa: PLC0415
161161

162162
jsontext = json.dumps(geojson.__geo_interface__)
163163
gpd.read_file(filename=io.StringIO(jsontext)).to_file(**ogrgmt_kwargs)

pygmt/helpers/testing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def check_figures_equal(*, extensions=("png",), tol=0.0, result_dir="result_imag
7272
keyword_only = inspect.Parameter.KEYWORD_ONLY
7373

7474
def decorator(func):
75-
import pytest
76-
from matplotlib.testing.compare import compare_images
75+
import pytest # noqa: PLC0415
76+
from matplotlib.testing.compare import compare_images # noqa: PLC0415
7777

7878
Path(result_dir).mkdir(parents=True, exist_ok=True)
7979
old_sig = inspect.signature(func)
@@ -188,7 +188,7 @@ def skip_if_no(package):
188188
A pytest.mark.skipif to use as either a test decorator or a
189189
parametrization mark.
190190
"""
191-
import pytest
191+
import pytest # noqa: PLC0415
192192

193193
try:
194194
_ = importlib.import_module(name=package)

pygmt/tests/test_clib.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test the wrappers for the C API.
33
"""
44

5+
import importlib
56
from contextlib import contextmanager
67

78
import pytest
@@ -241,8 +242,6 @@ def test_fails_for_wrong_version(monkeypatch):
241242
"""
242243
Make sure that importing clib raise an exception if GMT is too old.
243244
"""
244-
import importlib
245-
246245
with monkeypatch.context() as mpatch:
247246
# Make sure the current GMT major version is 6.
248247
assert clib.__gmt_version__.split(".")[0] == "6"

pygmt/tests/test_clib_dataarray_to_matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_dataarray_to_matrix_irregular_inc_warning():
9696
grid = xr.DataArray(data, coords=[("y", y), ("x", x)])
9797
with pytest.warns(expected_warning=RuntimeWarning) as record:
9898
dataarray_to_matrix(grid)
99-
assert len(record) == 1
99+
assert len(record) == 1
100100

101101

102102
def test_dataarray_to_matrix_zero_inc_fails():

pygmt/tests/test_datatypes_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,6 @@ def test_dataset_to_strings_with_none_values():
161161
Path(path).unlink()
162162
with pytest.warns(expected_warning=RuntimeWarning) as record:
163163
paths = which(fname=tiles, download="a")
164-
assert len(record) == 1
164+
assert len(record) == 1
165165
assert len(paths) == 2
166166
assert "" in paths

pygmt/tests/test_figure.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ def test_figure_savefig_geotiff():
124124

125125
# Check if a TIFF is georeferenced or not
126126
if _HAS_RIOXARRAY:
127-
import rioxarray
128-
from rasterio.errors import NotGeoreferencedWarning
129-
from rasterio.transform import Affine
127+
import rioxarray # noqa: PLC0415
128+
from rasterio.errors import NotGeoreferencedWarning # noqa: PLC0415
129+
from rasterio.transform import Affine # noqa: PLC0415
130130

131131
# GeoTIFF
132132
with rioxarray.open_rasterio(geofname) as xds:
@@ -152,15 +152,17 @@ def test_figure_savefig_geotiff():
152152
# TIFF
153153
with pytest.warns(expected_warning=NotGeoreferencedWarning) as record:
154154
with rioxarray.open_rasterio(fname) as xds:
155-
assert xds.rio.crs is None
156-
npt.assert_allclose(
157-
actual=xds.rio.bounds(), desired=(0.0, 0.0, 1331.0, 1257.0)
158-
)
159-
assert xds.rio.shape == (1257, 1331)
160-
assert xds.rio.transform() == Affine(
161-
a=1.0, b=0.0, c=0.0, d=0.0, e=1.0, f=0.0
162-
)
163-
assert len(record) == 1
155+
pass
156+
assert len(record) == 1
157+
with rioxarray.open_rasterio(fname) as xds:
158+
assert xds.rio.crs is None
159+
npt.assert_allclose(
160+
actual=xds.rio.bounds(), desired=(0.0, 0.0, 1331.0, 1257.0)
161+
)
162+
assert xds.rio.shape == (1257, 1331)
163+
assert xds.rio.transform() == Affine(
164+
a=1.0, b=0.0, c=0.0, d=0.0, e=1.0, f=0.0
165+
)
164166
geofname.unlink()
165167
fname.unlink()
166168

pygmt/tests/test_grdclip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def test_grdclip_replace():
8888
# TODO(PyGMT>=0.19.0): Remove this test below for the 'new' parameter
8989
with pytest.warns(FutureWarning):
9090
grid = grdclip(grid=grid, new=[1, 3]) # Replace 1 with 3
91-
npt.assert_array_equal(np.unique(grid), [2, 3])
91+
npt.assert_array_equal(np.unique(grid), [2, 3])
9292

9393

9494
def test_grdclip_between_repeated():

pygmt/tests/test_grdfill.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,4 @@ def test_grdfill_deprecated_mode(grid, expected_grid):
147147
"""
148148
with pytest.warns(FutureWarning):
149149
result = grdfill(grid=grid, mode="c20")
150-
xr.testing.assert_allclose(a=result, b=expected_grid)
150+
xr.testing.assert_allclose(a=result, b=expected_grid)

0 commit comments

Comments
 (0)