Skip to content

fix: use elif in _write_data_file and _read_data_file to avoid redundant checks#570

Open
31groot wants to merge 2 commits into
kubeedge:mainfrom
31groot:fix/dataset-elif-chains
Open

fix: use elif in _write_data_file and _read_data_file to avoid redundant checks#570
31groot wants to merge 2 commits into
kubeedge:mainfrom
31groot:fix/dataset-elif-chains

Conversation

@31groot

@31groot 31groot commented Jul 1, 2026

Copy link
Copy Markdown

What type of PR is this?
/kind cleanup

What this PR does / why we need it:
_write_data_file and _read_data_file in dataset.py used sequential
if statements for mutually exclusive data_format checks. Since
data_format can only match one value at a time, the second if block
was always evaluated unnecessarily. Changed to elif to make the intent
explicit and avoid redundant condition checks.

Which issue(s) this PR fixes:
Fixes #563

…ant checks

Signed-off-by: Parv Agrawal <agrawalparv13@gmail.com>
@kubeedge-bot kubeedge-bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Jul 1, 2026
@kubeedge-bot kubeedge-bot requested review from Poorunga and hsj576 July 1, 2026 21:39
@kubeedge-bot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 31groot
To complete the pull request process, please assign jaypume after the PR has been reviewed.
You can assign the PR to them by writing /assign @jaypume in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeedge-bot kubeedge-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Jul 1, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the dataset helper methods _write_data_file and _read_data_file in core/testenvmanager/dataset/dataset.py to use elif instead of sequential if statements when checking for the CSV data format. The reviewer recommends adding else blocks to both methods to raise a ValueError for unsupported data formats, which prevents silent failures and improves error handling.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +276 to 277
elif data_format == DatasetFormat.CSV.value:
data.to_csv(data_file, index=None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While changing the sequential if to elif is a good step, if data_format is an unsupported format (such as JSON or JSONFORLLM), this method will silently do nothing. It is safer to add an else block that raises a ValueError to prevent silent failures and make debugging easier.

Suggested change
elif data_format == DatasetFormat.CSV.value:
data.to_csv(data_file, index=None)
elif data_format == DatasetFormat.CSV.value:
data.to_csv(data_file, index=None)
else:
raise ValueError(f"Unsupported data format for writing: {data_format}")

Comment on lines +287 to 288
elif data_format == DatasetFormat.CSV.value:
data = pd.read_csv(data_file)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similarly, if data_format is unsupported, this method will silently return None, which will lead to downstream errors like TypeError when other methods attempt to process the returned data. Adding an else block to raise a ValueError provides defensive programming and clearer error messages.

Suggested change
elif data_format == DatasetFormat.CSV.value:
data = pd.read_csv(data_file)
elif data_format == DatasetFormat.CSV.value:
data = pd.read_csv(data_file)
else:
raise ValueError(f"Unsupported data format for reading: {data_format}")

…e data file

Signed-off-by: Parv Agrawal <agrawalparv13@gmail.com>
@31groot 31groot force-pushed the fix/dataset-elif-chains branch from 48d2caa to 200a61c Compare July 3, 2026 19:56
@31groot

31groot commented Jul 3, 2026

Copy link
Copy Markdown
Author

/assign @jaypume

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Core setup failures on fresh install: API rename, missing class, wrong docs path, undocumented deps

3 participants