Skip to content

Strip .json extension from CSV filenames in json2csv (Fixes #1679)#1967

Merged
nfahlgren merged 2 commits into
danforthcenter:mainfrom
Mohit-Ak:fix/json2csv-strip-json-ext
Jul 10, 2026
Merged

Strip .json extension from CSV filenames in json2csv (Fixes #1679)#1967
nfahlgren merged 2 commits into
danforthcenter:mainfrom
Mohit-Ak:fix/json2csv-strip-json-ext

Conversation

@Mohit-Ak

@Mohit-Ak Mohit-Ak commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Problem

Fixes #1679.

When running plantcv-run-workflow, the CSV files it generates from the JSON
results keep the .json extension embedded in their names. For example, with a
config pointing at ./results/output_control.json, the workflow writes:

output_control.json-single-value-traits.csv
output_control.json-multi-value-traits.csv

instead of the expected output_control-single-value-traits.csv.

Root cause

In plantcv/parallel/cli.py, the JSON results filename is passed directly as the
CSV prefix:

plantcv.utils.json2csv(config.json, config.json)

json2csv then builds its outputs as csv_prefix + "-single-value-traits.csv",
so the .json extension ends up glued in front of the -single-value-traits.csv
suffix. Anyone calling json2csv directly with a .json-suffixed prefix hits the
same thing.

Fix

Strip a trailing .json extension from csv_prefix inside json2csv before the
output filenames are assembled. Doing it in json2csv covers both the automatic
workflow call and any direct call, so the whole bug class is handled in one place
rather than only patching the single reported call site.

if csv_prefix.endswith(".json"):
    csv_prefix = csv_prefix[:-len(".json")]

Testing

Added a regression test, test_json2csv_json_prefix, that calls json2csv with a
.json-suffixed prefix and asserts the output is exports-single-value-traits.csv
and not exports.json-single-value-traits.csv.

  • The new test fails before the fix (writes exports.json-single-value-traits.csv)
    and passes after it.
  • pytest tests/utils/ — 17 passed.
  • pytest tests/parallel/ — 37 passed (this exercises the run-workflow
    json2csv path).
  • flake8 --max-line-length=127 (the repo's configured limit from
    .deepsource.toml) is clean on both changed files.

When plantcv-run-workflow converts results to CSV it reuses the JSON
results filename as the CSV prefix, producing filenames like
output_control.json-single-value-traits.csv. Strip a trailing .json
extension from the prefix so the output is output_control-single-value-traits.csv.

Fixes danforthcenter#1679
@deepsource-io

deepsource-io Bot commented Jul 8, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 1f40fae...e892786 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Python Jul 10, 2026 5:02p.m. Review ↗
Code coverage Jul 10, 2026 5:32p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@Mohit-Ak Mohit-Ak marked this pull request as ready for review July 8, 2026 13:22
@nfahlgren nfahlgren added cleanup Code quality updates ready to review labels Jul 10, 2026
@nfahlgren nfahlgren added this to the PlantCV v4.12 milestone Jul 10, 2026
@github-project-automation github-project-automation Bot moved this to Pull Requests in PlantCV4 Jul 10, 2026
@nfahlgren nfahlgren merged commit 77e3322 into danforthcenter:main Jul 10, 2026
4 of 5 checks passed
@github-project-automation github-project-automation Bot moved this from Pull Requests to Done in PlantCV4 Jul 10, 2026
@nfahlgren

Copy link
Copy Markdown
Member

@all-contributors please add @Mohit-Ak for code, testing

@allcontributors

Copy link
Copy Markdown
Contributor

@nfahlgren

I've put up a pull request to add @Mohit-Ak! 🎉

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

Labels

cleanup Code quality updates ready to review

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

remove .json extension from filename on automatic conversion to csv when running plantcv-run-workflow

2 participants