polyfemos.parser.typeoperator¶
Functions representing types used internally in polyfemos
- copyright
2019, University of Oulu, Sodankyla Geophysical Observatory
- license
GNU Lesser General Public License v3.0 or later (https://spdx.org/licenses/LGPL-3.0-or-later.html)
Public Functions
-
polyfemos.parser.typeoperator.NaN2None(func_)[source]¶ A decorator to be composed with a one-argument function, If the argument of the decorated function (
func_) is NaN returnNone, else call functionfunc_- Parameters
func_ (func) – A one-argument function
- Return type
func
- Returns
wrapper
-
polyfemos.parser.typeoperator.check_type(func_, invalid_value=None)[source]¶ A decorator to be composed with function where
ValueErrororTypeErrormight occur. If the error occurs whilefunc_is called, the return value of thefunc_isNone.- Parameters
func_ (func) –
invalid_value (anything, optional) – If the type conversion is not possible, given invalid value is returned, defaults to
None.
- Return type
func
- Returns
wrapper
-
polyfemos.parser.typeoperator.dict_(inputstr)[source]¶ Calls
literal_eval()to for a dictionary frominputstrand returns the dictionary.
-
polyfemos.parser.typeoperator.filepath(inputstr)[source]¶ see
path_from_str()for more info.- Parameters
inputstr (str) – A string representing a filepath, reserved variables may be used to create mutable filepaths.
- Return type
func
- Returns
-
polyfemos.parser.typeoperator.function(inputstr)[source]¶ See the function syntax and more info in
function_from_str()- Parameters
inputstr (str) – A string representing a function
- Return type
func
- Returns
-
polyfemos.parser.typeoperator.isNaN(num)[source]¶ check if
numis NaN- Parameters
num (numlike) –
- Return type
- Returns
-
polyfemos.parser.typeoperator.list_(inputstr, type_)[source]¶ A list may be defined with square brackets or the brackets may be omitted. Note that, the whitespaces are treated literally and empty list entries are removed.
-
polyfemos.parser.typeoperator.literal_eval(inputstr, type_)[source]¶ - Parameters
inputstr (str) – a string representation of the value to be passed to
ast.literal_eval().type_ (class or type) – desired type of the resulting value
- Return type
anything
- Returns
The retrun type is
type_. ReturnsNoneif something went wrong while trying to convertinputstrinto it’s desired type.
-
polyfemos.parser.typeoperator.ordinal(inputstr, today=None)[source]¶ - Parameters
inputstr (str) – A string compatible with
Ordinalconstructor. If symbol ‘+’ is contained ininputstr, an offset is applied to the returned value. The offset is an integer value representing days.today (
UTCDateTime, optional) – defaults toNone, if propertodayis given, ‘TODAY’ reserved variable is replaced with the given value.
- Return type
- Returns
-
polyfemos.parser.typeoperator.replaceNaN(func_)[source]¶ A decorator to replace NaN (see
isStrNaN()) values ofargsandkwargsoffunc_with an empty string.- Parameters
func_ (func) –
- Return type
func
- Returns
wrapper
-
polyfemos.parser.typeoperator.staticfilepath(inputstr)[source]¶ see
path_from_str()for more info.
-
polyfemos.parser.typeoperator.utcdatetime(inputstr, today=None)[source]¶ - Parameters
inputstr (str) – A string compatible with
UTCDateTimeconstructor. If symbol ‘+’ is contained ininputstr, an offset is applied to the returned value. The offset is an integer value representing days. If theinputstris not string type, the value is passed toUTCDateTimeconstructor as is.today (
UTCDateTime, optional) – defaults toNone, if propertodayis given, ‘TODAY’ reserved variable is replaced with the given value.
- Return type
- Returns
Private Functions