hyped.core.ops.boolean module

This module defines a collection of data processors for basic Boolean operations.

These processors allow for common Boolean logic operations such as inversion, logical conjunction (AND), disjunction (OR), and exclusive disjunction (XOR). The processors are designed to operate efficiently in a batched manner, leveraging the Apache Arrow backend for optimized performance.

These processors are registered as methods on the BoolFeature class, enabling direct application to Boolean features.

class hyped.core.ops.boolean.And(*args: Any, **kwargs: Any)[source]

Bases: BaseDataProcessor[AndConfig]

Data processor for computing the logical AND of two Boolean values.

process(ctx: RunContext, a: BoolFeature | bool | list[bool] | BooleanScalar | BooleanArray, b: BoolFeature | bool | list[bool] | BooleanScalar | BooleanArray) BoolFeature[source]

Computes the logical AND of two Boolean values.

Parameters:
  • ctx (RunContext) – The execution context.

  • a (Bool) – The first Boolean value.

  • b (Bool) – The second Boolean value.

Returns:

The result of the logical AND operation.

Return type:

BoolFeature

class hyped.core.ops.boolean.AndConfig[source]

Bases: BaseDataProcessorConfig

Configuration for the And processor.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class hyped.core.ops.boolean.Invert(*args: Any, **kwargs: Any)[source]

Bases: BaseDataProcessor[InvertConfig]

Data processor for inverting Boolean values (logical NOT).

process(ctx: RunContext, x: BoolFeature | bool | list[bool] | BooleanScalar | BooleanArray) BoolFeature[source]

Inverts the input Boolean value.

Parameters:
  • ctx (RunContext) – The execution context.

  • x (Bool) – The Boolean value to invert.

Returns:

The inverted Boolean value.

Return type:

BoolFeature

class hyped.core.ops.boolean.InvertConfig[source]

Bases: BaseDataProcessorConfig

Configuration for the Invert processor.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class hyped.core.ops.boolean.Or(*args: Any, **kwargs: Any)[source]

Bases: BaseDataProcessor[OrConfig]

Data processor for computing the logical OR of two Boolean values.

process(ctx: RunContext, a: BoolFeature | bool | list[bool] | BooleanScalar | BooleanArray, b: BoolFeature | bool | list[bool] | BooleanScalar | BooleanArray) BoolFeature[source]

Computes the logical OR of two Boolean values.

Parameters:
  • ctx (RunContext) – The execution context.

  • a (Bool) – The first Boolean value.

  • b (Bool) – The second Boolean value.

Returns:

The result of the logical OR operation.

Return type:

BoolFeature

class hyped.core.ops.boolean.OrConfig[source]

Bases: BaseDataProcessorConfig

Configuration for the Or processor.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class hyped.core.ops.boolean.Where(*args: Any, **kwargs: Any)[source]

Bases: BaseDataProcessor[WhereConfig]

Data processor that selects between two values based on a Boolean condition.

This processor returns the first value if the condition is true, otherwise it returns the second value. It acts similarly to the ternary expression a if cond else b.

T

alias of Annotated[T, MatchFeatures(func=wrapped_validator)]

process(ctx: ~hyped.core.nodes.base.RunContext, cond: ~hyped.core.features.features.BoolFeature | bool | list[bool] | ~pyarrow.lib.BooleanScalar | ~pyarrow.lib.BooleanArray, a: ~hyped.core.ops.boolean.Annotated[~hyped.core.ops.boolean.T, ~hyped.core.features.validators.MatchFeatures(func=~hyped.core.features.validators.FeatureValidator.__init__.<locals>.wrapped_validator)], b: ~hyped.core.ops.boolean.Annotated[~hyped.core.ops.boolean.T, ~hyped.core.features.validators.MatchFeatures(func=~hyped.core.features.validators.FeatureValidator.__init__.<locals>.wrapped_validator)]) wrapped_validator)][source]

Selects one of two values based on a Boolean condition.

Parameters:
  • ctx (RunContext) – The execution context.

  • cond (Bool) – The Boolean condition to evaluate.

  • a (T) – The value to return if cond is True.

  • b (T) – The value to return if cond is False.

Returns:

The selected value based on the condition.

Return type:

T

class hyped.core.ops.boolean.WhereConfig[source]

Bases: BaseDataProcessorConfig

Configuration for the Where processor.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class hyped.core.ops.boolean.Xor(*args: Any, **kwargs: Any)[source]

Bases: BaseDataProcessor[XorConfig]

Data processor for computing the logical XOR of two Boolean values.

process(ctx: RunContext, a: BoolFeature | bool | list[bool] | BooleanScalar | BooleanArray, b: BoolFeature | bool | list[bool] | BooleanScalar | BooleanArray) BoolFeature[source]

Computes the logical XOR of two Boolean values.

Parameters:
  • ctx (RunContext) – The execution context.

  • a (Bool) – The first Boolean value.

  • b (Bool) – The second Boolean value.

Returns:

The result of the logical XOR operation.

Return type:

BoolFeature

class hyped.core.ops.boolean.XorConfig[source]

Bases: BaseDataProcessorConfig

Configuration for the Xor processor.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'validate_default': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].