superleaf.operators.comparison#
Classes
Factories for common |
|
- class superleaf.operators.comparison.ComparisonFunctions[source]#
Bases:
objectFactories for common
BooleanOperatorpredicates, usually imported asF.Every predicate works on single values (
F.gt(0)(5)) and on Series viaon_series, whichdfilterandpartitionuse for keyword filters.on_seriesgives the same result per element as the scalar call, using vectorized pandas operations where they agree with it.In
eq,ne,lt,le,gtandgewith a non-missingvalue, missing values (None, NaN, NaT,pd.NA) are treated like NaN: onlyneis True.Predicates that take
fallbackandexceptionsreturnfallbackwhen evaluating a value raises one ofexceptions. Passing either one enables this;exceptionsdefaults toExceptionandfallbackto False. Without them, exceptions propagate.Examples
>>> F.gt(0)(1) True >>> (F.isna | F.lt(0))(float("nan")) True >>> F.lt(0, fallback=False)("a") False
- Variables:
isna (BooleanOperator) – Test that
xis a missing scalar (None, NaN, NaT orpd.NA).notna (BooleanOperator) – Negation of
isna.isinf (BooleanOperator) – Test that
xis infinite (np.isinf).notinf (BooleanOperator) – Negation of
isinf.
- static eq(value: Any, *, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test
x == value.- Parameters:
value (Any) – Value to compare against.
fallback (bool, optional) – Result when comparing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate.
- Return type:
- static ne(value: Any, *, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test
x != value.- Parameters:
value (Any) – Value to compare against.
fallback (bool, optional) – Result when comparing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate.
- Return type:
- static lt(value: Any, *, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test
x < value.- Parameters:
value (Any) – Value to compare against.
fallback (bool, optional) – Result when comparing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate.
- Return type:
- static le(value: Any, *, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test
x <= value.- Parameters:
value (Any) – Value to compare against.
fallback (bool, optional) – Result when comparing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate.
- Return type:
- static gt(value: Any, *, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test
x > value.- Parameters:
value (Any) – Value to compare against.
fallback (bool, optional) – Result when comparing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate.
- Return type:
- static ge(value: Any, *, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test
x >= value.- Parameters:
value (Any) – Value to compare against.
fallback (bool, optional) – Result when comparing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate.
- Return type:
- static isin(values: Any, *, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test
x in values.- Parameters:
values (iterable or str) – Collection to test membership in; unhashable
xgives False. Astrtests for a substring.fallback (bool, optional) – Result when testing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate.
- Return type:
- static contains(value: Any, *, exceptions=<class 'TypeError'>, fallback=False) BooleanOperator[source]#
Test
value in x.- Parameters:
value (Any) – Item or substring to look for.
exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback. DefaultTypeError, so non-containers give False.fallback (bool, optional) – Result when testing raises one of
exceptions. Default False.
- Returns:
The predicate.
- Return type:
- static contains_all(values: Any, *, exceptions=<class 'TypeError'>, fallback=False) BooleanOperator[source]#
Test that every item of
valuesis inx.- Parameters:
values (Any) – Items to look for. A
stror non-iterable is treated as a single item.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback. DefaultTypeError, so non-containers give False.fallback (bool, optional) – Result when testing raises one of
exceptions. Default False.
- Returns:
The predicate.
- Return type:
- static contains_any(values: Any, *, exceptions=<class 'TypeError'>, fallback=False) BooleanOperator[source]#
Test that at least one item of
valuesis inx.- Parameters:
values (Any) – Items to look for. A
stror non-iterable is treated as a single item.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback. DefaultTypeError, so non-containers give False.fallback (bool, optional) – Result when testing raises one of
exceptions. Default False.
- Returns:
The predicate.
- Return type:
- static startswith(value: Any, *, str_converter=<class 'str'>, raise_type_error=False, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test that
xstarts withvalue.- Parameters:
value (Any) – Prefix. Converted with
str_converterif not astr.str_converter (callable or None, optional) – Converts non-missing, non-
strvalues ofx(andvalue) tostr. Defaultstr. If None, non-strvalues give False.raise_type_error (bool, optional) – If True, raise
TypeErrorfor non-strvalues instead of converting them.fallback (bool, optional) – Result when testing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate. Missing values give False unless
raise_type_erroris True.- Return type:
- static endswith(value: Any, *, str_converter=<class 'str'>, raise_type_error=False, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test that
xends withvalue.- Parameters:
value (Any) – Suffix. Converted with
str_converterif not astr.str_converter (callable or None, optional) – Converts non-missing, non-
strvalues ofx(andvalue) tostr. Defaultstr. If None, non-strvalues give False.raise_type_error (bool, optional) – If True, raise
TypeErrorfor non-strvalues instead of converting them.fallback (bool, optional) – Result when testing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate. Missing values give False unless
raise_type_erroris True.- Return type:
- static startswith_one_of(values: ~typing.Iterable[~typing.Any], *, str_converter=<class 'str'>, raise_type_error=False, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test that
xstarts with any ofvalues.- Parameters:
values (iterable) – Prefixes. Each is converted with
str_converterif not astr.str_converter (callable or None, optional) – See
startswith().raise_type_error (bool, optional) – See
startswith().fallback (bool, optional) – Result when testing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate.
- Return type:
- static endswith_one_of(values: ~typing.Iterable[~typing.Any], *, str_converter=<class 'str'>, raise_type_error=False, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test that
xends with any ofvalues.- Parameters:
values (iterable) – Suffixes. Each is converted with
str_converterif not astr.str_converter (callable or None, optional) – See
endswith().raise_type_error (bool, optional) – See
endswith().fallback (bool, optional) – Result when testing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate.
- Return type:
- static matches_regex(pattern: str, how: Literal['match', 'search', 'fullmatch']='match', *, flags: int = 0, str_converter=<class 'str'>, raise_type_error=False, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test that
xmatches a regular expression.- Parameters:
pattern (str) – Regular expression.
how ({"match", "search", "fullmatch"}, optional) –
"match"(default) anchors the pattern at the start ofx,"search"finds it anywhere, and"fullmatch"requires it to match all ofx; as inre.flags (int, optional) –
reflags.str_converter (callable or None, optional) – See
startswith().raise_type_error (bool, optional) – See
startswith().fallback (bool, optional) – Result when testing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate.
- Return type:
- Raises:
ValueError – If
howis not one of the allowed values.
- static fuzzy_match(targets: str | ~typing.Iterable[str], *, normalizer: ~typing.Callable[[str], str] | None = <unset>, substring: bool = True, score_threshold: float = 80.0, raise_type_error: bool = False, fallback=<unset>, exceptions=None) BooleanOperator[source]#
Test that
xapproximately matches any oftargets. Requiressuperleaf[fuzzy].- Parameters:
targets (str or iterable of str) – Strings to match against.
normalizer (callable or None, optional) – Applied to
xandtargetsbefore scoring. Defaults torapidfuzz.utils.default_process(lowercase, non-alphanumerics replaced by spaces, trimmed). None disables normalization.substring (bool, optional) – If True (default), score with
rapidfuzz.fuzz.partial_ratio, so a target can match part ofx. Otherwise userapidfuzz.fuzz.ratio.score_threshold (float, optional) – Minimum score (0-100) for a match. Default 80.
raise_type_error (bool, optional) – If True, raise
TypeErrorfor non-strvalues; otherwise they give False.fallback (bool, optional) – Result when testing raises one of
exceptions.exceptions (type, tuple of types, or str, optional) – Exceptions that produce
fallback.
- Returns:
The predicate.
- Return type:
- isna: BooleanOperator = <superleaf.operators.base.VectorizedBooleanOperator object>#
- notna: BooleanOperator = <superleaf.operators.base._NotBoolOp object>#
- isinf: BooleanOperator = <superleaf.operators.base.VectorizedBooleanOperator object>#
- notinf: BooleanOperator = <superleaf.operators.base._NotBoolOp object>#
- superleaf.operators.comparison.F[source]#
alias of
ComparisonFunctions