ndtools.comparison.builtins module#
- ndtools.comparison.builtins.ANY = ANY#
Comparable that is always evaluated as True.
Examples
import numpy as np from ndtools import ANY np.arange(3) == ANY # -> array([True, True, True])
- class ndtools.comparison.builtins.AnyType[source]#
Bases:
Combinable,EquatableComparable that is always evaluated as True.
It is singleton and all instances created by
AnyType()are thus identical. ndtools provides it asndtools.ANY.Examples
import numpy as np from ndtools import ANY np.arange(3) == ANY # -> array([True, True, True])
- class ndtools.comparison.builtins.Match(pat: str, case: bool = True, flags: int = 0, na: Any = None)[source]#
Bases:
Combinable,EquatableComparable that matches regular expression to each array element.
It uses
pandas.Series.str.fullmatchso the same options are available.- Parameters:
pat – Character sequence or regular expression.
case – If True, case sensitive matching will be performed.
flags – Regular expression flags, e.g.
re.IGNORECASE.na – Fill value for missing values. The default value depends on data type of the array. For object-dtype,
numpy.nanwill be used. ForStringDtype,pandas.NAwill be used.
Examples
import numpy as np from ndtools import Match np.array(["a", "aa"]) == Match("a+") # -> array([True, True])
- case: bool = True#
If True, case sensitive matching will be performed.
- flags: int = 0#
Regular expression flags, e.g.
re.IGNORECASE.
- na: Any = None#
Fill value for missing values.
- pat: str#
Character sequence or regular expression.
- ndtools.comparison.builtins.NEVER = NEVER#
Comparable that is always evaluated as False.
Examples
import numpy as np from ndtools import NEVER np.arange(3) == NEVER # -> array([False, False, False])
- class ndtools.comparison.builtins.NeverType[source]#
Bases:
Combinable,EquatableComparable that is always evaluated as False.
It is singleton and all instances created by
NeverType()are thus identical. ndtools provides it asndtools.NEVER.Examples
import numpy as np from ndtools import NEVER np.arange(3) == NEVER # -> array([False, False, False])
- class ndtools.comparison.builtins.Range(lower: Any, upper: Any, bounds: Literal['[]', '[)', '(]', '()'] = '[)')[source]#
Bases:
Combinable,OrderableComparable that implements equivalence with a certain range.
- Parameters:
lower – Lower value of the range. If
Noneis specified, then the lower value comparison will be skipped.lower – Upper value of the range. If
Noneis specified, then the upper value comparison will be skipped.bounds – Type of bounds of the range.
[]: Lower-closed and upper-closed.[): Lower-closed and upper-open (default).(]: Lower-open and upper-closed.(): Lower-open and upper-open.
Examples
import numpy as np from ndtools import Range np.arange(3) == Range(1, 2) # -> array([False, True, False]) np.arange(3) < Range(1, 2) # -> array([True, False, False]) np.arange(3) > Range(1, 2) # -> array([False, False, True]) np.arange(3) == Range(None, 2) # -> array([True, True, False]) np.arange(3) == Range(1, None) # -> array([False, True, True]) np.arange(3) == Range(None, None) # -> array([True, True, True])
- bounds: Literal['[]', '[)', '(]', '()'] = '[)'#
Type of bounds of the range.
- property is_lower_closed: bool#
Check if the lower bound is closed.
- property is_lower_open: bool#
Check if the lower bound is open.
- property is_upper_closed: bool#
Check if the upper bound is closed.
- property is_upper_open: bool#
Check if the upper bound is open.
- lower: Any#
Lower value of the range.
- upper: Any#
Upper value of the range.
- class ndtools.comparison.builtins.Where(func: Callable[[...], Any], *args: Any, **kwargs: Any)[source]#
Bases:
Combinable,EquatableComparable that applies a boolean function for multidimensional arrays.
- Parameters:
func – Boolean function that takes
func(array, *args, **kwargs).*args – Positional arguments to be passed to the function.
**kwargs – Keyword arguments to be passed to the function.
Examples
import numpy as np from ndtools import Where from numpy.char import isupper np.array(["A", "b"]) == Where(isupper) # -> array([True, False])
- args: Any#
Positional arguments to be passed to the function.
- func: Callable[[...], Any]#
Boolean function that takes
func(array, *args, **kwargs).
- kwargs: Any#
Keyword arguments to be passed to the function.