Skip to content

Commit b5fa22b

Browse files
authored
Update existing inline examples to the new doctest style (#1793)
1 parent 9d5460a commit b5fa22b

10 files changed

+55
-55
lines changed

pygmt/src/blockm.py

+11-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use_alias,
1313
)
1414

15+
__doctest_skip__ = ["blockmean", "blockmedian", "blockmode"]
16+
1517

1618
def _blockm(block_method, data, x, y, z, outfile, **kwargs):
1719
r"""
@@ -150,15 +152,13 @@ def blockmean(data=None, x=None, y=None, z=None, outfile=None, **kwargs):
150152
151153
Example
152154
-------
153-
>>> import pygmt # doctest: +SKIP
155+
>>> import pygmt
154156
>>> # Load a table of ship observations of bathymetry off Baja California
155-
>>> data = pygmt.datasets.load_sample_data(
156-
... name="bathymetry"
157-
... ) # doctest: +SKIP
157+
>>> data = pygmt.datasets.load_sample_data(name="bathymetry")
158158
>>> # Calculate block mean values within 5 by 5 minute bins
159159
>>> data_bmean = pygmt.blockmean(
160160
... data=data, region=[245, 255, 20, 30], spacing="5m"
161-
... ) # doctest: +SKIP
161+
... )
162162
"""
163163
return _blockm(
164164
block_method="blockmean", data=data, x=x, y=y, z=z, outfile=outfile, **kwargs
@@ -240,15 +240,13 @@ def blockmedian(data=None, x=None, y=None, z=None, outfile=None, **kwargs):
240240
241241
Example
242242
-------
243-
>>> import pygmt # doctest: +SKIP
243+
>>> import pygmt
244244
>>> # Load a table of ship observations of bathymetry off Baja California
245-
>>> data = pygmt.datasets.load_sample_data(
246-
... name="bathymetry"
247-
... ) # doctest: +SKIP
245+
>>> data = pygmt.datasets.load_sample_data(name="bathymetry")
248246
>>> # Calculate block median values within 5 by 5 minute bins
249247
>>> data_bmedian = pygmt.blockmedian(
250248
... data=data, region=[245, 255, 20, 30], spacing="5m"
251-
... ) # doctest: +SKIP
249+
... )
252250
"""
253251
return _blockm(
254252
block_method="blockmedian", data=data, x=x, y=y, z=z, outfile=outfile, **kwargs
@@ -330,15 +328,13 @@ def blockmode(data=None, x=None, y=None, z=None, outfile=None, **kwargs):
330328
331329
Example
332330
-------
333-
>>> import pygmt # doctest: +SKIP
331+
>>> import pygmt
334332
>>> # Load a table of ship observations of bathymetry off Baja California
335-
>>> data = pygmt.datasets.load_sample_data(
336-
... name="bathymetry"
337-
... ) # doctest: +SKIP
333+
>>> data = pygmt.datasets.load_sample_data(name="bathymetry")
338334
>>> # Calculate block mode values within 5 by 5 minute bins
339335
>>> data_bmode = pygmt.blockmode(
340336
... data=data, region=[245, 255, 20, 30], spacing="5m"
341-
... ) # doctest: +SKIP
337+
... )
342338
"""
343339
return _blockm(
344340
block_method="blockmode", data=data, x=x, y=y, z=z, outfile=outfile, **kwargs

pygmt/src/grd2xyz.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use_alias,
1616
)
1717

18+
__doctest_skip__ = ["grd2xyz"]
19+
1820

1921
@fmt_docstring
2022
@use_alias(
@@ -128,17 +130,15 @@ def grd2xyz(grid, output_type="pandas", outfile=None, **kwargs):
128130
129131
Example
130132
-------
131-
>>> import pygmt # doctest: +SKIP
133+
>>> import pygmt
132134
>>> # Load a grid of @earth_relief_30m data, with an x-range of 10 to 30,
133135
>>> # and a y-range of 15 to 25
134136
>>> grid = pygmt.datasets.load_earth_relief(
135137
... resolution="30m", region=[10, 30, 15, 25]
136-
... ) # doctest: +SKIP
138+
... )
137139
>>> # Create a pandas DataFrame with the xyz data from an input grid
138-
>>> xyz_dataframe = pygmt.grd2xyz(
139-
... grid=grid, output_type="pandas"
140-
... ) # doctest: +SKIP
141-
>>> xyz_dataframe.head(n=2) # doctest: +SKIP
140+
>>> xyz_dataframe = pygmt.grd2xyz(grid=grid, output_type="pandas")
141+
>>> xyz_dataframe.head(n=2)
142142
lon lat elevation
143143
0 10.25 24.75 903.5
144144
1 10.75 24.75 820.0

