Skip to content

Commit 15a0642

Browse files
seismanweiji14
andauthored
Enable ruff's pandas-vet (PD) rules (#2830)
* Enable ruff's pandas-vet (PD) rules * Fix PD errors * Ignore PD901 Co-authored-by: Wei Ji <[email protected]>
1 parent ac4e184 commit 15a0642

7 files changed

Lines changed: 10 additions & 8 deletions

pygmt/clib/conversion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def dataarray_to_matrix(grid):
9292
# grids, this would be North-South, East-West. GMT's region and inc are
9393
# East-West, North-South.
9494
for dim in grid.dims[::-1]:
95-
coord = grid.coords[dim].values
95+
coord = grid.coords[dim].to_numpy()
9696
coord_incs = coord[1:] - coord[0:-1]
9797
coord_inc = coord_incs[0]
9898
if not np.allclose(coord_incs, coord_inc):
@@ -120,7 +120,7 @@ def dataarray_to_matrix(grid):
120120
inc = [abs(i) for i in inc]
121121
grid = grid.sortby(variables=list(grid.dims), ascending=True)
122122

123-
matrix = as_c_contiguous(grid[::-1].values)
123+
matrix = as_c_contiguous(grid[::-1].to_numpy())
124124
return matrix, region, inc
125125

126126

pygmt/tests/test_blockmedian.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_blockmedian_input_table_matrix(dataframe):
3636
Run blockmedian using table input that is not a pandas.DataFrame but still
3737
a matrix.
3838
"""
39-
table = dataframe.values
39+
table = dataframe.to_numpy()
4040
output = blockmedian(data=table, spacing="5m", region=[245, 255, 20, 30])
4141
assert isinstance(output, pd.DataFrame)
4242
assert output.shape == (5849, 3)

pygmt/tests/test_datasets_earth_vertical_gravity_gradient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_earth_vertical_gravity_gradient_01d():
2121
npt.assert_allclose(data.lon, np.arange(-180, 181, 1))
2222
npt.assert_allclose(data.min(), -137.125, atol=1 / 32)
2323
npt.assert_allclose(data.max(), 104.59375, atol=1 / 32)
24-
assert data[1, 1].isnull()
24+
assert data[1, 1].isnull() # noqa: PD003 # ruff's bug
2525

2626

2727
def test_earth_vertical_gravity_gradient_01d_with_region():

pygmt/tests/test_datasets_samples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def test_earth_relief_holes():
189189
npt.assert_allclose(grid.max(), 1601)
190190
npt.assert_allclose(grid.min(), -4929.5)
191191
# Test for the NaN values in the remote file
192-
assert grid[2, 21].isnull()
192+
assert grid[2, 21].isnull() # noqa: PD003 # ruff's bug
193193

194194

195195
def test_maunaloa_co2():

pygmt/tests/test_select.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_select_input_table_matrix(dataframe):
3737
3838
Also testing the reverse (I) alias.
3939
"""
40-
data = dataframe.values
40+
data = dataframe.to_numpy()
4141
output = select(data=data, region=[245.5, 254.5, 20.5, 29.5], reverse="r")
4242
assert isinstance(output, pd.DataFrame)
4343
assert output.shape == (9177, 3)

pygmt/tests/test_surface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_surface_input_data_array(data, region, spacing, expected_grid):
9393
"""
9494
Run surface by passing in a numpy array into data.
9595
"""
96-
data = data.values # convert pandas.DataFrame to numpy.ndarray
96+
data = data.to_numpy() # convert pandas.DataFrame to numpy.ndarray
9797
output = surface(
9898
data=data,
9999
spacing=spacing,
@@ -132,7 +132,7 @@ def test_surface_with_outgrid_param(data, region, spacing, expected_grid):
132132
"""
133133
Run surface with the -Goutputfile.nc parameter.
134134
"""
135-
data = data.values # convert pandas.DataFrame to numpy.ndarray
135+
data = data.to_numpy() # convert pandas.DataFrame to numpy.ndarray
136136
with GMTTempFile(suffix=".nc") as tmpfile:
137137
output = surface(
138138
data=data,

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ select = [
100100
"F", # pyflakes
101101
"I", # isort
102102
"NPY", # numpy
103+
"PD", # pandas-vet
103104
"PL", # pylint
104105
"UP", # pyupgrade
105106
"W", # pycodestyle warnings
106107
]
107108
ignore = [
108109
"E501", # Avoid enforcing line-length violations
110+
"PD901", # Allow using the generic variable name `df` for DataFrames
109111
"PLR2004", # Allow any magic values
110112
]
111113

0 commit comments

Comments
 (0)