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
ValueError
orTypeError
might 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 frominputstr
and 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
num
is 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_
. ReturnsNone
if something went wrong while trying to convertinputstr
into it’s desired type.
-
polyfemos.parser.typeoperator.
ordinal
(inputstr, today=None)[source]¶ - Parameters
inputstr (str) – A string compatible with
Ordinal
constructor. 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 propertoday
is 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 ofargs
andkwargs
offunc_
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
UTCDateTime
constructor. If symbol ‘+’ is contained ininputstr
, an offset is applied to the returned value. The offset is an integer value representing days. If theinputstr
is not string type, the value is passed toUTCDateTime
constructor as is.today (
UTCDateTime
, optional) – defaults toNone
, if propertoday
is given, ‘TODAY’ reserved variable is replaced with the given value.
- Return type
- Returns
Private Functions