Skip to content

Commit c1228c0

Browse files
committed
Test passing event names via pandas.DataFrame
1 parent 3c9fe8e commit c1228c0

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

pygmt/tests/test_meca.py

Lines changed: 36 additions & 3 deletions
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,20 +180,52 @@ def test_meca_offset(inputtype):
179180
return fig
180181

181182

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.
182185
@pytest.mark.mpl_image_compare(filename="test_meca_eventname.png")
183-
@pytest.mark.parametrize("inputtype", ["eventname_args"])
186+
@pytest.mark.parametrize(
187+
"inputtype",
188+
[
189+
"args",
190+
pytest.param(
191+
"pandas",
192+
marks=pytest.mark.xfail(
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+
)
184199
def test_meca_eventname(inputtype):
185200
"""
186201
Test passing event names.
187202
"""
188-
if inputtype == "eventname_args":
203+
if inputtype == "args":
189204
args = {
190205
"spec": {"strike": 330, "dip": 30, "rake": 90, "magnitude": 3},
191206
"longitude": -124,
192207
"latitude": 48,
193208
"depth": 12.0,
194209
"event_name": "Event20220311",
195210
}
211+
elif inputtype == "pandas":
212+
# Test pandas 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+
}
196229
fig = Figure()
197230
fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True)
198231
fig.meca(scale="1c", **args)

0 commit comments

Comments
 (0)