Skip to content

pygmt.grd2cpt & pygmt.makecpt: Simplify the logic for dealing with CPT output - #3334

Merged
seisman merged 3 commits into
mainfrom
cpt-wrapper
Jul 19, 2024
Merged

pygmt.grd2cpt & pygmt.makecpt: Simplify the logic for dealing with CPT output#3334
seisman merged 3 commits into
mainfrom
cpt-wrapper

Conversation

@seisman

@seismanseisman commented Jul 17, 2024

Copy link
Copy Markdown
Member

Simplify:

 if kwargs.get("H") is None: # if no output is set
arg_str = build_arg_list(kwargs)
else: # if output is set
outfile, kwargs["H"] = kwargs.pop("H"), True
if not outfile or not isinstance(outfile, str):
raise GMTInvalidInput("'output' should be a proper file name.")
arg_str = build_arg_list(kwargs, outfile=outfile)

to

 if (output := kwargs.pop("H", None)) is not None:
if not isinstance(output, str) or output == "":
raise GMTInvalidInput("'output' should be a proper file name.")
kwargs["H"] = True
arg_str = build_arg_list(kwargs, outfile=output)

It works because outfile in build_arg_list can be None.

@seismanseisman added the maintenance Boring but important stuff for the core devs label Jul 17, 2024
@seismanseisman added this to the 0.13.0 milestone Jul 17, 2024
@seismanseisman added needs review This PR has higher priority and needs review. run/benchmark Trigger the benchmark workflow in PRs labels Jul 17, 2024
Comment threadpygmt/src/grd2cpt.py Outdated
Comment threadpygmt/src/makecpt.py Outdated

@weiji14weiji14 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Needed to read that if-statement a few times to get the logic, but looks ok.

@seisman

Copy link
Copy Markdown
MemberAuthor

The if-statement can be further simplified after PR #3238

@seisman
seisman merged commit 6c436a3 into mainJul 19, 2024
@seisman
seisman deleted the cpt-wrapper branch July 19, 2024 02:30
@seismanseisman removed needs review This PR has higher priority and needs review. run/benchmark Trigger the benchmark workflow in PRs labels Jul 19, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenanceBoring but important stuff for the core devs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@seisman@weiji14