Skip to content

Commit e7a6a19

Browse files
authored
Merge branch 'master' into columns-plot3d
2 parents b3b78d7 + ab837d4 commit e7a6a19

File tree

9 files changed

+633
-584
lines changed

9 files changed

+633
-584
lines changed

.github/workflows/ci_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jobs:
144144

145145
# Upload coverage to Codecov
146146
- name: Upload coverage to Codecov
147-
uses: codecov/codecov-action@v1.5.0
147+
uses: codecov/codecov-action@v1.5.2
148148
with:
149149
file: ./coverage.xml # optional
150150
env_vars: OS,PYTHON,NUMPY

CONTRIBUTING.md

Lines changed: 7 additions & 570 deletions
Large diffs are not rendered by default.

doc/conf.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@
162162
)
163163
html_context = {
164164
"menu_links": [
165-
(
166-
'<i class="fa fa-users fa-fw"></i> Contributing',
167-
f"{repository_url}/blob/master/CONTRIBUTING.md",
168-
),
169165
(
170166
'<i class="fa fa-gavel fa-fw"></i> Code of Conduct',
171167
f"{repository_url}/blob/master/CODE_OF_CONDUCT.md",

doc/contributing.md

Lines changed: 564 additions & 0 deletions
Large diffs are not rendered by default.

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@
5858

5959
api/index.rst
6060
changes.md
61+
contributing.md
6162
maintenance.md

pygmt/helpers/decorators.py

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import functools
99
import textwrap
1010
import warnings
11+
from inspect import Parameter, signature
1112

1213
import numpy as np
1314
from pygmt.exceptions import GMTInvalidInput
@@ -322,6 +323,30 @@ def fmt_docstring(module_func):
322323
return module_func
323324

324325

326+
def _insert_alias(module_func, default_value=None):
327+
"""
328+
Function to insert PyGMT long aliases into the signature of a method.
329+
"""
330+
331+
# Get current signature and parameters
332+
sig = signature(module_func)
333+
wrapped_params = list(sig.parameters.values())
334+
kwargs_param = wrapped_params.pop(-1)
335+
# Add new parameters from aliases
336+
for alias in module_func.aliases.values():
337+
if alias not in sig.parameters.keys():
338+
new_param = Parameter(
339+
alias, kind=Parameter.KEYWORD_ONLY, default=default_value
340+
)
341+
wrapped_params = wrapped_params + [new_param]
342+
all_params = wrapped_params + [kwargs_param]
343+
# Update method signature
344+
sig_new = sig.replace(parameters=all_params)
345+
module_func.__signature__ = sig_new
346+
347+
return module_func
348+
349+
325350
def use_alias(**aliases):
326351
"""
327352
Decorator to add aliases to keyword arguments of a function.
@@ -359,7 +384,7 @@ def use_alias(**aliases):
359384
Traceback (most recent call last):
360385
...
361386
pygmt.exceptions.GMTInvalidInput:
362-
Arguments in short-form (J) and long-form (projection) can't coexist
387+
Parameters in short-form (J) and long-form (projection) can't coexist.
363388
"""
364389

365390
def alias_decorator(module_func):
@@ -372,17 +397,26 @@ def new_module(*args, **kwargs):
372397
"""
373398
New module that parses and replaces the registered aliases.
374399
"""
375-
for arg, alias in aliases.items():
376-
if alias in kwargs and arg in kwargs:
400+
for short_param, long_alias in aliases.items():
401+
if long_alias in kwargs and short_param in kwargs:
377402
raise GMTInvalidInput(
378-
f"Arguments in short-form ({arg}) and long-form ({alias}) can't coexist"
403+
f"Parameters in short-form ({short_param}) and "
404+
f"long-form ({long_alias}) can't coexist."
379405
)
380-
if alias in kwargs:
381-
kwargs[arg] = kwargs.pop(alias)
406+
if long_alias in kwargs:
407+
kwargs[short_param] = kwargs.pop(long_alias)
408+
elif short_param in kwargs:
409+
msg = (
410+
f"Short-form parameter ({short_param}) is not recommended. "
411+
f"Use long-form parameter '{long_alias}' instead."
412+
)
413+
warnings.warn(msg, category=SyntaxWarning, stacklevel=2)
382414
return module_func(*args, **kwargs)
383415

384416
new_module.aliases = aliases
385417

418+
new_module = _insert_alias(new_module)
419+
386420
return new_module
387421

388422
return alias_decorator

pygmt/src/grdfill.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import xarray as xr
66
from pygmt.clib import Session
7+
from pygmt.exceptions import GMTInvalidInput
78
from pygmt.helpers import (
89
GMTTempFile,
910
build_arg_string,
@@ -18,6 +19,7 @@
1819
A="mode",
1920
G="outgrid",
2021
R="region",
22+
V="verbose",
2123
)
2224
@kwargs_to_strings(R="sequence")
2325
def grdfill(grid, **kwargs):
@@ -45,8 +47,12 @@ def grdfill(grid, **kwargs):
4547
constant fill and append the constant value, **n** for nearest
4648
neighbor (and optionally append a search radius in
4749
pixels [default radius is :math:`r^2 = \sqrt{{ X^2 + Y^2 }}`,
48-
where (*X,Y*) are the node dimensions of the grid]).
50+
where (*X,Y*) are the node dimensions of the grid]), or
51+
**s** for bicubic spline (optionally append a *tension*
52+
parameter [Default is no tension]).
53+
4954
{R}
55+
{V}
5056
5157
Returns
5258
-------
@@ -57,6 +63,8 @@ def grdfill(grid, **kwargs):
5763
- None if ``outgrid`` is set (grid output will be stored in file set by
5864
``outgrid``)
5965
"""
66+
if "A" not in kwargs.keys() and "L" not in kwargs.keys():
67+
raise GMTInvalidInput("At least parameter 'mode' or 'L' must be specified.")
6068
with GMTTempFile(suffix=".nc") as tmpfile:
6169
with Session() as lib:
6270
file_context = lib.virtualfile_from_data(check_kind="raster", data=grid)

pygmt/src/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def plot(self, x=None, y=None, data=None, size=None, direction=None, **kwargs):
8080
data : str or {table-like}
8181
Pass in either a file name to an ASCII data table, a 2D
8282
{table-classes}.
83-
Use parameter ``columns`` to choose which columns are x, y, color, and
83+
Use parameter ``incols`` to choose which columns are x, y, color, and
8484
size, respectively.
8585
size : 1d array
8686
The size of the data points in units specified using ``style``.

pygmt/tests/test_grdfill.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Tests for grdclip.
2+
Tests for grdfill.
33
"""
44
import os
55

@@ -8,6 +8,7 @@
88
import xarray as xr
99
from pygmt import grdfill, grdinfo
1010
from pygmt.datasets import load_earth_relief
11+
from pygmt.exceptions import GMTInvalidInput
1112
from pygmt.helpers import GMTTempFile
1213

1314

@@ -47,3 +48,11 @@ def test_grdfill_file_out(grid):
4748
assert os.path.exists(path=tmpfile.name) # check that outgrid exists
4849
result = grdinfo(tmpfile.name, per_column=True).strip()
4950
assert result == "-5 5 -5 5 -5130.5 inf 1 1 10 10 1 1"
51+
52+
53+
def test_grdfill_required_args(grid):
54+
"""
55+
Test that grdfill fails without arguments for `mode` and `L`.
56+
"""
57+
with pytest.raises(GMTInvalidInput):
58+
grdfill(grid=grid)

0 commit comments

Comments
 (0)