Types¶
Versioning Engine¶
metaxy.versioning.types.LazyIncrement
dataclass
¶
LazyIncrement(*, added: LazyFrame[Any], changed: LazyFrame[Any], removed: LazyFrame[Any], input: LazyFrame[Any] | None = None)
Result of an incremental update containing lazy dataframes.
Attributes:
-
added(LazyFrame[Any]) –New samples from upstream not present in current metadata.
-
changed(LazyFrame[Any]) –Samples with different provenance.
-
removed(LazyFrame[Any]) –Samples in current metadata but not in upstream state.
-
input(LazyFrame[Any] | None) –Joined upstream metadata with
FeatureDeprules applied.
Functions¶
metaxy.versioning.types.LazyIncrement.collect
¶
Collect all lazy frames to eager DataFrames.
Tip
If all lazy frames are Polars frames, leverages
polars.collect_all
to optimize the collection process and take advantage of common subplan elimination.
Parameters:
-
**kwargs(Any, default:{}) –backend-specific keyword arguments to pass to the collect method of the lazy frames.
Returns:
-
Increment(Increment) –The collected increment.
Source code in src/metaxy/versioning/types.py
def collect(self, **kwargs: Any) -> Increment:
"""Collect all lazy frames to eager DataFrames.
!!! tip
If all lazy frames are Polars frames, leverages
[`polars.collect_all`](https://docs.pola.rs/api/python/stable/reference/api/polars.collect_all.html)
to optimize the collection process and take advantage of common subplan elimination.
Args:
**kwargs: backend-specific keyword arguments to pass to the collect method of the lazy frames.
Returns:
Increment: The collected increment.
"""
if (
self.added.implementation
== self.changed.implementation
== self.removed.implementation
== nw.Implementation.POLARS
):
polars_eager_increment = PolarsLazyIncrement(
added=self.added.to_native(),
changed=self.changed.to_native(),
removed=self.removed.to_native(),
).collect(**kwargs)
return Increment(
added=nw.from_native(polars_eager_increment.added),
changed=nw.from_native(polars_eager_increment.changed),
removed=nw.from_native(polars_eager_increment.removed),
)
else:
return Increment(
added=self.added.collect(**kwargs),
changed=self.changed.collect(**kwargs),
removed=self.removed.collect(**kwargs),
)
metaxy.versioning.types.LazyIncrement.to_polars
¶
to_polars() -> PolarsLazyIncrement
Convert to Polars.
Tip
If the Narwhals lazy frames are already backed by Polars, this is a no-op.
Warning
If the Narwhals lazy frames are not backed by Polars, this will trigger a full materialization for them.
Source code in src/metaxy/versioning/types.py
def to_polars(self) -> PolarsLazyIncrement:
"""Convert to Polars.
!!! tip
If the Narwhals lazy frames are already backed by Polars, this is a no-op.
!!! warning
If the Narwhals lazy frames are **not** backed by Polars, this will
trigger a full materialization for them.
"""
return PolarsLazyIncrement(
added=lazy_frame_to_polars(self.added),
changed=lazy_frame_to_polars(self.changed),
removed=lazy_frame_to_polars(self.removed),
input=lazy_frame_to_polars(self.input) if self.input is not None else None,
)
metaxy.versioning.types.Increment
¶
Bases: NamedTuple
Result of an incremental update containing eager dataframes.
Contains three sets of samples:
-
added: New samples from upstream not present in current metadata
-
changed: Samples with different provenance
-
removed: Samples in current metadata but not in upstream state
Functions¶
metaxy.versioning.types.Increment.to_polars
¶
to_polars() -> PolarsIncrement
metaxy.versioning.types.PolarsIncrement
¶
Bases: NamedTuple
Like Increment, but converted to Polars frames.
metaxy.versioning.types.PolarsLazyIncrement
dataclass
¶
PolarsLazyIncrement(*, added: LazyFrame, changed: LazyFrame, removed: LazyFrame, input: LazyFrame | None = None)
Like LazyIncrement, but converted to Polars lazy frames.
Attributes:
-
added(LazyFrame) –New samples from upstream not present in current metadata.
-
changed(LazyFrame) –Samples with different provenance.
-
removed(LazyFrame) –Samples in current metadata but not in upstream state.
-
input(LazyFrame | None) –Joined upstream metadata with
FeatureDeprules applied.
Attributes¶
metaxy.versioning.types.PolarsLazyIncrement.input
class-attribute
instance-attribute
¶
Functions¶
metaxy.versioning.types.PolarsLazyIncrement.collect
¶
collect(**kwargs: Any) -> PolarsIncrement
Collect into a PolarsIncrement.
Tip
Leverages polars.collect_all
to optimize the collection process and take advantage of common subplan elimination.
Parameters:
-
**kwargs(Any, default:{}) –backend-specific keyword arguments to pass to the collect method of the lazy frames.
Returns:
-
PolarsIncrement(PolarsIncrement) –The collected increment.
Source code in src/metaxy/versioning/types.py
def collect(self, **kwargs: Any) -> PolarsIncrement:
"""Collect into a [`PolarsIncrement`][metaxy.versioning.types.PolarsIncrement].
!!! tip
Leverages [`polars.collect_all`](https://docs.pola.rs/api/python/stable/reference/api/polars.collect_all.html)
to optimize the collection process and take advantage of common subplan elimination.
Args:
**kwargs: backend-specific keyword arguments to pass to the collect method of the lazy frames.
Returns:
PolarsIncrement: The collected increment.
"""
added, changed, removed = pl.collect_all(
[self.added, self.changed, self.removed], **kwargs
)
return PolarsIncrement(added, changed, removed)
metaxy.HashAlgorithm
¶
Keys¶
Types for working with feature and field keys.
Canonical Keys¶
metaxy.FeatureKey
¶
FeatureKey(parts: str | Sequence[str] | FeatureKey)
Bases: _Key
Feature key as a sequence of string parts.
Hashable for use as dict keys in registries. Parts cannot contain forward slashes (/) or double underscores (__).
Example:
```py
FeatureKey("a/b/c") # String format
# FeatureKey(parts=['a', 'b', 'c'])
FeatureKey(["a", "b", "c"]) # List format
# FeatureKey(parts=['a', 'b', 'c'])
FeatureKey(FeatureKey(["a", "b", "c"])) # FeatureKey copy
# FeatureKey(parts=['a', 'b', 'c'])
```
Source code in src/metaxy/models/types.py
Attributes¶
metaxy.FeatureKey.parts
property
¶
Backward compatibility property for accessing root as parts.
metaxy.FeatureKey.table_name
property
¶
table_name: str
Get SQL-like table name for this feature key.
Replaces hyphens with underscores for SQL compatibility.
Functions¶
metaxy.FeatureKey.__lt__
¶
metaxy.FeatureKey.__le__
¶
metaxy.FeatureKey.__gt__
¶
metaxy.FeatureKey.__ge__
¶
metaxy.FeatureKey.__iter__
¶
metaxy.FeatureKey.__getitem__
¶
metaxy.FeatureKey.__contains__
¶
metaxy.FeatureKey.__reversed__
¶
metaxy.FeatureKey.model_dump
¶
metaxy.FeatureKey.__eq__
¶
metaxy.FieldKey
¶
Bases: _Key
Field key as a sequence of string parts.
Hashable for use as dict keys in registries. Parts cannot contain forward slashes (/) or double underscores (__).
Example:
```py
FieldKey("a/b/c") # String format
# FieldKey(parts=['a', 'b', 'c'])
FieldKey(["a", "b", "c"]) # List format
# FieldKey(parts=['a', 'b', 'c'])
FieldKey(FieldKey(["a", "b", "c"])) # FieldKey copy
# FieldKey(parts=['a', 'b', 'c'])
```
Source code in src/metaxy/models/types.py
Attributes¶
metaxy.FieldKey.parts
property
¶
Backward compatibility property for accessing root as parts.
metaxy.FieldKey.table_name
property
¶
table_name: str
Get SQL-like table name for this feature key.
Replaces hyphens with underscores for SQL compatibility.
Functions¶
metaxy.FieldKey.__lt__
¶
metaxy.FieldKey.__le__
¶
metaxy.FieldKey.__gt__
¶
metaxy.FieldKey.__ge__
¶
metaxy.FieldKey.__iter__
¶
metaxy.FieldKey.__getitem__
¶
metaxy.FieldKey.__contains__
¶
metaxy.FieldKey.__reversed__
¶
metaxy.FieldKey.model_dump
¶
metaxy.FieldKey.__eq__
¶
Type Annotations¶
These are typically used to annotate function parameters. Most APIs in Metaxy accepts them and perform type coercion into canonical types.
metaxy.CoercibleToFeatureKey
module-attribute
¶
metaxy.CoercibleToFieldKey
module-attribute
¶
Pydantic Type Annotations¶
These types are used for type coercion into canonical types with Pydantic.
metaxy.ValidatedFeatureKeySequence
module-attribute
¶
ValidatedFeatureKeySequence: TypeAlias = Sequence[ValidatedFeatureKey]
metaxy.ValidatedFieldKeySequence
module-attribute
¶
ValidatedFieldKeySequence: TypeAlias = Sequence[ValidatedFieldKey]
Adapters¶
These can perform type coercsion into canonical types in non-pydantic code.
metaxy.ValidatedFeatureKeyAdapter
module-attribute
¶
ValidatedFeatureKeyAdapter: TypeAdapter[ValidatedFeatureKey] = TypeAdapter(ValidatedFeatureKey)
metaxy.ValidatedFeatureKeySequenceAdapter
module-attribute
¶
ValidatedFeatureKeySequenceAdapter: TypeAdapter[ValidatedFeatureKeySequence] = TypeAdapter(ValidatedFeatureKeySequence)
metaxy.ValidatedFieldKeyAdapter
module-attribute
¶
ValidatedFieldKeyAdapter: TypeAdapter[ValidatedFieldKey] = TypeAdapter(ValidatedFieldKey)
metaxy.ValidatedFieldKeySequenceAdapter
module-attribute
¶
ValidatedFieldKeySequenceAdapter: TypeAdapter[ValidatedFieldKeySequence] = TypeAdapter(ValidatedFieldKeySequence)
Other Types¶
metaxy.models.types.SnapshotPushResult
¶
Bases: NamedTuple
Result of recording a feature graph snapshot.
Attributes:
-
snapshot_version(str) –The deterministic hash of the graph snapshot
-
already_pushed(bool) –True if this snapshot_version was already pushed previously
-
updated_features(list[str]) –List of feature keys with updated information (changed full_definition_version)