-
Notifications
You must be signed in to change notification settings - Fork 310
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
[wip] Pandas Dataframe in Dataclass #3116
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Future-Outlier <[email protected]>
Code Review Agent Run #fedbf7Actionable Suggestions - 2
Review Details
|
Changelist by BitoThis pull request implements the following key changes.
|
import pandas as pd | ||
if isinstance(python_val, pd.DataFrame): | ||
python_val = StructuredDataset(dataframe=python_val, file_format="parquet") |
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.
Consider moving the pandas DataFrame conversion logic to a dedicated transformer class instead of handling it in the _make_dataclass_serializable
method. This would improve code organization and maintainability.
Code suggestion
Check the AI-generated fix before applying
import pandas as pd | |
if isinstance(python_val, pd.DataFrame): | |
python_val = StructuredDataset(dataframe=python_val, file_format="parquet") |
Code Review Run #fedbf7
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
decoder = JSONDecoder(new_expected_python_type) | ||
self._json_decoder[new_expected_python_type] = decoder |
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.
Consider storing the decoder in the original expected_python_type
key instead of new_expected_python_type
to avoid potential memory leaks from storing multiple decoders for the same logical type.
Code suggestion
Check the AI-generated fix before applying
decoder = JSONDecoder(new_expected_python_type) | |
self._json_decoder[new_expected_python_type] = decoder | |
decoder = JSONDecoder(new_expected_python_type) | |
self._json_decoder[expected_python_type] = decoder |
Code Review Run #fedbf7
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
Signed-off-by: Future-Outlier <[email protected]>
Code Review Agent Run #6cea0dActionable Suggestions - 0Review Details
|
Signed-off-by: Future-Outlier <[email protected]>
Code Review Agent Run #b16268Actionable Suggestions - 2
Review Details
|
from flytekit.types.structured.structured_dataset import StructuredDataset | ||
from typing import get_type_hints, Type, Dict | ||
|
||
def convert_dataclass(instance, target_cls): |
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.
The convert_dataclass
function could benefit from type hints for better code maintainability and IDE support. Consider adding type annotations for instance
and target_cls
parameters.
Code suggestion
Check the AI-generated fix before applying
def convert_dataclass(instance, target_cls): | |
def convert_dataclass(instance: Any, target_cls: Type[T]) -> T: |
Code Review Run #b16268
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
|
||
dc = decoder.decode(json_str) | ||
|
||
return self._fix_dataclass_int(expected_python_type, dc) | ||
return convert_dataclass(self._fix_dataclass_int(new_expected_python_type, dc), expected_python_type) |
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.
The conversion from new_expected_python_type
to expected_python_type
may lose data if the types have different field structures. Consider validating field compatibility before conversion.
Code suggestion
Check the AI-generated fix before applying
return convert_dataclass(self._fix_dataclass_int(new_expected_python_type, dc), expected_python_type) | |
fixed_dc = self._fix_dataclass_int(new_expected_python_type, dc) | |
# Validate field compatibility | |
if not all(f.name in [ef.name for ef in fields(expected_python_type)] for f in fields(fixed_dc.__class__)): | |
raise ValueError(f"Incompatible field structure between {new_expected_python_type.__name__} and {expected_python_type.__name__}") | |
return convert_dataclass(fixed_dc, expected_python_type) |
Code Review Run #b16268
Is this a valid issue, or was it incorrectly flagged by the Agent?
- it was incorrectly flagged
Tracking issue
Why are the changes needed?
we want to improve UX.
What changes were proposed in this pull request?
How was this patch tested?
Setup process
Screenshots
Check all the applicable boxes
Related PRs
Docs link
Summary by Bito
This PR implements automatic Pandas DataFrame to StructuredDataset conversion within dataclass structures, with recursive transformation capabilities and encoding/decoding support. The DataclassTransformer in flytekit's type engine is enhanced to handle nested dataclass conversions and improved Pandas DataFrame handling through a convert_dataclass helper function. The update includes improvements to JSON decoding in binary_to_python method while removing debug-related print statements and improving documentation for dataclass case handling.Unit tests added: False
Estimated effort to review (1-5, lower is better): 2