pygmt/src/grdclip.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
)
1313
from pygmt.io import load_dataarray
1414

15+
__doctest_skip__ = ["grdclip"]
16+
1517

1618
@fmt_docstring
1719
@use_alias(
@@ -80,22 +82,22 @@ def grdclip(grid, **kwargs):
8082
8183
Example
8284
-------
83-
>>> import pygmt # doctest: +SKIP
85+
>>> import pygmt
8486
>>> # Load a grid of @earth_relief_30m data, with an x-range of 10 to 30,
8587
>>> # and a y-range of 15 to 25
8688
>>> grid = pygmt.datasets.load_earth_relief(
8789
... resolution="30m", region=[10, 30, 15, 25]
88-
... ) # doctest: +SKIP
90+
... )
8991
>>> # Report the minimum and maximum data values
90-
>>> [grid.data.min(), grid.data.max()] # doctest: +SKIP
92+
>>> [grid.data.min(), grid.data.max()]
9193
[179.0, 2103.0]
9294
>>> # Create a new grid from an input grid. Set all values below 1,000 to
9395
>>> # 0 and all values above 1,500 to 10,000
9496
>>> new_grid = pygmt.grdclip(
9597
... grid=grid, below=[1000, 0], above=[1500, 10000]
96-
... ) # doctest: +SKIP
98+
... )
9799
>>> # Report the minimum and maximum data values
98-
>>> [new_grid.data.min(), new_grid.data.max()] # doctest: +SKIP
100+
>>> [new_grid.data.min(), new_grid.data.max()]
99101
[0.0, 10000.0]
100102
"""
101103
with GMTTempFile(suffix=".nc") as tmpfile:

pygmt/src/grdcut.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
)
1313
from pygmt.io import load_dataarray
1414

15+
__doctest_skip__ = ["grdcut"]
16+
1517

1618
@fmt_docstring
1719
@use_alias(
@@ -90,17 +92,15 @@ def grdcut(grid, **kwargs):
9092
9193
Example
9294
-------
93-
>>> import pygmt # doctest: +SKIP
95+
>>> import pygmt
9496
>>> # Load a grid of @earth_relief_30m data, with an x-range of 10 to 30,
9597
>>> # and a y-range of 15 to 25
9698
>>> grid = pygmt.datasets.load_earth_relief(
9799
... resolution="30m", region=[10, 30, 15, 25]
98-
... ) # doctest: +SKIP
100+
... )
99101
>>> # Create a new grid from an input grid, with an x-range of 12 to 15,
100102
>>> # and a y-range of 21 to 24
101-
>>> new_grid = pygmt.grdcut(
102-
... grid=grid, region=[12, 15, 21, 24]
103-
... ) # doctest: +SKIP
103+
>>> new_grid = pygmt.grdcut(grid=grid, region=[12, 15, 21, 24])
104104
"""
105105
with GMTTempFile(suffix=".nc") as tmpfile:
106106
with Session() as lib:

pygmt/src/grdgradient.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
)
1515
from pygmt.io import load_dataarray
1616

17+
__doctest_skip__ = ["grdgradient"]
18+
1719

1820
@fmt_docstring
1921
@use_alias(
@@ -152,17 +154,14 @@ def grdgradient(grid, **kwargs):
152154
153155
Example
154156
-------
155-
>>> import pygmt # doctest: +SKIP
157+
>>> import pygmt
156158
>>> # Load a grid of @earth_relief_30m data, with an x-range of 10 to 30,
157159
>>> # and a y-range of 15 to 25
158160
>>> grid = pygmt.datasets.load_earth_relief(
159161
... resolution="30m", region=[10, 30, 15, 25]
160-
... ) # doctest: +SKIP
162+
... )
161163
>>> # Create a new grid from an input grid, set the azimuth to 10 degrees,
162-
>>> # and the direction to "c" for Cartesian coordinates
163-
>>> new_grid = pygmt.grdgradient(
164-
... grid=grid, azimuth=10, direction="c"
165-
... ) # doctest: +SKIP
164+
>>> new_grid = pygmt.grdgradient(grid=grid, azimuth=10)
166165
"""
167166
with GMTTempFile(suffix=".nc") as tmpfile:
168167
if "Q" in kwargs and "N" not in kwargs:

pygmt/src/grdproject.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
grdproject - Forward and inverse map transformation of grids.
33
"""
4-
54
from pygmt.clib import Session
65
from pygmt.exceptions import GMTInvalidInput
76
from pygmt.helpers import (
@@ -13,6 +12,8 @@
1312
)
1413
from pygmt.io import load_dataarray
1514

15+
__doctest_skip__ = ["grdproject"]
16+
1617

