Package pygeodesy :: Module basics |
[frames] | no frames]

# Module basics

Basic definitions, decorators and functions.

Version: 20.12.20

Classes
| property_RO

Functions
bool |
isinf(x) Check if float x is infinite (positive or negative). |
bool |
isnan(x) Check if float x is not a number (NaN). |
clips(bstr, limit=50, white='') Clip a string to the given length limit. |
copysign(x, y) Like `math.copysign(x, y)` except `zero`, unsigned . |
halfs2(str2) Split a string in 2 halfs. |
isbool(obj) Check whether an object is `bool`ean. |
isclass(obj) Return `True` if `obj` is a `class`. |
isfinite(obj) Check for `Inf` and `NaN` values. |
isidentifier(obj) Return `True` if `obj` is a valid Python identifier. |
isint(obj, both=False) Check for `int` type or an integer `float` value. |
iskeyword(x, y) y in x. |
isneg0(obj) Check for NEG0, negative `0.0`. |
isscalar(obj) Check for scalar types. |
issequence(obj, *excluded) Check for sequence types. |
isstr(obj) Check for string types. |
issubclassof(Sub, Super) Check whether a class is a sub-class of a super class. |
len2(items) Make built-in function `len` work for generators, iterators, etc. |
map1(fun1, *xs) Apply each argument to a single-argument function and return a `tuple` of results. |
map2(func, *xs) Apply arguments to a function and return a `tuple` of results. |
neg(x) Negate `x` unless `zero` or `NEG0`. |
neg_(*xs) Negate all of `xs` like neg. |
property_doc_(doc) Decorator for a property with documentation. |
ub2str(ub) Convert `unicode` or `bytes` to `str`. |

Variables
| __all__ = `_ALL_LAZY.basics`

Function Details

### clips (bstr, limit=50, white='') |
Clip a string to the given length limit. Arguments: `bstr` - String (`bytes` or `str`). `limit` - Length limit (`int`). `white` - Optionally, replace all whitespace (`str`). Returns: The clipped or unclipped `bstr`.

### copysign (x, y) |
Like `math.copysign(x, y)` except `zero`, unsigned . Returns: `math.copysign(x, y)` if `x` else `0.0`.

### halfs2 (str2) |
Split a string in 2 halfs. Arguments: `str2` - String to split (`str`). Returns: 2-Tuple (_1st, _2nd) half (`str`). Raises: `ValueError` - Zero or odd `len`(`str2`).

### isbool (obj) |
Check whether an object is `bool`ean. Arguments: `obj` - The object (any `type`). Returns: `True` if `obj` is `bool`ean, `False` otherwise.

### isclass (obj) |
Return `True` if `obj` is a `class`. See Also: Python's `inspect.isclass`.

### isfinite (obj) |
Check for `Inf` and `NaN` values. Arguments: `obj` - Value (`scalar`). Returns: `False` if `obj` is `INF` or `NAN`, `True` otherwise. Raises: `TypeError` - Non-scalar `obj`.

### isint (obj, both=False) |
Check for `int` type or an integer `float` value. Arguments: `obj` - The object (any `type`). `both` - Optionally, check `float` type and value (`bool`). Returns: `True` if `obj` is `int` or an integer `float`, `False` otherwise. Note: `isint(True)` or `isint(False)` returns `False` (and no longer `True`).

### isneg0 (obj) |
Check for NEG0, negative `0.0`. Arguments: `obj` - Value (`scalar`). Returns: `True` if `obj` is `NEG0` or `-0.0`, `False` otherwise.

### isscalar (obj) |
Check for scalar types. Arguments: `obj` - The object (any `type`). Returns: `True` if `obj` is `scalar`, `False` otherwise.

### issequence (obj, *excluded) |
Check for sequence types. Arguments: `obj` - The object (any `type`). `excluded` - Optional exclusions (`type`). Returns: `True` if `obj` is a sequence, `False` otherwise. Note: Excluding `tuple` implies excluding `namedtuple`.

### isstr (obj) |
Check for string types. Arguments: `obj` - The object (any `type`). Returns: `True` if `obj` is `str`, `False` otherwise.

### issubclassof (Sub, Super) |
Check whether a class is a sub-class of a super class. Arguments: `Sub` - The sub-class (`class`). `Super` - The super class (`class`). Returns: `True` if `Sub` is a sub-class of `Super`, `False` otherwise (`bool`).

### len2 (items) |
Make built-in function `len` work for generators, iterators, etc. since those can only be started exactly once. Arguments: `items` - Generator, iterator, list, range, tuple, etc. Returns: 2-Tuple `(n, items)` of the number of items (`int`) and the items (`list` or `tuple`).

### map1 (fun1, *xs) |
Apply each argument to a single-argument function and return a `tuple` of results. Arguments: `fun1` - 1-Arg function to apply (`callable`). `xs` - Arguments to apply (`any positional`). Returns: Function results (`tuple`).

### map2 (func, *xs) |
Apply arguments to a function and return a `tuple` of results. Unlike Python 2's built-in `map`, Python 3+ `map` returns a `map` object, an iterator-like object which generates the results only once. Converting the `map` object to a tuple maintains Python 2 behavior. Arguments: `func` - Function to apply (`callable`). `xs` - Arguments to apply (`list, tuple, ...`). Returns: Function results (`tuple`).

### neg (x) |
Negate `x` unless `zero` or `NEG0`. Returns: `-x` if `x` else `0.0`.

### neg_ (*xs) |
Negate all of `xs` like neg. Returns: Yield `neg(x) for x in xs`.

### property_doc_ (doc) |
Decorator for a property with documentation. Arguments: `doc` - The property documentation (`str`). Example:
    >>> @property_doc_("documentation text.")
    >>> def name(self):
    >>>     ...
    >>>
    >>> @name.setter
    >>> def name(self, value):
    >>>     ...