Features¶
features
¶
Feature definitions: the immutable output of phase 1.
Features are frozen dataclasses with structural equality, so a feature reached by two different routes deduplicates in a set with no extra bookkeeping. Every dtype here is derived from primitive metadata, never from data.
Feature¶
Feature
dataclass
¶
Bases: ABC
Base class for every feature definition.
name
abstractmethod
property
¶
The column name in the feature matrix.
A plain SQL identifier: parts are joined with __ rather than the
dots, parentheses and spaces a conventional DFS name uses, since a
backend that generates SQL parses those as table qualifiers and
function calls rather than as part of an identifier. See
:attr:display_name for the readable form.
display_name
abstractmethod
property
¶
The readable name, e.g. MEAN(transactions.amount).
Carries the same meaning as :attr:name in the conventional DFS
notation. Used for documentation, logging and error messages; never
as a column name.
output_names
property
¶
One column name per output; more than one for multi-output primitives.
display_output_names
property
¶
One readable name per output, parallel to :attr:output_names.
is_multi_output
property
¶
Whether this feature materializes more than one column.
Only the indexed names in :attr:output_names are ever materialized,
so a multi-output feature has no single column another primitive could
read. It is a valid output of synthesis but never a valid input.
Deriving this from :attr:output_names rather than from a primitive's
number_of_outputs keeps it well defined for
:class:IdentityFeature and :class:DirectFeature, which have no
primitive at all.
Feature kinds¶
IdentityFeature
dataclass
¶
Bases: Feature
A raw column of a table.
Attributes:
| Name | Type | Description |
|---|---|---|
table_name |
str
|
Table the column belongs to. |
column |
str
|
Column name. |
column_dtype |
Any
|
The column's narwhals dtype. |
DirectFeature
dataclass
¶
Bases: Feature
A parent's feature joined down onto the child.
Attributes:
| Name | Type | Description |
|---|---|---|
base_feature |
Feature
|
The feature on the parent table. |
relationship |
Relationship
|
The parent-child link being traversed. |
TransformFeature
dataclass
¶
GroupByTransformFeature
dataclass
¶
Bases: Feature
A transform applied within groups defined by a foreign key.
Attributes:
| Name | Type | Description |
|---|---|---|
primitive |
Primitive
|
The transform primitive. |
bases |
tuple[Feature, ...]
|
Input features on the child table. |
relationship |
Relationship
|
The link whose foreign key defines the groups. |
AggregationFeature
dataclass
¶
Bases: Feature
A primitive applied to a child table's rows, grouped by foreign key.
Attributes:
| Name | Type | Description |
|---|---|---|
primitive |
Primitive
|
The aggregation primitive. |
bases |
tuple[Feature, ...]
|
Input features on the child table. Empty for zero-arity
primitives such as |
relationship |
Relationship
|
The parent-child link being aggregated across. |
name
property
¶
Generated name, e.g. MEAN__transactions__amount.
Zero-arity primitives name the child table instead of a column, giving
COUNT__transactions.