-
Notifications
You must be signed in to change notification settings - Fork 1
assemble support for pandas #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daiwaid
wants to merge
2
commits into
main
Choose a base branch
from
feat-pandas
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from llmint.assemble.pandas.function import assemble |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import pandas as pd | ||
|
|
||
| from llmint.assemble.pandas.transform import ( | ||
| add, cast, copy, default, delete, missing, rename, apply, link, scale, shift | ||
| ) | ||
| from llmint.map.function import Map | ||
|
|
||
| def assemble(df: pd.DataFrame, mappings: list[Map]): | ||
| df_outputs = [] | ||
|
|
||
| for mapping in mappings: | ||
| match mapping.transformation.split(' ')[0]: | ||
| case 'ADD': | ||
| df_outputs.append(add(df, mapping)) | ||
| case 'CAST': | ||
| df_outputs.append(cast(df, mapping)) | ||
| case 'COPY': | ||
| df_outputs.append(copy(df, mapping)) | ||
| case 'DEFAULT': | ||
| df_outputs.append(default(df, mapping)) | ||
| case 'DELETE': | ||
| df_outputs.append(delete(df, mapping)) | ||
| case 'MISSING': | ||
| df_outputs.append(missing(df, mapping)) | ||
| case 'RENAME': | ||
| df_outputs.append(rename(df, mapping)) | ||
| case 'APPLY': | ||
| df_outputs.append(apply(df, mapping)) | ||
| case 'LINK': | ||
| df_outputs.append(link(df, mapping)) | ||
| case 'SCALE': | ||
| df_outputs.append(scale(df, mapping)) | ||
| case 'SHIFT': | ||
| df_outputs.append(shift(df, mapping)) | ||
|
|
||
| return pd.concat(df_outputs, axis=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| from llmint.assemble.pandas.transform.field.add import func as add | ||
| from llmint.assemble.pandas.transform.field.cast import func as cast | ||
| from llmint.assemble.pandas.transform.field.copy import func as copy | ||
| from llmint.assemble.pandas.transform.field.default import func as default | ||
| from llmint.assemble.pandas.transform.field.delete import func as delete | ||
| from llmint.assemble.pandas.transform.field.missing import func as missing | ||
| from llmint.assemble.pandas.transform.field.rename import func as rename | ||
|
|
||
| from llmint.assemble.pandas.transform.value.apply import func as apply | ||
| from llmint.assemble.pandas.transform.value.link import func as link | ||
| from llmint.assemble.pandas.transform.value.scale import func as scale | ||
| from llmint.assemble.pandas.transform.value.shift import func as shift |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import re | ||
| from pandas import Series, DataFrame | ||
|
|
||
| from llmint.map.function import Map | ||
|
|
||
|
|
||
| def func(df: DataFrame, mapping: Map): | ||
| col_type = re.search(r'TYPE (\w+)', mapping.transformation).group(1) | ||
|
|
||
| return Series([], name=mapping.target_field, dtype=col_type) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from pandas import Series, DataFrame | ||
|
|
||
| from llmint.map.function import Map | ||
|
|
||
|
|
||
| def func(df: DataFrame, mapping: Map): | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import re | ||
| from pandas import Series, DataFrame | ||
|
|
||
| from llmint.map.function import Map | ||
|
|
||
|
|
||
| def func(df: DataFrame, mapping: Map): | ||
| return Series(df[mapping.source_field], name=mapping.target_field) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import re | ||
| from pandas import Series, DataFrame | ||
|
|
||
| from llmint.map.function import Map | ||
|
|
||
|
|
||
| def func(df: DataFrame, mapping: Map): | ||
| default_val = re.search(r'DEFAULT TO (.*)', mapping.transformation).group(1) | ||
|
|
||
| return Series([default_val] * len(df), name=mapping.target_field) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from pandas import Series, DataFrame | ||
|
|
||
| from llmint.map.function import Map | ||
|
|
||
|
|
||
| def func(df: DataFrame, mapping: Map): | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from pandas import Series, DataFrame | ||
|
|
||
| from llmint.map.function import Map | ||
|
|
||
|
|
||
| def func(df: DataFrame, mapping: Map): | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from pandas import Series, DataFrame | ||
|
|
||
| from llmint.map.function import Map | ||
|
|
||
|
|
||
| def func(df: DataFrame, mapping: Map): | ||
| pass |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import re | ||
| from pandas import Series, DataFrame | ||
|
|
||
| from llmint.map.function import Map | ||
|
|
||
|
|
||
| def func(df: DataFrame, mapping: Map): | ||
| apply_func = re.search(r'APPLY (.*)', mapping.transformation).group(1) | ||
|
|
||
| # assign all columns to their own variables | ||
| for col in df.columns: | ||
| exec(f'{col.replace(" ", "_")} = df[col]', locals(), globals()) | ||
|
|
||
| exec(f'_output = {apply_func}', locals(), globals()) | ||
|
|
||
| return Series(_output, name=mapping.target_field) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from pandas import Series, DataFrame | ||
|
|
||
| from llmint.map.function import Map | ||
|
|
||
|
|
||
| def func(df: DataFrame, mapping: Map): | ||
| pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import re | ||
| from pandas import Series, DataFrame | ||
|
|
||
| from llmint.map.function import Map | ||
|
|
||
|
|
||
| def func(df: DataFrame, mapping: Map): | ||
| try: | ||
| scale = float(re.search(r'SCALE BY (\d*.\d*)', mapping.transformation).group(1)) | ||
| except ValueError: | ||
| return df[mapping.source_field].copy() | ||
|
|
||
| return df[mapping.source_field] * scale |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import re | ||
| from pandas import Series, DataFrame | ||
|
|
||
| from llmint.map.function import Map | ||
|
|
||
|
|
||
| def func(df: DataFrame, mapping: Map): | ||
| try: | ||
| shift = float(re.search(r'SHIFT BY (\d*.\d*)', mapping.transformation).group(1)) | ||
| except ValueError: | ||
| return df[mapping.source_field].copy() | ||
|
|
||
| return df[mapping.source_field] + shift |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very neat / nice example for schema alignment for static datasets (known records with fixed size).
Could we have perhaps another example demonstrating this in the message broker setting?
E.g., having a continuous sending data source and the assembled data flow - once "in stalled" to the data path - able to process incoming data.