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
  • Loading branch information
seisman committed Oct 28, 2022
1 parent bd05e70 commit efde646
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pygmt/src/meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ def meca(

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

# expected columns are:
Expand Down
19 changes: 19 additions & 0 deletions pygmt/tests/test_meca.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ def test_meca_spec_dictionary():
return fig


@pytest.mark.mpl_image_compare(filename="test_meca_spec_dictionary.png")
def test_meca_spec_dict_all_scalars():
"""
Test supplying a dict with scalar values for all focal parameters.
"""
fig = Figure()
# Right lateral strike slip focal mechanism
fig.meca(
spec=dict(
strike=0, dip=90, rake=0, magnitude=5, longitude=0, latitude=5, depth=0
),
scale="2.5c",
region=[-1, 1, 4, 6],
projection="M14c",
frame=2,
)
return fig


@pytest.mark.mpl_image_compare
def test_meca_spec_dict_list():
"""
Expand Down

0 comments on commit efde646

Please sign in to comment.