-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the validate_output_type function to check the output_type parameter
- Loading branch information
Showing
7 changed files
with
59 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ | |
launch_external_viewer, | ||
non_ascii_to_octal, | ||
) | ||
from pygmt.helpers.validators import validate_output_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
""" | ||
Functions to check if given arguments are valid. | ||
""" | ||
import warnings | ||
|
||
from pygmt.exceptions import GMTInvalidInput | ||
|
||
|
||
def validate_output_type(output_type, outfile=None): | ||
""" | ||
Check if the 'output_type' and 'outfile' parameters are valid. | ||
Parameters | ||
---------- | ||
output_type : str | ||
The type for a table output. Valid values are "file", "numpy", and | ||
"pandas". | ||
outfile : str | ||
The file name for the output table file. Required if | ||
``output_type="file"``. | ||
Returns | ||
------- | ||
str | ||
The original or corrected output type. | ||
""" | ||
if output_type not in ["file", "numpy", "pandas"]: | ||
raise GMTInvalidInput( | ||
"Must specify 'output_type' either as 'file', 'numpy', or 'pandas'." | ||
) | ||
if output_type == "file" and outfile is None: | ||
raise GMTInvalidInput("Must specify 'outfile' for output_type='file'.") | ||
if output_type != "file" and outfile is not None: | ||
msg = ( | ||
f"Changing 'output_type' from '{output_type}' to 'file' " | ||
"since 'outfile' parameter is set. Please use output_type='file' " | ||
"to silence this warning." | ||
) | ||
warnings.warn(message=msg, category=RuntimeWarning, stacklevel=2) | ||
output_type = "file" | ||
return output_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters