Skip to content

Commit

Permalink
meca: Fix the bug when passing a dict of scalar values to the spec pa…
Browse files Browse the repository at this point in the history
…rameter (#2174)

Co-authored-by: Wei Ji <[email protected]>
  • Loading branch information
seisman and weiji14 authored Nov 13, 2022
1 parent e4e4c43 commit ecdb66c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pygmt/src/meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ def meca(

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

# expected columns are:
Expand Down
26 changes: 26 additions & 0 deletions pygmt/tests/test_meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,29 @@ def test_meca_dict_offset_eventname():
event_name="Event20220311",
)
return fig


@pytest.mark.mpl_image_compare(filename="test_meca_dict_eventname.png")
def test_meca_spec_dict_all_scalars():
"""
Test supplying a dict with scalar values for all focal parameters.
This is a regression test for
https://github.com/GenericMappingTools/pygmt/pull/2174
"""
fig = Figure()
fig.basemap(region=[-125, -122, 47, 49], projection="M6c", frame=True)
fig.meca(
spec=dict(
strike=330,
dip=30,
rake=90,
magnitude=3,
longitude=-124,
latitude=48,
depth=12.0,
event_name="Event20220311",
),
scale="1c",
)
return fig

0 comments on commit ecdb66c

Please sign in to comment.