Skip to content

Commit a933364

Browse files
authored
pygmt.blockm*: Reorder input parameters to 'data, x, y, z' (#1565)
1 parent 7bd5a8f commit a933364

File tree

3 files changed

+30
-33
lines changed

3 files changed

+30
-33
lines changed

pygmt/src/blockm.py

+19-22
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
from pygmt.helpers import (
77
GMTTempFile,
88
build_arg_string,
9+
check_data_input_order,
910
fmt_docstring,
1011
kwargs_to_strings,
1112
use_alias,
1213
)
1314

1415

15-
def _blockm(block_method, table, outfile, x, y, z, **kwargs):
16+
def _blockm(block_method, data, x, y, z, outfile, **kwargs):
1617
r"""
1718
Block average (x,y,z) data tables by mean, median, or mode estimation.
1819
@@ -38,12 +39,11 @@ def _blockm(block_method, table, outfile, x, y, z, **kwargs):
3839
- None if ``outfile`` is set (filtered output will be stored in file
3940
set by ``outfile``)
4041
"""
41-
4242
with GMTTempFile(suffix=".csv") as tmpfile:
4343
with Session() as lib:
4444
# Choose how data will be passed into the module
4545
table_context = lib.virtualfile_from_data(
46-
check_kind="vector", data=table, x=x, y=y, z=z, required_z=True
46+
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
4747
)
4848
# Run blockm* on data table
4949
with table_context as infile:
@@ -55,7 +55,7 @@ def _blockm(block_method, table, outfile, x, y, z, **kwargs):
5555
# Read temporary csv output to a pandas table
5656
if outfile == tmpfile.name: # if user did not set outfile, return pd.DataFrame
5757
try:
58-
column_names = table.columns.to_list()
58+
column_names = data.columns.to_list()
5959
result = pd.read_csv(tmpfile.name, sep="\t", names=column_names)
6060
except AttributeError: # 'str' object has no attribute 'columns'
6161
result = pd.read_csv(tmpfile.name, sep="\t", header=None, comment=">")
@@ -66,6 +66,7 @@ def _blockm(block_method, table, outfile, x, y, z, **kwargs):
6666

6767

6868
@fmt_docstring
69+
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
6970
@use_alias(
7071
I="spacing",
7172
R="region",
@@ -82,7 +83,7 @@ def _blockm(block_method, table, outfile, x, y, z, **kwargs):
8283
w="wrap",
8384
)
8485
@kwargs_to_strings(R="sequence", i="sequence_comma", o="sequence_comma")
85-
def blockmean(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
86+
def blockmean(data=None, x=None, y=None, z=None, outfile=None, **kwargs):
8687
r"""
8788
Block average (x,y,z) data tables by mean estimation.
8889
@@ -93,15 +94,15 @@ def blockmean(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
9394
9495
Takes a matrix, xyz triplets, or a file name as input.
9596
96-
Must provide either ``table`` or ``x``, ``y``, and ``z``.
97+
Must provide either ``data`` or ``x``, ``y``, and ``z``.
9798
9899
Full option list at :gmt-docs:`blockmean.html`
99100
100101
{aliases}
101102
102103
Parameters
103104
----------
104-
table : str or {table-like}
105+
data : str or {table-like}
105106
Pass in (x, y, z) or (longitude, latitude, elevation) values by
106107
providing a file name to an ASCII data table, a 2D
107108
{table-classes}.
@@ -138,11 +139,12 @@ def blockmean(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
138139
set by ``outfile``).
139140
"""
140141
return _blockm(
141-
block_method="blockmean", table=table, outfile=outfile, x=x, y=y, z=z, **kwargs
142+
block_method="blockmean", data=data, x=x, y=y, z=z, outfile=outfile, **kwargs
142143
)
143144

144145

145146
@fmt_docstring
147+
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
146148
@use_alias(
147149
I="spacing",
148150
R="region",
@@ -159,7 +161,7 @@ def blockmean(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
159161
w="wrap",
160162
)
161163
@kwargs_to_strings(R="sequence", i="sequence_comma", o="sequence_comma")
162-
def blockmedian(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
164+
def blockmedian(data=None, x=None, y=None, z=None, outfile=None, **kwargs):
163165
r"""
164166
Block average (x,y,z) data tables by median estimation.
165167
@@ -170,15 +172,15 @@ def blockmedian(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
170172
171173
Takes a matrix, xyz triplets, or a file name as input.
172174
173-
Must provide either ``table`` or ``x``, ``y``, and ``z``.
175+
Must provide either ``data`` or ``x``, ``y``, and ``z``.
174176
175177
Full option list at :gmt-docs:`blockmedian.html`
176178
177179
{aliases}
178180
179181
Parameters
180182
----------
181-
table : str or {table-like}
183+
data : str or {table-like}
182184
Pass in (x, y, z) or (longitude, latitude, elevation) values by
183185
providing a file name to an ASCII data table, a 2D
184186
{table-classes}.
@@ -215,17 +217,12 @@ def blockmedian(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
215217
set by ``outfile``).
216218
"""
217219
return _blockm(
218-
block_method="blockmedian",
219-
table=table,
220-
outfile=outfile,
221-
x=x,
222-
y=y,
223-
z=z,
224-
**kwargs
220+
block_method="blockmedian", data=data, x=x, y=y, z=z, outfile=outfile, **kwargs
225221
)
226222

227223

228224
@fmt_docstring
225+
@check_data_input_order("v0.5.0", remove_version="v0.7.0")
229226
@use_alias(
230227
I="spacing",
231228
R="region",
@@ -242,7 +239,7 @@ def blockmedian(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
242239
w="wrap",
243240
)
244241
@kwargs_to_strings(R="sequence", i="sequence_comma", o="sequence_comma")
245-
def blockmode(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
242+
def blockmode(data=None, x=None, y=None, z=None, outfile=None, **kwargs):
246243
r"""
247244
Block average (x,y,z) data tables by mode estimation.
248245
@@ -253,15 +250,15 @@ def blockmode(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
253250
254251
Takes a matrix, xyz triplets, or a file name as input.
255252
256-
Must provide either ``table`` or ``x``, ``y``, and ``z``.
253+
Must provide either ``data`` or ``x``, ``y``, and ``z``.
257254
258255
Full option list at :gmt-docs:`blockmode.html`
259256
260257
{aliases}
261258
262259
Parameters
263260
----------
264-
table : str or {table-like}
261+
data : str or {table-like}
265262
Pass in (x, y, z) or (longitude, latitude, elevation) values by
266263
providing a file name to an ASCII data table, a 2D
267264
{table-classes}.
@@ -298,5 +295,5 @@ def blockmode(table=None, outfile=None, *, x=None, y=None, z=None, **kwargs):
298295
set by ``outfile``).
299296
"""
300297
return _blockm(
301-
block_method="blockmode", table=table, outfile=outfile, x=x, y=y, z=z, **kwargs
298+
block_method="blockmode", data=data, x=x, y=y, z=z, outfile=outfile, **kwargs
302299
)

pygmt/tests/test_blockm.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_blockmean_input_dataframe(dataframe):
2626
"""
2727
Run blockmean by passing in a pandas.DataFrame as input.
2828
"""
29-
output = blockmean(table=dataframe, spacing="5m", region=[245, 255, 20, 30])
29+
output = blockmean(data=dataframe, spacing="5m", region=[245, 255, 20, 30])
3030
assert isinstance(output, pd.DataFrame)
3131
assert all(dataframe.columns == output.columns)
3232
assert output.shape == (5849, 3)
@@ -40,7 +40,7 @@ def test_blockmean_input_table_matrix(array_func, dataframe):
4040
matrix.
4141
"""
4242
table = array_func(dataframe)
43-
output = blockmean(table=table, spacing="5m", region=[245, 255, 20, 30])
43+
output = blockmean(data=table, spacing="5m", region=[245, 255, 20, 30])
4444
assert isinstance(output, pd.DataFrame)
4545
assert output.shape == (5849, 3)
4646
npt.assert_allclose(output.iloc[0], [245.888877, 29.978707, -384.0])
@@ -70,7 +70,7 @@ def test_blockmean_wrong_kind_of_input_table_grid(dataframe):
7070
invalid_table = dataframe.bathymetry.to_xarray()
7171
assert data_kind(invalid_table) == "grid"
7272
with pytest.raises(GMTInvalidInput):
73-
blockmean(table=invalid_table, spacing="5m", region=[245, 255, 20, 30])
73+
blockmean(data=invalid_table, spacing="5m", region=[245, 255, 20, 30])
7474

7575

7676
def test_blockmean_input_filename():
@@ -79,7 +79,7 @@ def test_blockmean_input_filename():
7979
"""
8080
with GMTTempFile() as tmpfile:
8181
output = blockmean(
82-
table="@tut_ship.xyz",
82+
data="@tut_ship.xyz",
8383
spacing="5m",
8484
region=[245, 255, 20, 30],
8585
outfile=tmpfile.name,
@@ -95,7 +95,7 @@ def test_blockmean_without_outfile_setting():
9595
"""
9696
Run blockmean by not passing in outfile parameter setting.
9797
"""
98-
output = blockmean(table="@tut_ship.xyz", spacing="5m", region=[245, 255, 20, 30])
98+
output = blockmean(data="@tut_ship.xyz", spacing="5m", region=[245, 255, 20, 30])
9999
assert isinstance(output, pd.DataFrame)
100100
assert output.shape == (5849, 3)
101101
npt.assert_allclose(output.iloc[0], [245.888877, 29.978707, -384.0])
@@ -105,7 +105,7 @@ def test_blockmode_input_dataframe(dataframe):
105105
"""
106106
Run blockmode by passing in a pandas.DataFrame as input.
107107
"""
108-
output = blockmode(table=dataframe, spacing="5m", region=[245, 255, 20, 30])
108+
output = blockmode(data=dataframe, spacing="5m", region=[245, 255, 20, 30])
109109
assert isinstance(output, pd.DataFrame)
110110
assert all(dataframe.columns == output.columns)
111111
assert output.shape == (5849, 3)

pygmt/tests/test_blockmedian.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_blockmedian_input_dataframe(dataframe):
2424
"""
2525
Run blockmedian by passing in a pandas.DataFrame as input.
2626
"""
27-
output = blockmedian(table=dataframe, spacing="5m", region=[245, 255, 20, 30])
27+
output = blockmedian(data=dataframe, spacing="5m", region=[245, 255, 20, 30])
2828
assert isinstance(output, pd.DataFrame)
2929
assert all(dataframe.columns == output.columns)
3030
assert output.shape == (5849, 3)
@@ -37,7 +37,7 @@ def test_blockmedian_input_table_matrix(dataframe):
3737
a matrix.
3838
"""
3939
table = dataframe.values
40-
output = blockmedian(table=table, spacing="5m", region=[245, 255, 20, 30])
40+
output = blockmedian(data=table, spacing="5m", region=[245, 255, 20, 30])
4141
assert isinstance(output, pd.DataFrame)
4242
assert output.shape == (5849, 3)
4343
npt.assert_allclose(output.iloc[0], [245.88819, 29.97895, -385.0])
@@ -67,7 +67,7 @@ def test_blockmedian_wrong_kind_of_input_table_grid(dataframe):
6767
invalid_table = dataframe.bathymetry.to_xarray()
6868
assert data_kind(invalid_table) == "grid"
6969
with pytest.raises(GMTInvalidInput):
70-
blockmedian(table=invalid_table, spacing="5m", region=[245, 255, 20, 30])
70+
blockmedian(data=invalid_table, spacing="5m", region=[245, 255, 20, 30])
7171

7272

7373
def test_blockmedian_input_filename():
@@ -76,7 +76,7 @@ def test_blockmedian_input_filename():
7676
"""
7777
with GMTTempFile() as tmpfile:
7878
output = blockmedian(
79-
table="@tut_ship.xyz",
79+
data="@tut_ship.xyz",
8080
spacing="5m",
8181
region=[245, 255, 20, 30],
8282
outfile=tmpfile.name,
@@ -92,7 +92,7 @@ def test_blockmedian_without_outfile_setting():
9292
"""
9393
Run blockmedian by not passing in outfile parameter setting.
9494
"""
95-
output = blockmedian(table="@tut_ship.xyz", spacing="5m", region=[245, 255, 20, 30])
95+
output = blockmedian(data="@tut_ship.xyz", spacing="5m", region=[245, 255, 20, 30])
9696
assert isinstance(output, pd.DataFrame)
9797
assert output.shape == (5849, 3)
9898
npt.assert_allclose(output.iloc[0], [245.88819, 29.97895, -385.0])

0 commit comments

Comments
 (0)