diff --git a/pygmt/tests/baseline/test_meca_dict_eventname.png.dvc b/pygmt/tests/baseline/test_meca_eventname.png.dvc similarity index 61% rename from pygmt/tests/baseline/test_meca_dict_eventname.png.dvc rename to pygmt/tests/baseline/test_meca_eventname.png.dvc index 61e47357f70..a6dedc1effc 100644 --- a/pygmt/tests/baseline/test_meca_dict_eventname.png.dvc +++ b/pygmt/tests/baseline/test_meca_eventname.png.dvc @@ -1,4 +1,4 @@ outs: - md5: 81203f9e3a43ec235cf4b5068f928b56 size: 10689 - path: test_meca_dict_eventname.png + path: test_meca_eventname.png diff --git a/pygmt/tests/test_meca.py b/pygmt/tests/test_meca.py index cbff884ea75..f54f6b7d16a 100644 --- a/pygmt/tests/test_meca.py +++ b/pygmt/tests/test_meca.py @@ -4,7 +4,8 @@ import numpy as np import pandas as pd import pytest -from pygmt import Figure +from packaging.version import Version +from pygmt import Figure, __gmt_version__ from pygmt.helpers import GMTTempFile @@ -179,22 +180,55 @@ def test_meca_offset(inputtype): return fig -@pytest.mark.mpl_image_compare -def test_meca_dict_eventname(): +# Passing event names via pandas doesn't work for GMT<=6.4, thus marked as +# xfail. See https://github.com/GenericMappingTools/pygmt/issues/2524. +@pytest.mark.mpl_image_compare(filename="test_meca_eventname.png") +@pytest.mark.parametrize( + "inputtype", + [ + "args", + pytest.param( + "dataframe", + marks=pytest.mark.skipif( + condition=Version(__gmt_version__) < Version("6.5.0"), + reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/7557", + ), + ), + ], +) +def test_meca_eventname(inputtype): """ - Test offsetting beachballs for a dict input. + Test passing event names. """ + if inputtype == "args": + args = { + "spec": {"strike": 330, "dip": 30, "rake": 90, "magnitude": 3}, + "longitude": -124, + "latitude": 48, + "depth": 12.0, + "event_name": "Event20220311", + } + elif inputtype == "dataframe": + # Test pandas.DataFrame input. Requires GMT>=6.5. + # See https://github.com/GenericMappingTools/pygmt/issues/2524. + # The numeric columns must be in float type to trigger the bug. + args = { + "spec": pd.DataFrame( + { + "longitude": [-124.0], + "latitude": [48.0], + "depth": [12.0], + "strike": [330.0], + "dip": [30.0], + "rake": [90.0], + "magnitude": [3.0], + "event_name": ["Event20220311"], + } + ) + } fig = Figure() - focal_mechanism = {"strike": 330, "dip": 30, "rake": 90, "magnitude": 3} fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True) - fig.meca( - spec=focal_mechanism, - scale="1c", - longitude=-124, - latitude=48, - depth=12.0, - event_name="Event20220311", - ) + fig.meca(scale="1c", **args) return fig @@ -219,7 +253,7 @@ def test_meca_dict_offset_eventname(): return fig -@pytest.mark.mpl_image_compare(filename="test_meca_dict_eventname.png") +@pytest.mark.mpl_image_compare(filename="test_meca_eventname.png") def test_meca_spec_dict_all_scalars(): """ Test supplying a dict with scalar values for all focal parameters.