12
12
from packaging .version import Version
13
13
14
14
15
- def unique_name ():
15
+ def unique_name () -> str :
16
16
"""
17
17
Generate a unique name.
18
18
19
- Useful for generating unique names for figures (otherwise GMT will plot
20
- everything on the same figure instead of creating a new one) .
19
+ Useful for generating unique names for figures. Otherwise GMT will plot everything
20
+ on the same figure instead of creating a new one.
21
21
22
22
Returns
23
23
-------
24
- name : str
25
- A unique name generated by :func:`uuid.uuid4`
24
+ name
25
+ A unique name generated by :func:`uuid.uuid4`.
26
26
"""
27
27
return uuid .uuid4 ().hex
28
28
@@ -31,15 +31,14 @@ class GMTTempFile:
31
31
"""
32
32
Context manager for creating closed temporary files.
33
33
34
- This class does not return a file-like object. So, you can't do
35
- ``for line in GMTTempFile()``, for example, or pass it to things that
36
- need file objects.
34
+ This class does not return a file-like object. So, you can't iterate over the object
35
+ like ``for line in GMTTempFile()``, or pass it to things that need a file object.
37
36
38
37
Parameters
39
38
----------
40
- prefix : str
39
+ prefix
41
40
The temporary file name begins with the prefix.
42
- suffix : str
41
+ suffix
43
42
The temporary file name ends with the suffix.
44
43
45
44
Examples
@@ -60,7 +59,10 @@ class GMTTempFile:
60
59
[0. 0. 0.] [1. 1. 1.] [2. 2. 2.]
61
60
"""
62
61
63
- def __init__ (self , prefix = "pygmt-" , suffix = ".txt" ):
62
+ def __init__ (self , prefix : str = "pygmt-" , suffix : str = ".txt" ):
63
+ """
64
+ Initialize the object.
65
+ """
64
66
with NamedTemporaryFile (prefix = prefix , suffix = suffix , delete = False ) as tmpfile :
65
67
self .name = tmpfile .name
66
68
@@ -76,33 +78,33 @@ def __exit__(self, *args):
76
78
"""
77
79
Path (self .name ).unlink (missing_ok = True )
78
80
79
- def read (self , keep_tabs = False ):
81
+ def read (self , keep_tabs : bool = False ) -> str :
80
82
"""
81
83
Read the entire contents of the file as a Unicode string.
82
84
83
85
Parameters
84
86
----------
85
- keep_tabs : bool
87
+ keep_tabs
86
88
If False, replace the tabs that GMT uses with spaces.
87
89
88
90
Returns
89
91
-------
90
- content : str
92
+ content
91
93
Content of the temporary file as a Unicode string.
92
94
"""
93
95
content = Path (self .name ).read_text (encoding = "utf8" )
94
96
if not keep_tabs :
95
97
content = content .replace ("\t " , " " )
96
98
return content
97
99
98
- def loadtxt (self , ** kwargs ):
100
+ def loadtxt (self , ** kwargs ) -> np . ndarray :
99
101
"""
100
102
Load data from the temporary file using numpy.loadtxt.
101
103
102
104
Parameters
103
105
----------
104
- kwargs : dict
105
- Any keyword arguments that can be passed to numpy .loadtxt.
106
+ kwargs
107
+ Any keyword arguments that can be passed to :func:`np .loadtxt` .
106
108
107
109
Returns
108
110
-------
0 commit comments