Dataframes and merge functions¶
StandardFrame¶
uptimely.dataframes.StandardFrame
¶
Describe a dataframe without changing the value passed between functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
object
|
A Polars, PyArrow, or configured dataframe instance. |
required |
classes
|
ClassRegistry | None
|
Additional dataframe classes and their evaluation modes. |
None
|
row_count
property
¶
Return the eager row count, or None without collecting a lazy frame.
Raises:
| Type | Description |
|---|---|
TypeError
|
The eager dataframe class does not support row counts. |
supports_engineframe
staticmethod
¶
Return whether the built-in engine can convert the dataframe.
head
¶
Return a new wrapper containing at most the requested number of rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rows
|
int
|
Nonnegative maximum row count. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
The row count is not a nonnegative integer. |
TypeError
|
Limiting rows is not supported for the dataframe class. |
collect
¶
Return a new wrapper containing the eager dataframe.
Raises:
| Type | Description |
|---|---|
TypeError
|
Collection is not supported for the lazy dataframe class. |
to_engineframe
¶
Return a Polars dataframe without modifying the wrapped value.
Raises:
| Type | Description |
|---|---|
TypeError
|
Conversion is not supported for the dataframe class. |
to_engineframe_pair
¶
to_engineframe_pair(other: StandardFrame) -> tuple[frame_types.PolarsFrame, frame_types.PolarsFrame]
Return compatible Polars frames, keeping both lazy when either is lazy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
StandardFrame
|
The second dataframe. |
required |
Returns:
| Type | Description |
|---|---|
tuple[PolarsFrame, PolarsFrame]
|
Two Polars dataframes with compatible evaluation modes. |
Raises:
| Type | Description |
|---|---|
TypeError
|
Either dataframe cannot be converted to the engine format. |
Dataframes and merge functions¶
merge_by_grain is the built-in Polars merge function. Provide a custom merge
function when the built-in behavior does not fit.
Compiled calls to the built-in merge include the target profile's declared
relation keys in key_columns, so lower-grain fragments join on shared keys
instead of becoming Cartesian products.
Polars dataframe merge functions.
merge_by_grain
¶
merge_by_grain(dataset: DataFrame | None, fragment: DataFrame, dataset_identifiers: Sequence[str], fragment_keys: Sequence[str] | None = None, *, key_columns: Sequence[str] = (), join_cardinality: str = 'm:m', broadcast_cardinality: str = 'm:m') -> DataFrame
Assemble a fragment into a dataset according to the keys each carries.
Fragments carrying the complete grain use a full join, preserving either observation scope. Carried relations use a left join, broadcasting over the dataset's scope; no keys uses a cross join. With no dataset, only a fragment carrying the complete dataset key set can initialize the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset
|
DataFrame | None
|
Accumulated dataset dataframe, or |
required |
fragment
|
DataFrame
|
Contribution dataframe. |
required |
dataset_identifiers
|
Sequence[str]
|
Columns identifying dataset rows at its grain. |
required |
fragment_keys
|
Sequence[str] | None
|
Keys carried by the contribution. If omitted, infer the matching grain and relation columns from the fragment schema at runtime. |
None
|
key_columns
|
Sequence[str]
|
Grain keys and declared relation columns. Present columns are retained and used to join lower-resolution fragments. |
()
|
join_cardinality
|
str
|
Cardinality constraint for full joins. |
'm:m'
|
broadcast_cardinality
|
str
|
Cardinality constraint for subset-key left joins. |
'm:m'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
The assembled dataframe. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Fragment keys are incompatible or broadcasting has no dataset. |