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

Allow passing None explicitly to pygmt functions Part 2 #1862

Merged
merged 10 commits into from
Apr 5, 2022
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
5 changes: 2 additions & 3 deletions pygmt/src/nearneighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ def nearneighbor(data=None, x=None, y=None, z=None, **kwargs):
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
)
with table_context as infile:
if "G" not in kwargs: # if outgrid is unset, output to tmpfile
kwargs.update({"G": tmpfile.name})
outgrid = kwargs["G"]
if (outgrid := kwargs.get("G")) is None:
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
lib.call_module(
module="nearneighbor", args=build_arg_string(kwargs, infile=infile)
)
Expand Down
5 changes: 2 additions & 3 deletions pygmt/src/sphdistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ def sphdistance(data=None, x=None, y=None, **kwargs):
check_kind="vector", data=data, x=x, y=y
)
with file_context as infile:
if "G" not in kwargs: # if outgrid is unset, output to tempfile
kwargs.update({"G": tmpfile.name})
outgrid = kwargs["G"]
if (outgrid := kwargs.get("G")) is None:
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
lib.call_module("sphdistance", build_arg_string(kwargs, infile=infile))

return load_dataarray(outgrid) if outgrid == tmpfile.name else None
5 changes: 2 additions & 3 deletions pygmt/src/sphinterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ def sphinterpolate(data, **kwargs):
with Session() as lib:
file_context = lib.virtualfile_from_data(check_kind="vector", data=data)
with file_context as infile:
if "G" not in kwargs: # if outgrid is unset, output to tempfile
kwargs.update({"G": tmpfile.name})
outgrid = kwargs["G"]
if (outgrid := kwargs.get("G")) is None:
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
lib.call_module(
"sphinterpolate", build_arg_string(kwargs, infile=infile)
)
Expand Down
5 changes: 2 additions & 3 deletions pygmt/src/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ def surface(data=None, x=None, y=None, z=None, **kwargs):
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
)
with file_context as infile:
if "G" not in kwargs: # if outgrid is unset, output to tmpfile
kwargs.update({"G": tmpfile.name})
outgrid = kwargs["G"]
if (outgrid := kwargs.get("G")) is None:
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
lib.call_module(
module="surface", args=build_arg_string(kwargs, infile=infile)
)
Expand Down
2 changes: 1 addition & 1 deletion pygmt/src/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def text_(
raise GMTInvalidInput("Must provide text with x/y pairs or position")

# Build the -F option in gmt text.
if "F" not in kwargs and (
if kwargs.get("F") is None and (
(
position is not None
or angle is not None
Expand Down
5 changes: 2 additions & 3 deletions pygmt/src/xyz2grd.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
)
with file_context as infile:
if "G" not in kwargs: # if outgrid is unset, output to tempfile
kwargs.update({"G": tmpfile.name})
outgrid = kwargs["G"]
if (outgrid := kwargs.get("G")) is None:
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
lib.call_module("xyz2grd", build_arg_string(kwargs, infile=infile))

return load_dataarray(outgrid) if outgrid == tmpfile.name else None