polyfemos.parser.typeoperator — polyfemos 0.3.29 documentation

# 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_)

  A decorator to be composed with a one-argument function, If the argument of the decorated function (`func_`) is NaN return `None`, else call function `func_`

  Parameters

    func_ (func) – A one-argument function

  Return type

    func

  Returns

    `wrapper`

`polyfemos.parser.typeoperator.` `anything`(inputstr)

  Has no effect whatsoever.

  Parameters

    inputstr (str) –

  Return type

    str

  Returns

`polyfemos.parser.typeoperator.` `bool_`(inputstr)
  Parameters

    inputstr (str) –

  Return type

    bool

  Returns

    `inputstr` converted into boolean, values `True` and `False` follow the boolean rules of python, e.g. `"" = 0 = False` and `"asd" = 1 = 9. = True`.

`polyfemos.parser.typeoperator.` `check_type`(func_, invalid_value=None)

  A decorator to be composed with function where `ValueError` or `TypeError` might occur. If the error occurs while `func_` is called, the return value of the `func_` is `None`.

  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)

  Calls `literal_eval()` to for a dictionary from `inputstr` and returns the dictionary.

  Parameters

    inputstr (str) – A string representation of a python dictionary

  Return type

    dict

  Returns

    Dictionary or `None`

`polyfemos.parser.typeoperator.` `filepath`(inputstr)

  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.` `float_`(inputstr)
  Parameters

    inputstr (str) –

  Return type

    float

  Returns

    `inputstr` converted into float

`polyfemos.parser.typeoperator.` `floatlist`(inputstr)
  Parameters

    inputstr (str) – a string representation of a list containing floating point values

  Return type

    list

  Returns

    A list of float values

`polyfemos.parser.typeoperator.` `function`(inputstr)

  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.` `getNaN`()
  Return type

    float

  Returns

    `float('nan')`

`polyfemos.parser.typeoperator.` `int_`(inputstr, to_float_first=True)
  Parameters

    - inputstr (str) –

    - to_float_first (bool, optional) – defaults to `True`, If `True` the input string is first converted to float and then to integer.

  Return type

    int

  Returns

    `inputstr` converted into integer

`polyfemos.parser.typeoperator.` `intlist`(inputstr)
  Parameters

    inputstr (str) – a string representation of a list containing integer values

  Return type

    list

  Returns

    A list of integer values

`polyfemos.parser.typeoperator.` `isNaN`(num)

  check if `num` is NaN

  Parameters

    num (numlike) –

  Return type

    bool

  Returns

`polyfemos.parser.typeoperator.` `isStrNaN`(inputstr)
  Parameters

    inputstr (str) –

  Return type

    bool

  Returns

    `True`, if `inputstr` is is equal any string representation of nan.

`polyfemos.parser.typeoperator.` `list_`(inputstr, type_)

  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.

  Parameters

    - inputstr (str) – a string representation of a list containing either string, int, or float values.

    - type_ (str) – Either ‘str’, ‘float’ or ‘int’, describing the resulting type of the list entries.

  Return type

    list

  Returns

    A list of either string, int, or float values.

`polyfemos.parser.typeoperator.` `literal_eval`(inputstr, type_)
  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_`. Returns `None` if something went wrong while trying to convert `inputstr` into it’s desired type.

`polyfemos.parser.typeoperator.` `ordinal`(inputstr, today=None)
  Parameters

    - inputstr (str) – A string compatible with `Ordinal` constructor. If symbol ‘+’ is contained in `inputstr`, an offset is applied to the returned value. The offset is an integer value representing days.

    - today (`UTCDateTime`, optional) – defaults to `None`, if proper `today` is given, ‘TODAY’ reserved variable is replaced with the given value.

  Return type

    `Ordinal`

  Returns

`polyfemos.parser.typeoperator.` `replaceNaN`(func_)

  A decorator to replace NaN (see `isStrNaN()`) values of `args` and `kwargs` of `func_` with an empty string.

  Parameters

    func_ (func) –

  Return type

    func

  Returns

    `wrapper`

`polyfemos.parser.typeoperator.` `staticfilepath`(inputstr)

  see `path_from_str()` for more info.

  Parameters

    inputstr (str) – A string representing a filepath, the `inputstr` may not contain reserved variables

  Return type

    str

  Returns

    A string representing a filepath

`polyfemos.parser.typeoperator.` `strNaN`()
  Return type

    str

  Returns

    string representation of NaN

`polyfemos.parser.typeoperator.` `str_`(inputstr, check_empty=False)
  Parameters

    inputstr (str) –

  Return type

    str

  Returns

    `inputstr` converted into string, but nothing happened!

`polyfemos.parser.typeoperator.` `strlist`(inputstr)
  Parameters

    inputstr (str) – a string representation of a list containing string values, for example: `[1,asd,3, 4]`. The resulting list will be `["1", "asd", "3", " 4"]`.

  Return type

    list

  Returns

    A list of string values

`polyfemos.parser.typeoperator.` `utcdatetime`(inputstr, today=None)
  Parameters

    - inputstr (str) – A string compatible with `UTCDateTime` constructor. If symbol ‘+’ is contained in `inputstr`, an offset is applied to the returned value. The offset is an integer value representing days. If the `inputstr` is not string type, the value is passed to `UTCDateTime` constructor as is.

    - today (`UTCDateTime`, optional) – defaults to `None`, if proper `today` is given, ‘TODAY’ reserved variable is replaced with the given value.

  Return type

    `UTCDateTime`

  Returns

`polyfemos.parser.typeoperator.` `var`(inputstr)
  Parameters

    inputstr (str) –

  Return type

    str

  Returns

    Adds the variable symbol to the start of the `inputstr`, if the `inputstr` lacks it.

Private Functions

`polyfemos.parser.typeoperator.` `_get_offset`(inputstr)
  Parameters

    inputstr (str) –

  Return type

    int

  Returns

    An integer number after ‘+’ symbol in `inputstr`, negative or positive. For negative offsets, the `inputstr` has to be for example: `SOMETHING+-5`.