Skip to content

Commit 17d1ce8

Browse files
committed
Merge branch 'main' into alias-system
2 parents b8fe689 + 0348fad commit 17d1ce8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+610
-170
lines changed

.github/workflows/ci_tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
GH_TOKEN: ${{ github.token }}
153153

154154
- name: Install uv
155-
uses: astral-sh/[email protected].1
155+
uses: astral-sh/[email protected].2
156156
with:
157157
python-version: ${{ matrix.python-version }}
158158

@@ -183,7 +183,7 @@ jobs:
183183

184184
# Upload coverage to Codecov
185185
- name: Upload coverage to Codecov
186-
uses: codecov/[email protected].0
186+
uses: codecov/[email protected].2
187187
if: success() || failure()
188188
with:
189189
use_oidc: true

doc/_templates/autosummary/class.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
.. rubric:: Methods Summary
1818

1919
.. autosummary::
20+
:toctree:
2021
{% for item in methods %}
2122
{% if item != '__init__' %}
2223
{{ objname }}.{{ item }}

doc/_templates/autosummary/module.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
.. rubric:: Classes
1717

1818
.. autosummary::
19-
:toctree: ./
19+
:toctree:
2020
{% for item in classes %}
2121
{{ item }}
2222
{% endfor %}
@@ -29,7 +29,7 @@
2929
.. rubric:: Functions
3030

3131
.. autosummary::
32-
:toctree: ./
32+
:toctree:
3333
{% for item in functions %}
3434
{{ item }}
3535
{% endfor %}
@@ -42,7 +42,7 @@
4242
.. rubric:: Exceptions
4343

4444
.. autosummary::
45-
:toctree: ./
45+
:toctree:
4646
{% for item in exceptions %}
4747
{{ item }}
4848
{% endfor %}

doc/api/index.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
.. _api:
2-
31
API Reference
42
=============
53

6-
.. automodule:: pygmt
4+
This page gives an overview of all public PyGMT objects, functions and methods.
75

86
.. currentmodule:: pygmt
97

@@ -208,6 +206,14 @@ Common Parameters
208206
Box
209207
Frame
210208

209+
Xarray Integration
210+
------------------
211+
212+
.. autosummary::
213+
:toctree: generated
214+
215+
GMTBackendEntrypoint
216+
211217
Enums
212218
-----
213219

pygmt/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
x2sys_init,
6666
xyz2grd,
6767
)
68+
from pygmt.xarray import GMTBackendEntrypoint
6869

6970
# Start our global modern mode session
7071
_begin()

pygmt/_typing.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44

55
import contextlib
66
import importlib
7+
import os
78
from collections.abc import Sequence
89
from typing import Literal
910

1011
import numpy as np
12+
import pandas as pd
13+
import xarray as xr
1114

1215
# Anchor codes
1316
AnchorCode = Literal["TL", "TC", "TR", "ML", "MC", "MR", "BL", "BC", "BR"]
@@ -16,3 +19,9 @@
1619
StringArrayTypes = Sequence[str] | np.ndarray
1720
with contextlib.suppress(ImportError):
1821
StringArrayTypes |= importlib.import_module(name="pyarrow").StringArray
22+
23+
# PathLike and TableLike types
24+
PathLike = str | os.PathLike
25+
TableLike = dict | np.ndarray | pd.DataFrame | xr.Dataset
26+
with contextlib.suppress(ImportError):
27+
TableLike |= importlib.import_module(name="geopandas").GeoDataFrame

