Skip to content

Commit 3c16875

Browse files
committed
More fixes
1 parent b1363c0 commit 3c16875

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

pygmt/clib/session.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,12 +1641,13 @@ def virtualfile_out(
16411641
16421642
Examples
16431643
--------
1644+
>>> from pathlib import Path
16441645
>>> from pygmt.clib import Session
16451646
>>> from pygmt.datatypes import _GMT_DATASET
16461647
>>> from pygmt.helpers import GMTTempFile
16471648
>>>
16481649
>>> with GMTTempFile(suffix=".txt") as tmpfile:
1649-
... with open(tmpfile.name, mode="w") as fp:
1650+
... with Path(tmpfile.name).open(mode="w") as fp:
16501651
... print("1.0 2.0 3.0 TEXT", file=fp)
16511652
...
16521653
... # Create a virtual file for storing the output table.
@@ -1661,8 +1662,7 @@ def virtualfile_out(
16611662
... with lib.virtualfile_out(fname=tmpfile.name) as vouttbl:
16621663
... assert vouttbl == tmpfile.name
16631664
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
1664-
... with open(vouttbl, mode="r") as fp:
1665-
... line = fp.readline()
1665+
... line = Path(vouttbl).read_text()
16661666
... assert line == "1\t2\t3\tTEXT\n"
16671667
"""
16681668
if fname is not None: # Yield the actual file name.
@@ -1692,13 +1692,14 @@ def read_virtualfile(
16921692
16931693
Examples
16941694
--------
1695+
>>> from pathlib import Path
16951696
>>> from pygmt.clib import Session
16961697
>>> from pygmt.helpers import GMTTempFile
16971698
>>>
16981699
>>> # Read dataset from a virtual file
16991700
>>> with Session() as lib:
17001701
... with GMTTempFile(suffix=".txt") as tmpfile:
1701-
... with open(tmpfile.name, mode="w") as fp:
1702+
... with Path(tmpfile.name).open(mode="w") as fp:
17021703
... print("1.0 2.0 3.0 TEXT", file=fp)
17031704
... with lib.virtualfile_out(kind="dataset") as vouttbl:
17041705
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
@@ -1779,7 +1780,7 @@ def virtualfile_to_dataset(
17791780
>>>
17801781
>>> with GMTTempFile(suffix=".txt") as tmpfile:
17811782
... # prepare the sample data file
1782-
... with open(tmpfile.name, mode="w") as fp:
1783+
... with Path(tmpfile.name).open(mode="w") as fp:
17831784
... print(">", file=fp)
17841785
... print("1.0 2.0 3.0 TEXT1 TEXT23", file=fp)
17851786
... print("4.0 5.0 6.0 TEXT4 TEXT567", file=fp)

pygmt/datatypes/dataset.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ class _GMT_DATASET(ctp.Structure): # noqa: N801
1818
1919
Examples
2020
--------
21+
>>> from pathlib import Path
2122
>>> from pygmt.helpers import GMTTempFile
2223
>>> from pygmt.clib import Session
2324
>>>
2425
>>> with GMTTempFile(suffix=".txt") as tmpfile:
2526
... # Prepare the sample data file
26-
... with open(tmpfile.name, mode="w") as fp:
27+
... with Path(tmpfile.name).open(mode="w") as fp:
2728
... print(">", file=fp)
2829
... print("1.0 2.0 3.0 TEXT1 TEXT23", file=fp)
2930
... print("4.0 5.0 6.0 TEXT4 TEXT567", file=fp)
@@ -157,12 +158,13 @@ def to_dataframe(self) -> pd.DataFrame:
157158
158159
Examples
159160
--------
161+
>>> from pathlib import Path
160162
>>> from pygmt.helpers import GMTTempFile
161163
>>> from pygmt.clib import Session
162164
>>>
163165
>>> with GMTTempFile(suffix=".txt") as tmpfile:
164166
... # prepare the sample data file
165-
... with open(tmpfile.name, mode="w") as fp:
167+
... with Path(tmpfile.name).open(mode="w") as fp:
166168
... print(">", file=fp)
167169
... print("1.0 2.0 3.0 TEXT1 TEXT23", file=fp)
168170
... print("4.0 5.0 6.0 TEXT4 TEXT567", file=fp)

0 commit comments

Comments
 (0)