33"""
44
55import warnings
6- from collections .abc import Sequence
76from typing import Literal
87
98from pygmt .exceptions import GMTInvalidInput
109
1110
1211def validate_output_table_type (
13- output_type : Literal ["pandas" , "numpy" , "file" ],
14- valid_types : Sequence [str ] = ("pandas" , "numpy" , "file" ),
15- outfile : str | None = None ,
12+ output_type : Literal ["pandas" , "numpy" , "file" ], outfile : str | None = None
1613) -> Literal ["pandas" , "numpy" , "file" ]:
1714 """
1815 Check if the ``output_type`` and ``outfile`` parameters are valid.
1916
2017 Parameters
2118 ----------
2219 output_type
23- Desired output type of tabular data. Default valid values are ``"pandas"``,
24- ``"numpy"`` and ``"file"``, but can be configured by parameter ``valid_types``.
25- valid_types
26- Tuple of valid desired output types.
20+ Desired output type of tabular data. Valid values are ``"pandas"``,
21+ ``"numpy"`` and ``"file"``.
2722 outfile
2823 File name for saving the result data. Required if ``output_type`` is ``"file"``.
2924 If specified, ``output_type`` will be forced to be ``"file"``.
@@ -41,32 +36,23 @@ def validate_output_table_type(
4136 'numpy'
4237 >>> validate_output_table_type(output_type="file", outfile="output-fname.txt")
4338 'file'
44- >>> validate_output_table_type(output_type="pandas", valid_types=("pandas", "file"))
45- 'pandas'
4639 >>> validate_output_table_type(output_type="invalid-type")
4740 Traceback (most recent call last):
4841 ...
49- pygmt.exceptions.GMTInvalidInput: Must specify 'output_type' as 'pandas ', ...
42+ pygmt.exceptions.GMTInvalidInput: Must specify 'output_type' either as 'file ', ...
5043 >>> validate_output_table_type("file", outfile=None)
5144 Traceback (most recent call last):
5245 ...
5346 pygmt.exceptions.GMTInvalidInput: Must specify 'outfile' for output_type='file'.
54- >>> validate_output_table_type(output_type="numpy", valid_types=("pandas", "file"))
55- Traceback (most recent call last):
56- ...
57- pygmt.exceptions.GMTInvalidInput: Must specify 'output_type' as 'pandas', or 'file'.
5847 >>> with warnings.catch_warnings(record=True) as w:
5948 ... validate_output_table_type("pandas", outfile="not-none.txt")
6049 ... assert len(w) == 1
6150 'file'
6251 """
63- if output_type not in valid_types :
64- msg = (
65- "Must specify 'output_type' as "
66- + ", " .join (f"'{ v } '" for v in valid_types [:- 1 ])
67- + f", or '{ valid_types [- 1 ]} '."
52+ if output_type not in ["file" , "numpy" , "pandas" ]:
53+ raise GMTInvalidInput (
54+ "Must specify 'output_type' either as 'file', 'numpy', or 'pandas'."
6855 )
69- raise GMTInvalidInput (msg )
7056 if output_type == "file" and outfile is None :
7157 raise GMTInvalidInput ("Must specify 'outfile' for output_type='file'." )
7258 if output_type != "file" and outfile is not None :
0 commit comments