Skip to content
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

TYP: Add type hints support for pygmt.datasets.load_sample_data #2859

Merged
merged 6 commits into from
Dec 15, 2023
Merged
Changes from 3 commits
Commits
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
25 changes: 18 additions & 7 deletions pygmt/datasets/samples.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Functions to load sample data.
"""
from typing import Callable, NamedTuple
from typing import Callable, Literal, NamedTuple

import pandas as pd
from pygmt.exceptions import GMTInvalidInput
Expand Down Expand Up @@ -70,7 +70,6 @@ def _load_baja_california_bathymetry():
The data table. The column names are "longitude", "latitude",
and "bathymetry".
"""

fname = which("@tut_ship.xyz", download="c")
return pd.read_csv(
fname, sep="\t", header=None, names=["longitude", "latitude", "bathymetry"]
Expand Down Expand Up @@ -99,10 +98,9 @@ def _load_fractures_compilation():
Returns
-------
data : pandas.DataFrame
The data table. The column names are "length" and
"azimuth" of the fractures.
The data table. The column names are "length" and "azimuth" of
the fractures.
"""

fname = which("@fractures_06.txt", download="c")
data = pd.read_csv(
fname, header=None, delim_whitespace=True, names=["azimuth", "length"]
Expand Down Expand Up @@ -166,7 +164,6 @@ def _load_rock_sample_compositions():
The data table with columns "limestone", "water", "air",
and "permittivity".
"""

fname = which("@ternary.txt", download="c")
return pd.read_csv(
fname,
Expand Down Expand Up @@ -300,7 +297,21 @@ def list_sample_data():
return {name: dataset.description for name, dataset in datasets.items()}


def load_sample_data(name):
def load_sample_data(
name: Literal[
"bathymetry",
"earth_relief_holes",
"fractures",
"hotspots",
"japan_quakes",
"mars_shape",
"maunaloa_co2",
"notre_dame_topography",
"ocean_ridge_points",
"rock_compositions",
"usgs_quakes",
],
):
Comment on lines +300 to +314
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far in line 313 (currently) or 324 (after this PR):

Parameters
----------
name : str
Name of the dataset to load.

was not changed to

name

Analogous as done for data_source in PR #2849.

for all resolutions except ``"15s"`` which is ``"pixel"`` only.
data_source
Select the source for the Earth relief data. Available options are:

Or was this intended because the list of available input names is a bit longer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 10a7ce4. Now it looks like:

image

Yes, it's a little bit longer, but I feel it's still acceptable.

"""
Load an example dataset from the GMT server.

Expand Down