Skip to content

Commit ecdb66c

Browse files
seismanweiji14
andauthored
meca: Fix the bug when passing a dict of scalar values to the spec parameter (#2174)
Co-authored-by: Wei Ji <[email protected]>
1 parent e4e4c43 commit ecdb66c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pygmt/src/meca.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ def meca(
283283

284284
# convert dict to pd.DataFrame so columns can be reordered
285285
if isinstance(spec, dict):
286+
# convert values to ndarray so pandas doesn't complain about "all
287+
# scalar values". See
288+
# https://github.com/GenericMappingTools/pygmt/pull/2174
289+
spec = {key: np.atleast_1d(value) for key, value in spec.items()}
286290
spec = pd.DataFrame(spec)
287291

288292
# expected columns are:

pygmt/tests/test_meca.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,3 +291,29 @@ def test_meca_dict_offset_eventname():
291291
event_name="Event20220311",
292292
)
293293
return fig
294+
295+
296+
@pytest.mark.mpl_image_compare(filename="test_meca_dict_eventname.png")
297+
def test_meca_spec_dict_all_scalars():
298+
"""
299+
Test supplying a dict with scalar values for all focal parameters.
300+
301+
This is a regression test for
302+
https://github.com/GenericMappingTools/pygmt/pull/2174
303+
"""
304+
fig = Figure()
305+
fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True)
306+
fig.meca(
307+
spec=dict(
308+
strike=330,
309+
dip=30,
310+
rake=90,
311+
magnitude=3,
312+
longitude=-124,
313+
latitude=48,
314+
depth=12.0,
315+
event_name="Event20220311",
316+
),
317+
scale="1c",
318+
)
319+
return fig

0 commit comments

Comments
 (0)