Skip to content

feature

Represent a feature object.

Classes:

Name Description
BaseFeature

Base Feature used if no convenient available feature.

ExplainableFeature

Define a feature object.

IndexMetadata

Represents an index metadata, automatically added to the schema, cf doc dataset/concept.

__all__ = ['BaseFeature', 'ExplainableFeature', 'IndexMetadata'] #

AbstractFeature #

Parameters:

Name Type Description Default

name #

str
required

id #

str | None
None

is_target #

bool
False

Attributes:

Name Type Description
id str | None
is_target bool

id: str | None = None #

is_target: bool = False #

BaseFeature #

Base Feature used if no convenient available feature.

Parameters:

Name Type Description Default

name #

str
required

id #

str | None
None

is_target #

bool
False

ExplainableFeature #

Define a feature object.

Parameters:

Name Type Description Default

id #

UUID | None

Feature Identifier

None

is_target #

bool

Whether the feature is target or not.

False

feature_type #

FeatureTypeUnion
required

UnivariateTimeSeriesFeature #

Feature type.

required

preprocessor #

TorchPreprocessor | SklearnPreprocessor | IdentityPreprocessor

The feature preprocessor function used to preprocess the data.

required

name #

str
required

augmentation #

FeatureAugmentation | None
None

Methods:

Name Description
to_model

Convert to FeatureInsert instance.

stable_hash

Return a hash, without the id.

Attributes:

Name Type Description
feature_type FeatureTypeUnion
preprocessor TorchPreprocessor | SklearnPreprocessor | IdentityPreprocessor | BoundingBoxesPreprocessor
augmentation FeatureAugmentation | None

feature_type: FeatureTypeUnion = field(kw_only=True) #

preprocessor: TorchPreprocessor | SklearnPreprocessor | IdentityPreprocessor | BoundingBoxesPreprocessor = field(kw_only=True) #

augmentation: FeatureAugmentation | None = field(kw_only=True, default=None) #

to_model() -> FeatureInsert #

Convert to FeatureInsert instance.

Source code in src/xpdeep/dataset/feature/feature.py
def to_model(self) -> FeatureInsert:
    """Convert to FeatureInsert instance."""
    return FeatureInsert(
        type_="FEATURE",
        name=self.name,
        feature_type=self.feature_type.to_model(),
        is_target=self.is_target,
        preprocessor=self.preprocessor.to_model(),
        augmentation=self.augmentation.to_model() if self.augmentation is not None else None,
    )

stable_hash() -> str #

Return a hash, without the id.

Source code in src/xpdeep/dataset/feature/feature.py
def stable_hash(self) -> str:
    """Return a hash, without the id."""
    augmentation_hash = self.augmentation.stable_hash() if self.augmentation is not None else None
    return str(
        sha256(
            f"{self.feature_type.stable_hash()}_{self.preprocessor.stable_hash()}_{augmentation_hash}_{self.is_target}".encode()
        ).hexdigest()
    )

IndexMetadata #

Represents an index metadata, automatically added to the schema, cf doc dataset/concept.

Parameters:

Name Type Description Default

name #

str
required

id #

str | None
None

feature_type #

str
'xpdeep_index'

Methods:

Name Description
to_model

Convert to IndexMetadataInsert instance.

stable_hash

Return a hash, without the id.

Attributes:

Name Type Description
name str
id str | None
feature_type str

name: str #

id: str | None = None #

feature_type: str = 'xpdeep_index' #

to_model() -> IndexMetadataInsert #

Convert to IndexMetadataInsert instance.

Source code in src/xpdeep/dataset/feature/feature.py
def to_model(self) -> IndexMetadataInsert:
    """Convert to IndexMetadataInsert instance."""
    return IndexMetadataInsert(name=self.name, type_="INDEX_METADATA")

stable_hash() -> str #

Return a hash, without the id.

Source code in src/xpdeep/dataset/feature/feature.py
def stable_hash(self) -> str:
    """Return a hash, without the id."""
    return str(sha256(f"{self.name}_{self.feature_type}".encode()).hexdigest())

feature_from_model(json_response: dict[str, object]) -> BaseFeature | ExplainableFeature | IndexMetadata #

Convert json exposed features into corresponding Feature.

Source code in src/xpdeep/dataset/feature/feature.py
def feature_from_model(json_response: dict[str, object]) -> BaseFeature | ExplainableFeature | IndexMetadata:
    """Convert json exposed features into corresponding Feature."""
    match json_response["type"]:
        case "INDEX_METADATA":
            try:
                index_metadata: IndexMetadataSelect | IndexMetadataInsert = IndexMetadataSelect.from_dict(json_response)
            except KeyError:
                index_metadata = IndexMetadataInsert.from_dict(json_response)

            return IndexMetadata(
                id=index_metadata.id if isinstance(index_metadata, IndexMetadataSelect) else None,
                name=index_metadata.name,
            )

        case "FEATURE":
            try:
                feature: FeatureSelectInput | FeatureInsert = FeatureSelectInput.from_dict(json_response)
            except KeyError:
                feature = FeatureInsert.from_dict(json_response)

            if feature.preprocessor is None or isinstance(feature.preprocessor, Unset):
                return BaseFeature(
                    id=feature.id if isinstance(feature, FeatureSelectInput) else None,
                    name=feature.name,
                    is_target=bool(feature.is_target),
                )

            return ExplainableFeature(
                id=feature.id if isinstance(feature, FeatureSelectInput) else None,
                name=feature.name,
                is_target=bool(feature.is_target),
                feature_type=feature_type_from_model(feature.feature_type),
                preprocessor=preprocessor_from_model(feature.preprocessor),
                augmentation=augmentation_from_model(feature.augmentation)
                if not (isinstance(feature.augmentation, Unset) or feature.augmentation is None)
                else None,
            )

        case _:
            msg = (
                f"`type` should be one of the following values: `INDEX_METADATA` or "
                f"`FEATURE`. Got {json_response['type']} "
            )
            raise ApiError(msg)