Concatenation rules
Concatenation rules¶
Rules to concatenate two dataframes vertically (rows) or horizontally (columns).
Importing the rules
The rules are implemented by each backend. Import them from the package of the backend you use, e.g.
from etlrules.backends.pandas import VConcatRule (or etlrules.backends.polars, etlrules.backends.dask, etlrules.backends.pyarrow).
The arguments and the behaviour are the same in all the backends, unless stated otherwise.
VConcatRule ¶
Vertically concatenates two dataframe with the result having the rows from the left dataframe followed by the rows from the right dataframe.
The rows of the right dataframe are added at the bottom of the rows from the left dataframe in the result dataframe.
Example:
1 2 3 4 5 6 7 8 9 10 11 | |
After a concat(left, right), the result will look like:
1 2 3 4 5 6 7 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
named_input_left
|
Optional[str]
|
Which dataframe to use as the input on the left side of the join. When set to None, the input is taken from the main output of the previous rule. Set it to a string value, the name of an output dataframe of a previous rule. |
required |
named_input_right
|
Optional[str]
|
Which dataframe to use as the input on the right side of the join. When set to None, the input is taken from the main output of the previous rule. Set it to a string value, the name of an output dataframe of a previous rule. |
required |
subset_columns
|
Optional[Iterable[str]]
|
A subset list of columns available in both dataframes. Only these columns will be concated. The effect is similar to doing a ProjectRule(subset_columns) on both dataframes before the concat. |
None
|
named_output
|
Optional[str]
|
Give the output of this rule a name so it can be used by another rule as a named input. Optional. When not set, the result of this rule will be available as the main output. When set to a name (string), the result will be available as that named output. |
None
|
name
|
Optional[str]
|
Give the rule a name. Optional. Named rules are more descriptive as to what they're trying to do/the intent. |
None
|
description
|
Optional[str]
|
Describe in detail what the rules does, how it does it. Optional. Together with the name, the description acts as the documentation of the rule. |
None
|
strict
|
bool
|
When set to True, the rule does a stricter valiation. Default: True |
True
|
Raises:
| Type | Description |
|---|---|
MissingColumnError
|
raised if any subset columns specified are missing from any of the dataframe. |
SchemaError
|
raised in strict mode only if the columns differ between the two dataframes and subset_columns is not specified. |
Note
In strict mode, as described above, SchemaError is raised if the columns are not the same (names, types can be inferred). In non-strict mode, columns are not checked and values are filled with NA when missing.
HConcatRule ¶
Horizontally concatenates two dataframe with the result having the columns from the left dataframe followed by the columns from the right dataframe.
The columns from the left dataframe will be followed by the columns from the right dataframe in the result dataframe. The two dataframes must not have columns with the same name.
Example:
1 2 3 4 5 6 7 8 9 10 11 | |
After a concat(left, right), the result will look like:
1 2 3 4 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
named_input_left
|
Optional[str]
|
Which dataframe to use as the input on the left side of the join. When set to None, the input is taken from the main output of the previous rule. Set it to a string value, the name of an output dataframe of a previous rule. |
required |
named_input_right
|
Optional[str]
|
Which dataframe to use as the input on the right side of the join. When set to None, the input is taken from the main output of the previous rule. Set it to a string value, the name of an output dataframe of a previous rule. |
required |
named_output
|
Optional[str]
|
Give the output of this rule a name so it can be used by another rule as a named input. Optional. When not set, the result of this rule will be available as the main output. When set to a name (string), the result will be available as that named output. |
None
|
name
|
Optional[str]
|
Give the rule a name. Optional. Named rules are more descriptive as to what they're trying to do/the intent. |
None
|
description
|
Optional[str]
|
Describe in detail what the rules does, how it does it. Optional. Together with the name, the description acts as the documentation of the rule. |
None
|
strict
|
bool
|
When set to True, the rule does a stricter valiation. Default: True |
True
|
Raises:
| Type | Description |
|---|---|
ColumnAlreadyExistsError
|
raised if the two dataframes have columns with the same name. |
SchemaError
|
raised in strict mode only if the two dataframes have different number of rows. |