Skip to content

Standardize docstrings for table-like inputs #1186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
192b651
Add standardized filler text for table-like data inputs
weiji14 Apr 6, 2021
1d06354
Reformat pygmt.info docstring to use table-like filler
weiji14 Apr 6, 2021
01b2038
Reformat plot and plot3d docstring to use table-like filler
weiji14 Apr 6, 2021
1d66c40
Reformat data_kind and virtualfile_from_data docstring to use table-like
weiji14 Apr 6, 2021
6084578
Reformat rose docstring to use table-like filler
weiji14 Apr 6, 2021
913ef24
Merge branch 'master' into standardize-table-like-docs
weiji14 May 9, 2021
a003a21
Reformat grdtrack docstring to use table-like filler
weiji14 May 9, 2021
99d1191
Reformat velo docstring to use table-like filler
weiji14 May 9, 2021
0df6a5a
Reformat wiggle docstring to use table-like filler
weiji14 May 9, 2021
1ad6b94
Reformat histogram docstring to use table-like filler
weiji14 May 9, 2021
0536017
Add Python list to histogram's table param description
weiji14 May 10, 2021
7121c31
Merge branch 'master' into standardize-table-like-docs
weiji14 May 14, 2021
44f941b
Use table-classes filler in docstring description
weiji14 May 14, 2021
8980e8a
Update pygmt/helpers/decorators.py
weiji14 May 14, 2021
cb61f41
Update pygmt/clib/session.py to put table-like filler last
weiji14 May 16, 2021
c4043f7
Merge branch 'master' into standardize-table-like-docs
weiji14 May 16, 2021
983dc16
Use fmt_docstring decorator on virtualfile_from_data function
weiji14 May 16, 2021
e9a798b
Apply suggestions from code review
weiji14 May 16, 2021
91e6558
Add a doctest for the table-classes filler text
weiji14 May 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,7 @@ def virtualfile_from_data(
check_kind : str
Used to validate the type of data that can be passed in. Choose
from 'raster', 'vector' or None. Default is None (no validation).
data : str, xarray.DataArray, 2d array, or None
data : str or xarray.DataArray or {table-like} or None
Any raster or vector data format. This could be a file name, a
raster grid, a vector matrix/arrays, or other supported data input.
x/y/z : 1d arrays or None
Expand Down
14 changes: 14 additions & 0 deletions pygmt/helpers/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def fmt_docstring(module_func):
...
... Parameters
... ----------
... data : {table-like}
... {R}
... {J}
...
Expand All @@ -200,6 +201,7 @@ def fmt_docstring(module_func):
<BLANKLINE>
Parameters
----------
data : numpy.ndarray or pandas.DataFrame or xarray.Dataset
region : str or list
*Required if this is the first plot command*.
*xmin/xmax/ymin/ymax*\ [**+r**][**+u**\ *unit*].
Expand All @@ -224,6 +226,18 @@ def fmt_docstring(module_func):
aliases.append("- {} = {}".format(arg, alias))
filler_text["aliases"] = "\n".join(aliases)

filler_text["table-like"] = (
"numpy.ndarray or "
"pandas.DataFrame or "
"xarray.Dataset"
# "geopandas.GeoDataFrame"
)
filler_text["table-classes"] = (
":class:`numpy.ndarray`, a :class:`pandas.DataFrame`, or an \n"
" :class:`xarray.Dataset` made up of 1D :class:`xarray.DataArray` \n"
" data variables containing the tabular data."
)

for marker, text in COMMON_OPTIONS.items():
# Remove the indentation and the first line break from the multiline
# strings so that it doesn't mess up the original docstring
Expand Down
6 changes: 4 additions & 2 deletions pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def data_kind(data, x=None, y=None, z=None):

Parameters
----------
data : str, xarray.DataArray, 2d array, or None
Data file name, xarray.DataArray or numpy array.
data : str or xarray.DataArray or {table-like} or None
Pass in either a file name to an ASCII data table, an
:class:`xarray.DataArray`, a 1D/2D
{table-classes}.
x/y : 1d arrays or None
x and y columns as numpy arrays.
z : 1d array or None
Expand Down
7 changes: 3 additions & 4 deletions pygmt/src/grdtrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ def grdtrack(points, grid, newcolname=None, outfile=None, **kwargs):

Parameters
----------
points : pandas.DataFrame or str
Either a table with (x, y) or (lon, lat) values in the first two
columns, or a filename (e.g. csv, txt format). More columns may be
present.
points : str or {table-like}
Pass in either a file name to an ASCII data table, a 2D
{table-classes}.

grid : xarray.DataArray or str
Gridded array from which to sample values from, or a filename (netcdf
Expand Down
6 changes: 4 additions & 2 deletions pygmt/src/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ def histogram(self, table, **kwargs):

Parameters
----------
table : str, list, or 1d array
A data file name, list, or 1d numpy array. This is a required argument.
table : str or list or {table-like}
Pass in either a file name to an ASCII data table, a Python list, a 2D
{table-classes}.
This is a required argument.
{J}
{R}
{B}
Expand Down
7 changes: 3 additions & 4 deletions pygmt/src/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ def info(table, **kwargs):

Parameters
----------
table : str or np.ndarray or pandas.DataFrame or xarray.Dataset
Pass in either a file name to an ASCII data table, a 1D/2D numpy array,
a pandas dataframe, or an xarray dataset made up of 1D xarray.DataArray
data variables.
table : str or {table-like}
Pass in either a file name to an ASCII data table, a 1D/2D
{table-classes}.
per_column : bool
Report the min/max values per column in separate columns.
spacing : str
Expand Down
9 changes: 5 additions & 4 deletions pygmt/src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ def plot(self, x=None, y=None, data=None, size=None, direction=None, **kwargs):
x/y : float or 1d arrays
The x and y coordinates, or arrays of x and y coordinates of the
data points
data : str or 2d array
Either a data file name or a 2d numpy array with the tabular data.
Use parameter ``columns`` to choose which columns are x, y, color,
and size, respectively.
data : str or {table-like}
Pass in either a file name to an ASCII data table, a 2D
{table-classes}.
Use parameter ``columns`` to choose which columns are x, y, color, and
size, respectively.
size : 1d array
The size of the data points in units specified using ``style``.
Only valid if using ``x``/``y``.
Expand Down
9 changes: 5 additions & 4 deletions pygmt/src/plot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ def plot3d(
x/y/z : float or 1d arrays
The x, y, and z coordinates, or arrays of x, y and z coordinates of
the data points
data : str or 2d array
Either a data file name or a 2d numpy array with the tabular data.
Use parameter ``columns`` to choose which columns are x, y, z,
color, and size, respectively.
data : str or {table-like}
Pass in either a file name to an ASCII data table, a 2D
{table-classes}.
Use parameter ``columns`` to choose which columns are x, y, z, color,
and size, respectively.
size : 1d array
The size of the data points in units specified in ``style``.
Only valid if using ``x``/``y``/``z``.
Expand Down
14 changes: 7 additions & 7 deletions pygmt/src/rose.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ def rose(self, length=None, azimuth=None, data=None, **kwargs):
Length and azimuth values, or arrays of length and azimuth
values

data : str or 2d array
Either a data file name or a 2d numpy array with the tabular data.
Use option ``columns`` to choose which columns are length and
azimuth, respectively. If a file with only azimuths is given,
use ``columns`` to indicate the single column with azimuths; then
all lengths are set to unity (see ``scale = 'u'`` to set actual
lengths to unity as well).
data : str or {table-like}
Pass in either a file name to an ASCII data table, a 2D
{table-classes}.
Use option ``columns`` to choose which columns are length and azimuth,
respectively. If a file with only azimuths is given, use ``columns`` to
indicate the single column with azimuths; then all lengths are set to
unity (see ``scale = 'u'`` to set actual lengths to unity as well).

orientation : bool
Specifies that the input data are orientation data (i.e., have a
Expand Down
9 changes: 5 additions & 4 deletions pygmt/src/velo.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ def velo(self, data=None, **kwargs):

Parameters
----------
data : str or numpy.ndarray or pandas.DataFrame
Either a file name, a 2D :class:`numpy.ndarray` or a
:class:`pandas.DataFrame` with the tabular data. Note that text columns
are only supported with file or pandas DataFrame inputs.
data : str or {table-like}
Pass in either a file name to an ASCII data table, a 2D
{table-classes}.
Note that text columns are only supported with file or pandas DataFrame
inputs.

spec: str
Selects the meaning of the columns in the data file and the figure to
Expand Down
5 changes: 3 additions & 2 deletions pygmt/src/wiggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ def wiggle(self, x=None, y=None, z=None, data=None, **kwargs):
----------
x/y/z : 1d arrays
The arrays of x and y coordinates and z data points.
data : str or 2d array
Either a data file name or a 2d numpy array with the tabular data.
data : str or {table-like}
Pass in either a file name to an ASCII data table, a 2D
{table-classes}.
Use parameter ``columns`` to choose which columns are x, y, z,
respectively.
{J}
Expand Down