Skip to content

Fix the bug when passing a sequence that contains True to a parameter #3982

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

Merged
merged 2 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ def build_arg_list( # noqa: PLR0912
['-A1/2/3/4', '-BWSen', '-Bxaf', '-Byaf', '-C1p', '-C2p']
>>> build_arg_list(dict(B=["af", "WSne+tBlank Space"]))
['-BWSne+tBlank Space', '-Baf']
>>> build_arg_list(dict(B=[True, "+tTitle"]))
['-B', '-B+tTitle']
>>> build_arg_list(dict(F='+t"Empty Spaces"'))
['-F+t"Empty Spaces"']
>>> build_arg_list(dict(l="'Void Space'"))
Expand Down Expand Up @@ -565,7 +567,10 @@ def build_arg_list( # noqa: PLR0912
elif value is True:
gmt_args.append(f"-{key}")
elif is_nonstr_iter(value):
gmt_args.extend(f"-{key}{_value}" for _value in value)
gmt_args.extend(
f"-{key}{_value}" if _value is not True else f"-{key}"
for _value in value
)
else:
gmt_args.append(f"-{key}{value}")

Expand Down
5 changes: 5 additions & 0 deletions pygmt/tests/baseline/test_basemap_frame_sequence_true.png.dvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
outs:
- md5: b04af7fe4c42e405adb600cc3d6d3272
size: 11679
hash: md5
path: test_basemap_frame_sequence_true.png
12 changes: 12 additions & 0 deletions pygmt/tests/test_basemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,15 @@ def test_basemap_subplot():
with fig.set_panel(panel=1):
fig.basemap(region=[0, 10, 0, 10], projection="X?")
return fig


@pytest.mark.mpl_image_compare
def test_basemap_frame_sequence_true():
"""
Test that passing a sequence with True works.

Test for https://github.com/GenericMappingTools/pygmt/issues/3981.
"""
fig = Figure()
fig.basemap(region=[0, 10, 0, 10], projection="X10c", frame=[True, "WSen"])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This translates to gmt basemap -R0/10/0/10 -JX10c -B -BWSen -pdf temp in GMT, which seems a little weird, but I see the output is different from gmt basemap -R0/10/0/10 -JX10c -BWSen -pdf temp, so ok I guess.

return fig
Loading