Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure.meca: Fix the bug when passing a dict of scalar values to the spec parameter #2174

Merged
merged 8 commits into from
Nov 13, 2022
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
23 changes: 23 additions & 0 deletions pygmt/tests/test_meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,26 @@ 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.
seisman marked this conversation as resolved.
Show resolved Hide resolved
"""
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