Skip to content

Commit dde23f1

Browse files
authored
Figure.meca: Add a test for passing event names via pandas.DataFrame (#2582)
1 parent 857472e commit dde23f1

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
outs:
22
- md5: 81203f9e3a43ec235cf4b5068f928b56
33
size: 10689
4-
path: test_meca_dict_eventname.png
4+
path: test_meca_eventname.png

pygmt/tests/test_meca.py

+48-14
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import numpy as np
55
import pandas as pd
66
import pytest
7-
from pygmt import Figure
7+
from packaging.version import Version
8+
from pygmt import Figure, __gmt_version__
89
from pygmt.helpers import GMTTempFile
910

1011

@@ -179,22 +180,55 @@ def test_meca_offset(inputtype):
179180
return fig
180181

181182

182-
@pytest.mark.mpl_image_compare
183-
def test_meca_dict_eventname():
183+
# Passing event names via pandas doesn't work for GMT<=6.4, thus marked as
184+
# xfail. See https://github.com/GenericMappingTools/pygmt/issues/2524.
185+
@pytest.mark.mpl_image_compare(filename="test_meca_eventname.png")
186+
@pytest.mark.parametrize(
187+
"inputtype",
188+
[
189+
"args",
190+
pytest.param(
191+
"dataframe",
192+
marks=pytest.mark.skipif(
193+
condition=Version(__gmt_version__) < Version("6.5.0"),
194+
reason="Upstream bug fixed in https://github.com/GenericMappingTools/gmt/pull/7557",
195+
),
196+
),
197+
],
198+
)
199+
def test_meca_eventname(inputtype):
184200
"""
185-
Test offsetting beachballs for a dict input.
201+
Test passing event names.
186202
"""
203+
if inputtype == "args":
204+
args = {
205+
"spec": {"strike": 330, "dip": 30, "rake": 90, "magnitude": 3},
206+
"longitude": -124,
207+
"latitude": 48,
208+
"depth": 12.0,
209+
"event_name": "Event20220311",
210+
}
211+
elif inputtype == "dataframe":
212+
# Test pandas.DataFrame input. Requires GMT>=6.5.
213+
# See https://github.com/GenericMappingTools/pygmt/issues/2524.
214+
# The numeric columns must be in float type to trigger the bug.
215+
args = {
216+
"spec": pd.DataFrame(
217+
{
218+
"longitude": [-124.0],
219+
"latitude": [48.0],
220+
"depth": [12.0],
221+
"strike": [330.0],
222+
"dip": [30.0],
223+
"rake": [90.0],
224+
"magnitude": [3.0],
225+
"event_name": ["Event20220311"],
226+
}
227+
)
228+
}
187229
fig = Figure()
188-
focal_mechanism = {"strike": 330, "dip": 30, "rake": 90, "magnitude": 3}
189230
fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True)
190-
fig.meca(
191-
spec=focal_mechanism,
192-
scale="1c",
193-
longitude=-124,
194-
latitude=48,
195-
depth=12.0,
196-
event_name="Event20220311",
197-
)
231+
fig.meca(scale="1c", **args)
198232
return fig
199233

200234

@@ -219,7 +253,7 @@ def test_meca_dict_offset_eventname():
219253
return fig
220254

221255

222-
@pytest.mark.mpl_image_compare(filename="test_meca_dict_eventname.png")
256+
@pytest.mark.mpl_image_compare(filename="test_meca_eventname.png")
223257
def test_meca_spec_dict_all_scalars():
224258
"""
225259
Test supplying a dict with scalar values for all focal parameters.

0 commit comments

Comments
 (0)