1718
@fmt_docstring
1819
@use_alias(
@@ -98,18 +99,16 @@ def grdproject(grid, **kwargs):
9899
99100
Example
100101
-------
101-
>>> import pygmt # doctest: +SKIP
102+
>>> import pygmt
102103
>>> # Load a grid of @earth_relief_30m data, with an x-range of 10 to 30,
103104
>>> # and a y-range of 15 to 25
104105
>>> grid = pygmt.datasets.load_earth_relief(
105106
... resolution="30m", region=[10, 30, 15, 25]
106-
... ) # doctest: +SKIP
107+
... )
107108
>>> # Create a new grid from the input grid, set the projection to
108109
>>> # Mercator, and set inverse to "True" to change from "geographic"
109110
>>> # to "rectangular"
110-
>>> new_grid = pygmt.grdproject(
111-
... grid=grid, projection="M10c", inverse=True
112-
... ) # doctest: +SKIP
111+
>>> new_grid = pygmt.grdproject(grid=grid, projection="M10c", inverse=True)
113112
"""
114113
if "J" not in kwargs:
115114
raise GMTInvalidInput("The projection must be specified.")

pygmt/src/grdsample.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
)
1313
from pygmt.io import load_dataarray
1414

15+
__doctest_skip__ = ["grdsample"]
16+
1517

1618
@fmt_docstring
1719
@use_alias(
@@ -76,17 +78,17 @@ def grdsample(grid, **kwargs):
7678
7779
Example
7880
-------
79-
>>> import pygmt # doctest: +SKIP
81+
>>> import pygmt
8082
>>> # Load a grid of @earth_relief_30m data, with an x-range of 10 to 30,
8183
>>> # and a y-range of 15 to 25
8284
>>> grid = pygmt.datasets.load_earth_relief(
8385
... resolution="30m", region=[10, 30, 15, 25]
84-
... ) # doctest: +SKIP
86+
... )
8587
>>> # Create a new grid from an input grid, change the registration,
8688
>>> # and set both x- and y-spacing to 0.5 degrees
8789
>>> new_grid = pygmt.grdsample(
8890
... grid=grid, translate=True, spacing=[0.5, 0.5]
89-
... ) # doctest: +SKIP
91+
... )
9092
"""
9193
with GMTTempFile(suffix=".nc") as tmpfile:
9294
with Session() as lib:

pygmt/src/inset.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from pygmt.clib import Session
77
from pygmt.helpers import build_arg_string, fmt_docstring, kwargs_to_strings, use_alias
88

9+
__doctest_skip__ = ["inset"]
10+
911

1012
@fmt_docstring
1113
@contextlib.contextmanager

pygmt/src/select.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use_alias,
1212
)
1313

14+
__doctest_skip__ = ["select"]
15+
1416

1517
@fmt_docstring
1618
@use_alias(
@@ -150,16 +152,12 @@ def select(data=None, outfile=None, **kwargs):
150152
151153
Example
152154
-------
153-
>>> import pygmt # doctest: +SKIP
155+
>>> import pygmt
154156
>>> # Load a table of ship observations of bathymetry off Baja California
155-
>>> data = pygmt.datasets.load_sample_data(
156-
... name="bathymetry"
157-
... ) # doctest: +SKIP
157+
>>> ship_data = pygmt.datasets.load_sample_data(name="bathymetry")
158158
>>> # Only return the data points that lie within the region between
159159
>>> # longitudes 246 and 247 and latitudes 20 and 21
160-
>>> pygmt.select(
161-
... data=ship_data, region=[246, 247, 20, 21]
162-
... ) # doctest: +SKIP
160+
>>> out = pygmt.select(data=ship_data, region=[246, 247, 20, 21])
163161
"""
164162

165163
with GMTTempFile(suffix=".csv") as tmpfile:

pygmt/src/sph2grd.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
)
1212
from pygmt.io import load_dataarray
1313

14+
__doctest_skip__ = ["sph2grd"]
15+
1416

1517
@fmt_docstring
1618
@use_alias(
@@ -66,12 +68,12 @@ def sph2grd(data, **kwargs):
6668
6769
Example
6870
-------
69-
>>> import pygmt # doctest: +SKIP
71+
>>> import pygmt
7072
>>> # Create a new grid from the remote file "EGM96_to_36.txt",
7173
>>> # set the grid spacing to 1, and the region to "g"
7274
>>> new_grid = pygmt.sph2grd(
7375
... data="@EGM96_to_36.txt", spacing=1, region="g"
74-
... ) # doctest: +SKIP
76+
... )
7577
"""
7678
with GMTTempFile(suffix=".nc") as tmpfile:
7779
with Session() as lib:

0 commit comments

Comments
 (0)