|
4 | 4 | import numpy as np |
5 | 5 | import pandas as pd |
6 | 6 | import pytest |
7 | | -from pygmt import Figure |
| 7 | +from packaging.version import Version |
| 8 | +from pygmt import Figure, __gmt_version__ |
8 | 9 | from pygmt.helpers import GMTTempFile |
9 | 10 |
|
10 | 11 |
|
@@ -179,20 +180,52 @@ def test_meca_offset(inputtype): |
179 | 180 | return fig |
180 | 181 |
|
181 | 182 |
|
| 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. |
182 | 185 | @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 | +) |
184 | 199 | def test_meca_eventname(inputtype): |
185 | 200 | """ |
186 | 201 | Test passing event names. |
187 | 202 | """ |
188 | | - if inputtype == "eventname_args": |
| 203 | + if inputtype == "args": |
189 | 204 | args = { |
190 | 205 | "spec": {"strike": 330, "dip": 30, "rake": 90, "magnitude": 3}, |
191 | 206 | "longitude": -124, |
192 | 207 | "latitude": 48, |
193 | 208 | "depth": 12.0, |
194 | 209 | "event_name": "Event20220311", |
195 | 210 | } |
| 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 | + } |
196 | 229 | fig = Figure() |
197 | 230 | fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True) |
198 | 231 | fig.meca(scale="1c", **args) |
|
0 commit comments