From 075bfa56ecbf6fd219aa82f327e863a74b764524 Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Thu, 19 Jun 2025 12:35:23 +0800 Subject: [PATCH 1/2] Fix the bug that passing a sequence that contains True to a parameter --- pygmt/helpers/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pygmt/helpers/utils.py b/pygmt/helpers/utils.py index 387d61e03b3..dac58eb160c 100644 --- a/pygmt/helpers/utils.py +++ b/pygmt/helpers/utils.py @@ -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'")) @@ -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}") From 919782bf6711080d44a5e835ed2bd7e4e5f2c4ea Mon Sep 17 00:00:00 2001 From: Dongdong Tian Date: Mon, 23 Jun 2025 17:12:56 +0800 Subject: [PATCH 2/2] Add one test --- .../test_basemap_frame_sequence_true.png.dvc | 5 +++++ pygmt/tests/test_basemap.py | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 pygmt/tests/baseline/test_basemap_frame_sequence_true.png.dvc diff --git a/pygmt/tests/baseline/test_basemap_frame_sequence_true.png.dvc b/pygmt/tests/baseline/test_basemap_frame_sequence_true.png.dvc new file mode 100644 index 00000000000..ed3a6aaf199 --- /dev/null +++ b/pygmt/tests/baseline/test_basemap_frame_sequence_true.png.dvc @@ -0,0 +1,5 @@ +outs: +- md5: b04af7fe4c42e405adb600cc3d6d3272 + size: 11679 + hash: md5 + path: test_basemap_frame_sequence_true.png diff --git a/pygmt/tests/test_basemap.py b/pygmt/tests/test_basemap.py index c75459c99ca..a88f015b0e9 100644 --- a/pygmt/tests/test_basemap.py +++ b/pygmt/tests/test_basemap.py @@ -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"]) + return fig