Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
seisman committed Mar 20, 2024
1 parent b1363c0 commit 3c16875
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 6 additions & 5 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1641,12 +1641,13 @@ def virtualfile_out(
Examples
--------
>>> from pathlib import Path
>>> from pygmt.clib import Session
>>> from pygmt.datatypes import _GMT_DATASET
>>> from pygmt.helpers import GMTTempFile
>>>
>>> with GMTTempFile(suffix=".txt") as tmpfile:
... with open(tmpfile.name, mode="w") as fp:
... with Path(tmpfile.name).open(mode="w") as fp:
... print("1.0 2.0 3.0 TEXT", file=fp)
...
... # Create a virtual file for storing the output table.
Expand All @@ -1661,8 +1662,7 @@ def virtualfile_out(
... with lib.virtualfile_out(fname=tmpfile.name) as vouttbl:
... assert vouttbl == tmpfile.name
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
... with open(vouttbl, mode="r") as fp:
... line = fp.readline()
... line = Path(vouttbl).read_text()
... assert line == "1\t2\t3\tTEXT\n"
"""
if fname is not None: # Yield the actual file name.
Expand Down Expand Up @@ -1692,13 +1692,14 @@ def read_virtualfile(
Examples
--------
>>> from pathlib import Path
>>> from pygmt.clib import Session
>>> from pygmt.helpers import GMTTempFile
>>>
>>> # Read dataset from a virtual file
>>> with Session() as lib:
... with GMTTempFile(suffix=".txt") as tmpfile:
... with open(tmpfile.name, mode="w") as fp:
... with Path(tmpfile.name).open(mode="w") as fp:
... print("1.0 2.0 3.0 TEXT", file=fp)
... with lib.virtualfile_out(kind="dataset") as vouttbl:
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
Expand Down Expand Up @@ -1779,7 +1780,7 @@ def virtualfile_to_dataset(
>>>
>>> with GMTTempFile(suffix=".txt") as tmpfile:
... # prepare the sample data file
... with open(tmpfile.name, mode="w") as fp:
... with Path(tmpfile.name).open(mode="w") as fp:
... print(">", file=fp)
... print("1.0 2.0 3.0 TEXT1 TEXT23", file=fp)
... print("4.0 5.0 6.0 TEXT4 TEXT567", file=fp)
Expand Down
6 changes: 4 additions & 2 deletions pygmt/datatypes/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ class _GMT_DATASET(ctp.Structure): # noqa: N801
Examples
--------
>>> from pathlib import Path
>>> from pygmt.helpers import GMTTempFile
>>> from pygmt.clib import Session
>>>
>>> with GMTTempFile(suffix=".txt") as tmpfile:
... # Prepare the sample data file
... with open(tmpfile.name, mode="w") as fp:
... with Path(tmpfile.name).open(mode="w") as fp:
... print(">", file=fp)
... print("1.0 2.0 3.0 TEXT1 TEXT23", file=fp)
... print("4.0 5.0 6.0 TEXT4 TEXT567", file=fp)
Expand Down Expand Up @@ -157,12 +158,13 @@ def to_dataframe(self) -> pd.DataFrame:
Examples
--------
>>> from pathlib import Path
>>> from pygmt.helpers import GMTTempFile
>>> from pygmt.clib import Session
>>>
>>> with GMTTempFile(suffix=".txt") as tmpfile:
... # prepare the sample data file
... with open(tmpfile.name, mode="w") as fp:
... with Path(tmpfile.name).open(mode="w") as fp:
... print(">", file=fp)
... print("1.0 2.0 3.0 TEXT1 TEXT23", file=fp)
... print("4.0 5.0 6.0 TEXT4 TEXT567", file=fp)
Expand Down

0 comments on commit 3c16875

Please sign in to comment.