diff --git a/pygmt/src/nearneighbor.py b/pygmt/src/nearneighbor.py index 641b5861703..a1cb2d7bb3b 100644 --- a/pygmt/src/nearneighbor.py +++ b/pygmt/src/nearneighbor.py @@ -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) ) diff --git a/pygmt/src/sphdistance.py b/pygmt/src/sphdistance.py index c8ac83035b5..3d083b0a6a4 100644 --- a/pygmt/src/sphdistance.py +++ b/pygmt/src/sphdistance.py @@ -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 diff --git a/pygmt/src/sphinterpolate.py b/pygmt/src/sphinterpolate.py index bf585440a02..bcdbdd1bff0 100644 --- a/pygmt/src/sphinterpolate.py +++ b/pygmt/src/sphinterpolate.py @@ -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) ) diff --git a/pygmt/src/surface.py b/pygmt/src/surface.py index 25273e1f2b7..f871081f3ef 100644 --- a/pygmt/src/surface.py +++ b/pygmt/src/surface.py @@ -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) ) diff --git a/pygmt/src/text.py b/pygmt/src/text.py index d12ffcd9696..66413758ebc 100644 --- a/pygmt/src/text.py +++ b/pygmt/src/text.py @@ -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 diff --git a/pygmt/src/xyz2grd.py b/pygmt/src/xyz2grd.py index 4e0d9b7a220..cf31e3a8be7 100644 --- a/pygmt/src/xyz2grd.py +++ b/pygmt/src/xyz2grd.py @@ -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