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

Remove the deprecated load_mars_shape function (deprecated since v0.6.0) #2304

Merged
merged 13 commits into from
Jan 31, 2023
Merged
7 changes: 0 additions & 7 deletions doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,6 @@ and store them in GMT's user data directory.
datasets.load_earth_vertical_gravity_gradient
datasets.load_sample_data

The following functions are deprecated since v0.6.0 and will be removed in v0.9.0.
Use :func:`pygmt.datasets.load_sample_data` instead.

.. autosummary::
:toctree: generated

datasets.load_mars_shape

.. currentmodule:: pygmt

Expand Down
2 changes: 1 addition & 1 deletion pygmt/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
from pygmt.datasets.earth_vertical_gravity_gradient import (
load_earth_vertical_gravity_gradient,
)
from pygmt.datasets.samples import list_sample_data, load_mars_shape, load_sample_data
from pygmt.datasets.samples import list_sample_data, load_sample_data
45 changes: 10 additions & 35 deletions pygmt/datasets/samples.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
Functions to load sample data.
"""
import warnings

import pandas as pd
from pygmt.exceptions import GMTInvalidInput
from pygmt.io import load_dataarray
Expand Down Expand Up @@ -68,28 +66,22 @@ def load_sample_data(name):
if name not in names:
raise GMTInvalidInput(f"Invalid dataset name '{name}'.")

# Dictionary of public load functions for backwards compatibility
load_func_old = {
"mars_shape": load_mars_shape,
}

# Dictionary of private load functions
load_func = {
"bathymetry": _load_baja_california_bathymetry,
"earth_relief_holes": _load_earth_relief_holes,
"fractures": _load_fractures_compilation,
"hotspots": _load_hotspots,
"japan_quakes": _load_japan_quakes,
"mars_shape": _load_mars_shape,
"maunaloa_co2": _load_maunaloa_co2,
"notre_dame_topography": _load_notre_dame_topography,
"ocean_ridge_points": _load_ocean_ridge_points,
"rock_compositions": _load_rock_sample_compositions,
"usgs_quakes": _load_usgs_quakes,
}

if name in load_func_old:
data = load_func_old[name](suppress_warning=True)
elif name in load_func:
if name in load_func:
Copy link
Member

Choose a reason for hiding this comment

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

We already checked if a valid name is given at line 66, so no need to check if name in load_func.

Please change:

if name in load_func:
    data = load_func[name]()
return data

to

return load_func[name]()

data = load_func[name]()

return data
Expand Down Expand Up @@ -221,40 +213,23 @@ def _load_hotspots():
)


def load_mars_shape(**kwargs):
def _load_mars_shape():
"""
(Deprecated) Load a table of data for the shape of Mars.
Load a table of data for the shape of Mars as a pandas.DataFrame.
willschlitzer marked this conversation as resolved.
Show resolved Hide resolved

.. warning:: Deprecated since v0.6.0. This function has been replaced with
``load_sample_data(name="mars_shape")`` and will be removed in
v0.9.0.

This is the ``@mars370d.txt`` dataset used in GMT examples, with data and
information from Smith, D. E., and M. T. Zuber (1996), The shape of Mars
and the topographic signature of the hemispheric dichotomy. Data columns
are "longitude," "latitude", and "radius (meters)."
yvonnefroehlich marked this conversation as resolved.
Show resolved Hide resolved

The data are downloaded to a cache directory (usually ``~/.gmt/cache``) the
first time you invoke this function. Afterwards, it will load the data from
the cache. So you'll need an internet connection the first time around.
Data and information are from Smith, D. E., and M. T. Zuber (1996),
The shape of Mars and the topographic signature of the hemispheric
dichotomy.

Returns
-------
data : pandas.DataFrame
The data table with columns "longitude", "latitude", and "radius(m)".
The data table with column names "longitude", "latitude", and
"radius_m".
"""

if "suppress_warning" not in kwargs:
warnings.warn(
"This function has been deprecated since v0.6.0 and will be "
"removed in v0.9.0. Please use "
"load_sample_data(name='mars_shape') instead.",
category=FutureWarning,
stacklevel=2,
)
fname = which("@mars370d.txt", download="c")
data = pd.read_csv(
fname, sep="\t", header=None, names=["longitude", "latitude", "radius(m)"]
fname, sep="\t", header=None, names=["longitude", "latitude", "radius_m"]
)
return data

Expand Down
10 changes: 4 additions & 6 deletions pygmt/tests/test_datasets_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy.testing as npt
import pandas as pd
import pytest
from pygmt.datasets import load_mars_shape, load_sample_data
from pygmt.datasets import load_sample_data
from pygmt.exceptions import GMTInvalidInput


Expand Down Expand Up @@ -128,16 +128,14 @@ def test_mars_shape():
"""
Check that the @mars370d.txt dataset loads without errors.
"""
with pytest.warns(expected_warning=FutureWarning) as record:
data = load_mars_shape()
assert len(record) == 1
data = load_sample_data(name="mars_shape")
assert data.shape == (370, 3)
assert data["longitude"].min() == 0.008
assert data["longitude"].max() == 359.983
assert data["latitude"].min() == -79.715
assert data["latitude"].max() == 85.887
assert data["radius(m)"].min() == -6930
assert data["radius(m)"].max() == 15001
assert data["radius_m"].min() == -6930
assert data["radius_m"].max() == 15001


def test_hotspots():
Expand Down