pygmt/clib/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1772,7 +1772,7 @@ def virtualfile_in(
17721772
check_kind : str or None
17731773
Used to validate the type of data that can be passed in. Choose
17741774
from 'raster', 'vector', or None. Default is None (no validation).
1775-
data : str or pathlib.Path or xarray.DataArray or {table-like} or dict or None
1775+
data
17761776
Any raster or vector data format. This could be a file name or
17771777
path, a raster grid, a vector matrix/arrays, or other supported
17781778
data input.

pygmt/figure.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
import base64
66
import os
7-
from pathlib import Path, PurePath
7+
from pathlib import Path
88
from tempfile import TemporaryDirectory
99
from typing import Literal, overload
1010

11+
from pygmt._typing import PathLike
12+
1113
try:
1214
import IPython
1315

@@ -137,7 +139,7 @@ def region(self) -> np.ndarray:
137139

138140
def savefig(
139141
self,
140-
fname: str | PurePath,
142+
fname: PathLike,
141143
transparent: bool = False,
142144
crop: bool = True,
143145
anti_alias: bool = True,

pygmt/helpers/decorators.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,11 @@
7171
:gmt-docs:`gmt.html#f-full`.""",
7272
"cores": r"""
7373
cores : bool or int
74-
[[**-**]\ *n*].
75-
Limit the number of cores to be used in any OpenMP-enabled
76-
multi-threaded algorithms. By default we try to use all available
77-
cores. Set a number *n* to only use n cores (if too large it will
78-
be truncated to the maximum cores available). Finally, give a
79-
negative number *-n* to select (all - *n*) cores (or at least 1 if
80-
*n* equals or exceeds all).
81-
""",
74+
Specify the number of active cores to be used in any OpenMP-enabled
75+
multi-threaded algorithms. By default, all available cores are used. Set a
76+
positive number *n* to use *n* cores (if too large it will be truncated to
77+
the maximum cores available); or set a negative number *-n* to select
78+
(all - *n*) cores (or at least 1 if *n* equals or exceeds all).""",
8279
"distcalc": r"""
8380
distcalc : str
8481
Determine how spherical distances are calculated
@@ -141,7 +138,7 @@
141138
- **+p**: specify that the current value minus the previous
142139
value must exceed *gap* for a break to be imposed.""",
143140
"grid": r"""
144-
grid : str or xarray.DataArray
141+
grid
145142
Name of the input grid file or the grid loaded as a
146143
:class:`xarray.DataArray` object.
147144
@@ -408,7 +405,7 @@ def fmt_docstring(module_func):
408405
...
409406
... Parameters
410407
... ----------
411-
... data : str, {table-like}
408+
... data
412409
... Pass in either a file name to an ASCII data table, a 2-D
413410
... {table-classes}.
414411
... {region}
@@ -423,7 +420,7 @@ def fmt_docstring(module_func):
423420
<BLANKLINE>
424421
Parameters
425422
----------
426-
data : str, numpy.ndarray, pandas.DataFrame, xarray.Dataset, or geo...
423+
data
427424
Pass in either a file name to an ASCII data table, a 2-D
428425
:class:`numpy.ndarray`, a :class:`pandas.DataFrame`, an
429426
:class:`xarray.Dataset` made up of 1-D :class:`xarray.DataArray`
@@ -455,9 +452,6 @@ def fmt_docstring(module_func):
455452
aliases.append(f" - {arg} = {alias}")
456453
filler_text["aliases"] = "\n".join(aliases)
457454

458-
filler_text["table-like"] = (
459-
"numpy.ndarray, pandas.DataFrame, xarray.Dataset, or geopandas.GeoDataFrame"
460-
)
461455
filler_text["table-classes"] = (
462456
":class:`numpy.ndarray`, a :class:`pandas.DataFrame`, an\n"
463457
" :class:`xarray.Dataset` made up of 1-D :class:`xarray.DataArray`\n"

pygmt/helpers/utils.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import io
66
import os
7-
import pathlib
87
import shutil
98
import string
109
import subprocess
@@ -17,6 +16,7 @@
1716
from typing import Any, Literal
1817

1918
import xarray as xr
19+
from pygmt._typing import PathLike
2020
from pygmt.encodings import charset
2121
from pygmt.exceptions import GMTInvalidInput
2222

@@ -387,10 +387,10 @@ def data_kind(
387387
match data:
388388
case None if required: # No data provided and required=True.
389389
kind = "empty"
390-
case str() | pathlib.PurePath(): # One file.
390+
case str() | os.PathLike(): # One file.
391391
kind = "file"
392392
case list() | tuple() if all(
393-
isinstance(_file, str | pathlib.PurePath) for _file in data
393+
isinstance(_file, str | os.PathLike) for _file in data
394394
): # A list/tuple of files.
395395
kind = "file"
396396
case io.StringIO():
@@ -482,8 +482,8 @@ def non_ascii_to_octal(argstr: str, encoding: Encoding = "ISOLatin1+") -> str:
482482
def build_arg_list( # noqa: PLR0912
483483
kwdict: dict[str, Any],
484484
confdict: Mapping[str, Any] | None = None,
485-
infile: str | pathlib.PurePath | Sequence[str | pathlib.PurePath] | None = None,
486-
outfile: str | pathlib.PurePath | None = None,
485+
infile: PathLike | Sequence[PathLike] | None = None,
486+
outfile: PathLike | None = None,
487487
) -> list[str]:
488488
r"""
489489
Convert keyword dictionaries and input/output files into a list of GMT arguments.
@@ -581,19 +581,19 @@ def build_arg_list( # noqa: PLR0912
581581
gmt_args.extend(f"--{key}={value}" for key, value in confdict.items())
582582

583583
if infile: # infile can be a single file or a list of files
584-
if isinstance(infile, str | pathlib.PurePath):
585-
gmt_args = [str(infile), *gmt_args]
584+
if isinstance(infile, str | os.PathLike):
585+
gmt_args = [os.fspath(infile), *gmt_args]
586586
else:
587-
gmt_args = [str(_file) for _file in infile] + gmt_args
587+
gmt_args = [os.fspath(_file) for _file in infile] + gmt_args
588588
if outfile is not None:
589589
if (
590-
not isinstance(outfile, str | pathlib.PurePath)
591-
or str(outfile) in {"", ".", ".."}
592-
or str(outfile).endswith(("/", "\\"))
590+
not isinstance(outfile, str | os.PathLike)
591+
or os.fspath(outfile) in {"", ".", ".."}
592+
or os.fspath(outfile).endswith(("/", "\\"))
593593
):
594594
msg = f"Invalid output file name '{outfile}'."
595595
raise GMTInvalidInput(msg)
596-
gmt_args.append(f"->{outfile}")
596+
gmt_args.append(f"->{os.fspath(outfile)}")
597597
return gmt_args
598598

599599

@@ -632,7 +632,7 @@ def is_nonstr_iter(value: Any) -> bool:
632632
return isinstance(value, Iterable) and not isinstance(value, str)
633633

634634

635-
def launch_external_viewer(fname: str, waiting: float = 0) -> None:
635+
def launch_external_viewer(fname: PathLike, waiting: float = 0) -> None:
636636
"""
637637
Open a file in an external viewer program.
638638

0 commit comments

Comments
 (0)