Skip to content

Commit 6ee851b

Browse files
author
Meghan Jones
authored
Allow passing None explicitly to pygmt functions Part 2 (#1862)
1 parent 722dae9 commit 6ee851b

File tree

6 files changed

+11
-16
lines changed

6 files changed

+11
-16
lines changed

pygmt/src/nearneighbor.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ def nearneighbor(data=None, x=None, y=None, z=None, **kwargs):
139139
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
140140
)
141141
with table_context as infile:
142-
if "G" not in kwargs: # if outgrid is unset, output to tmpfile
143-
kwargs.update({"G": tmpfile.name})
144-
outgrid = kwargs["G"]
142+
if (outgrid := kwargs.get("G")) is None:
143+
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
145144
lib.call_module(
146145
module="nearneighbor", args=build_arg_string(kwargs, infile=infile)
147146
)

pygmt/src/sphdistance.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ def sphdistance(data=None, x=None, y=None, **kwargs):
108108
check_kind="vector", data=data, x=x, y=y
109109
)
110110
with file_context as infile:
111-
if "G" not in kwargs: # if outgrid is unset, output to tempfile
112-
kwargs.update({"G": tmpfile.name})
113-
outgrid = kwargs["G"]
111+
if (outgrid := kwargs.get("G")) is None:
112+
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
114113
lib.call_module("sphdistance", build_arg_string(kwargs, infile=infile))
115114

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

pygmt/src/sphinterpolate.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ def sphinterpolate(data, **kwargs):
6060
with Session() as lib:
6161
file_context = lib.virtualfile_from_data(check_kind="vector", data=data)
6262
with file_context as infile:
63-
if "G" not in kwargs: # if outgrid is unset, output to tempfile
64-
kwargs.update({"G": tmpfile.name})
65-
outgrid = kwargs["G"]
63+
if (outgrid := kwargs.get("G")) is None:
64+
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
6665
lib.call_module(
6766
"sphinterpolate", build_arg_string(kwargs, infile=infile)
6867
)

pygmt/src/surface.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ def surface(data=None, x=None, y=None, z=None, **kwargs):
9898
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
9999
)
100100
with file_context as infile:
101-
if "G" not in kwargs: # if outgrid is unset, output to tmpfile
102-
kwargs.update({"G": tmpfile.name})
103-
outgrid = kwargs["G"]
101+
if (outgrid := kwargs.get("G")) is None:
102+
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
104103
lib.call_module(
105104
module="surface", args=build_arg_string(kwargs, infile=infile)
106105
)

pygmt/src/text.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def text_(
184184
raise GMTInvalidInput("Must provide text with x/y pairs or position")
185185

186186
# Build the -F option in gmt text.
187-
if "F" not in kwargs and (
187+
if kwargs.get("F") is None and (
188188
(
189189
position is not None
190190
or angle is not None

pygmt/src/xyz2grd.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,8 @@ def xyz2grd(data=None, x=None, y=None, z=None, **kwargs):
157157
check_kind="vector", data=data, x=x, y=y, z=z, required_z=True
158158
)
159159
with file_context as infile:
160-
if "G" not in kwargs: # if outgrid is unset, output to tempfile
161-
kwargs.update({"G": tmpfile.name})
162-
outgrid = kwargs["G"]
160+
if (outgrid := kwargs.get("G")) is None:
161+
kwargs["G"] = outgrid = tmpfile.name # output to tmpfile
163162
lib.call_module("xyz2grd", build_arg_string(kwargs, infile=infile))
164163

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

0 commit comments

Comments
 (0)