-
Notifications
You must be signed in to change notification settings - Fork 15
refactor: abstract CustomizableDataflow into pandas/polars subclasses #548
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
paddymul
wants to merge
2
commits into
main
Choose a base branch
from
refactor/abstract-dataflow
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 all commits
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,50 @@ | ||
| from typing import Tuple, Dict as TDict, Any as TAny | ||
|
|
||
| import pandas as pd | ||
| from typing_extensions import override | ||
|
|
||
| from buckaroo.pluggable_analysis_framework.col_analysis import SDType | ||
| from buckaroo.pluggable_analysis_framework.df_stats_v2 import DfStatsV2 | ||
| from ..serialization_utils import pd_to_obj | ||
| from .dataflow import CustomizableDataflow | ||
|
|
||
|
|
||
| class PandasCustomizableDataflow(CustomizableDataflow): | ||
| """Concrete pandas implementation of CustomizableDataflow.""" | ||
|
|
||
| DFStatsClass = DfStatsV2 | ||
|
|
||
| @override | ||
| def _compute_processed_result(self, cleaned_df, post_processing_method): | ||
| if post_processing_method == '': | ||
| return (cleaned_df, {}) | ||
| else: | ||
| post_analysis = self.post_processing_klasses[post_processing_method] | ||
| try: | ||
| ret_df, sd = post_analysis.post_process_df(cleaned_df) | ||
| return (ret_df, sd) | ||
| except Exception as e: | ||
| return (self._build_error_dataframe(e), {}) | ||
|
|
||
| @override | ||
| def _build_error_dataframe(self, e): | ||
| return pd.DataFrame({'err': [str(e)]}) | ||
|
|
||
| @override | ||
| def _get_summary_sd(self, processed_df) -> Tuple[SDType, TDict[str, TAny]]: | ||
| stats = self.DFStatsClass( | ||
| processed_df, | ||
| self.analysis_klasses, | ||
| self.df_name, debug=self.debug) | ||
| sdf = stats.sdf | ||
| if stats.errs: | ||
| if self.debug: | ||
| raise Exception("Error executing analysis") | ||
| else: | ||
| return {}, stats.errs | ||
| else: | ||
| return sdf, {} | ||
|
|
||
| @override | ||
| def _df_to_obj(self, df) -> TDict[str, TAny]: | ||
| return pd_to_obj(self.sampling_klass.serialize_sample(df)) |
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,53 @@ | ||
| from typing import Tuple, Dict as TDict, Any as TAny | ||
|
|
||
| import pandas as pd | ||
| import polars as pl | ||
| from typing_extensions import override | ||
|
|
||
| from buckaroo.pluggable_analysis_framework.col_analysis import SDType | ||
| from buckaroo.pluggable_analysis_framework.df_stats_v2 import PlDfStatsV2 | ||
| from ..serialization_utils import pd_to_obj | ||
| from .dataflow import CustomizableDataflow | ||
|
|
||
|
|
||
| class PolarsCustomizableDataflow(CustomizableDataflow): | ||
| """Concrete polars implementation of CustomizableDataflow.""" | ||
|
|
||
| DFStatsClass = PlDfStatsV2 | ||
|
|
||
| @override | ||
| def _compute_processed_result(self, cleaned_df, post_processing_method): | ||
| if post_processing_method == '': | ||
| return (cleaned_df, {}) | ||
| else: | ||
| post_analysis = self.post_processing_klasses[post_processing_method] | ||
| try: | ||
| ret_df, sd = post_analysis.post_process_df(cleaned_df) | ||
| return (ret_df, sd) | ||
| except Exception as e: | ||
| return (self._build_error_dataframe(e), {}) | ||
|
|
||
| @override | ||
| def _build_error_dataframe(self, e): | ||
| return pl.DataFrame({'err': [str(e)]}) | ||
|
|
||
| @override | ||
| def _get_summary_sd(self, processed_df) -> Tuple[SDType, TDict[str, TAny]]: | ||
| stats = self.DFStatsClass( | ||
| processed_df, | ||
| self.analysis_klasses, | ||
| self.df_name, debug=self.debug) | ||
| sdf = stats.sdf | ||
| if stats.errs: | ||
| if self.debug: | ||
| raise Exception("Error executing analysis") | ||
| else: | ||
| return {}, stats.errs | ||
| else: | ||
| return sdf, {} | ||
|
|
||
| @override | ||
| def _df_to_obj(self, df) -> TDict[str, TAny]: | ||
| if isinstance(df, pd.DataFrame): | ||
| return pd_to_obj(self.sampling_klass.serialize_sample(df)) | ||
| return pd_to_obj(self.sampling_klass.serialize_sample(df.to_pandas())) |
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.
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 refactor removed the
InnerDataFlow._df_to_objbridge, so_df_to_objimplementations on widget subclasses are no longer used during serialization. That breaks built-in override paths likeGeopandasBase._df_to_obj(buckaroo/geopandas_buckaroo.py), which exists to coerce geopandas frames beforepd_to_obj; after this change, serialization falls back toPandasCustomizableDataflow._df_to_objand bypasses that conversion, causing geopandas widget payload generation to fail or produce incorrect data.Useful? React with 👍 / 👎.