Skip to content

Commit 7fd8253

Browse files
seismanweiji14
andauthored
clib: Change the parameter order and set output_type to pandas in virtualfile_to_dataset (#3124)
Co-authored-by: Wei Ji <[email protected]>
1 parent ce1ae82 commit 7fd8253

10 files changed

+17
-17
lines changed

pygmt/clib/session.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1740,8 +1740,8 @@ def read_virtualfile(
17401740

17411741
def virtualfile_to_dataset(
17421742
self,
1743-
output_type: Literal["pandas", "numpy", "file"],
17441743
vfname: str,
1744+
output_type: Literal["pandas", "numpy", "file"] = "pandas",
17451745
column_names: list[str] | None = None,
17461746
) -> pd.DataFrame | np.ndarray | None:
17471747
"""
@@ -1751,15 +1751,15 @@ def virtualfile_to_dataset(
17511751
17521752
Parameters
17531753
----------
1754+
vfname
1755+
The virtual file name that stores the result data. Required for ``"pandas"``
1756+
and ``"numpy"`` output type.
17541757
output_type
17551758
Desired output type of the result data.
17561759
17571760
- ``"pandas"`` will return a :class:`pandas.DataFrame` object.
17581761
- ``"numpy"`` will return a :class:`numpy.ndarray` object.
17591762
- ``"file"`` means the result was saved to a file and will return ``None``.
1760-
vfname
1761-
The virtual file name that stores the result data. Required for ``"pandas"``
1762-
and ``"numpy"`` output type.
17631763
column_names
17641764
The column names for the :class:`pandas.DataFrame` output.
17651765
@@ -1795,7 +1795,7 @@ def virtualfile_to_dataset(
17951795
... ) as vouttbl:
17961796
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
17971797
... result = lib.virtualfile_to_dataset(
1798-
... output_type="file", vfname=vouttbl
1798+
... vfname=vouttbl, output_type="file"
17991799
... )
18001800
... assert result is None
18011801
... assert Path(outtmp.name).stat().st_size > 0
@@ -1805,7 +1805,7 @@ def virtualfile_to_dataset(
18051805
... with lib.virtualfile_out(kind="dataset") as vouttbl:
18061806
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
18071807
... outnp = lib.virtualfile_to_dataset(
1808-
... output_type="numpy", vfname=vouttbl
1808+
... vfname=vouttbl, output_type="numpy"
18091809
... )
18101810
... assert isinstance(outnp, np.ndarray)
18111811
...
@@ -1814,7 +1814,7 @@ def virtualfile_to_dataset(
18141814
... with lib.virtualfile_out(kind="dataset") as vouttbl:
18151815
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
18161816
... outpd = lib.virtualfile_to_dataset(
1817-
... output_type="pandas", vfname=vouttbl
1817+
... vfname=vouttbl, output_type="pandas"
18181818
... )
18191819
... assert isinstance(outpd, pd.DataFrame)
18201820
...
@@ -1823,8 +1823,8 @@ def virtualfile_to_dataset(
18231823
... with lib.virtualfile_out(kind="dataset") as vouttbl:
18241824
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
18251825
... outpd2 = lib.virtualfile_to_dataset(
1826-
... output_type="pandas",
18271826
... vfname=vouttbl,
1827+
... output_type="pandas",
18281828
... column_names=["col1", "col2", "col3", "coltext"],
18291829
... )
18301830
... assert isinstance(outpd2, pd.DataFrame)

pygmt/src/blockm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def _blockm(
6464
args=build_arg_string(kwargs, infile=vintbl, outfile=vouttbl),
6565
)
6666
return lib.virtualfile_to_dataset(
67-
output_type=output_type, vfname=vouttbl, column_names=column_names
67+
vfname=vouttbl, output_type=output_type, column_names=column_names
6868
)
6969

7070

pygmt/src/filter1d.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,4 @@ def filter1d(
123123
module="filter1d",
124124
args=build_arg_string(kwargs, infile=vintbl, outfile=vouttbl),
125125
)
126-
return lib.virtualfile_to_dataset(output_type=output_type, vfname=vouttbl)
126+
return lib.virtualfile_to_dataset(vfname=vouttbl, output_type=output_type)

pygmt/src/grd2xyz.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,5 @@ def grd2xyz(
168168
args=build_arg_string(kwargs, infile=vingrd, outfile=vouttbl),
169169
)
170170
return lib.virtualfile_to_dataset(
171-
output_type=output_type, vfname=vouttbl, column_names=column_names
171+
vfname=vouttbl, output_type=output_type, column_names=column_names
172172
)

pygmt/src/grdhisteq.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ def compute_bins(
239239
)
240240

241241
result = lib.virtualfile_to_dataset(
242-
output_type=output_type,
243242
vfname=vouttbl,
243+
output_type=output_type,
244244
column_names=["start", "stop", "bin_id"],
245245
)
246246
if output_type == "pandas":

pygmt/src/grdtrack.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def grdtrack(
318318
args=build_arg_string(kwargs, infile=vintbl, outfile=vouttbl),
319319
)
320320
return lib.virtualfile_to_dataset(
321-
output_type=output_type,
322321
vfname=vouttbl,
322+
output_type=output_type,
323323
column_names=column_names,
324324
)

pygmt/src/grdvolume.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,4 @@ def grdvolume(
111111
module="grdvolume",
112112
args=build_arg_string(kwargs, infile=vingrd, outfile=vouttbl),
113113
)
114-
return lib.virtualfile_to_dataset(output_type=output_type, vfname=vouttbl)
114+
return lib.virtualfile_to_dataset(vfname=vouttbl, output_type=output_type)

pygmt/src/project.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def project(
256256
args=build_arg_string(kwargs, infile=vintbl, outfile=vouttbl),
257257
)
258258
return lib.virtualfile_to_dataset(
259-
output_type=output_type,
260259
vfname=vouttbl,
260+
output_type=output_type,
261261
column_names=column_names,
262262
)

pygmt/src/select.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def select(
221221
args=build_arg_string(kwargs, infile=vintbl, outfile=vouttbl),
222222
)
223223
return lib.virtualfile_to_dataset(
224-
output_type=output_type,
225224
vfname=vouttbl,
225+
output_type=output_type,
226226
column_names=column_names,
227227
)

pygmt/src/triangulate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,4 +249,4 @@ def delaunay_triples(
249249
module="triangulate",
250250
args=build_arg_string(kwargs, infile=vintbl, outfile=vouttbl),
251251
)
252-
return lib.virtualfile_to_dataset(output_type=output_type, vfname=vouttbl)
252+
return lib.virtualfile_to_dataset(vfname=vouttbl, output_type=output_type)

0 commit comments

Comments
 (0)