Skip to content

Conversation

kdvalin
Copy link
Member

@kdvalin kdvalin commented Aug 20, 2025

Description

This PR adds 2 scripts csv_to_json and verify_results

csv_to_json converts CSV files to JSON files using python's csvkit module

verify_results imports a pydantic model dynamically and then verifies wheter a passed JSON file matches the schema provided.

Before/After Comparison

Before

We were using regular expressions to try and validate results, which are error-prone, fragile, and annoying to maintain

After

we use pydantic models to easily say "this field is greater than 0, and is a floating point number"

Clerical Stuff

Issue TBD

Relates to JIRA: RPOPC-<TICKET_NUMBER>

This adds a script `csv_to_json` which is essentially a wrapper for
`csvjson` found in the python3-csvkit package.  This is the first step
for JSON results in Zathras, but for now this is intended to convert the
current CSV files to a results JSON (metadata is stripped) so we can
easily verify those results.

Co-developed-by: Cursor
This adds `verify_results` which uses the pydantic python module to
verify if results match certain constraints, akin to JSON schemas.  This
script dynamically imports a passed script and a passed class then
verifies if the JSON file/input matches.

Co-developed-by: Cursor
This adds `--verify_skip` and `--json_skip` which skips the verification
step and json conversion step respectively.  This is placed inside of
general_setup so the scripts can simply pass $to_json_flags and
$to_verify_flags to avoid having to manage an ever-growing pile of flags
in the future.

Co-developed-by: Cursor
This adds `$to_script_dir` so it is easy for running scripts to fetch
the directory that the script lives in.  This will make verification
scripts a lot easier to manage.

Co-developed-by: Cursor
Previously the `verify_results` script could not handle absolute paths
causing import errors and validation to fail.  This changes the import logic so
we can import a file from anywhere on a system and load the relevant
class we need.

Co-developed-by: Cursor
@kdvalin
Copy link
Member Author

kdvalin commented Aug 25, 2025

Bug: csvjson casts ints to floats.

Previously we used csvkit to convert the csv files to JSON, but csvkit
does not keep integer fields as integers.  It will convert integers to
floats, which will fail validation processes.  The change to pandas will
respect data types.

Co-developed-by: Cursor
…ers into feat/result-verify

Co-developed-by: Cursor
Change args.output to args.output_file, since I updated the arg at
one point and forgot to do it everywhere else, d'oh

Co-developed-by: Cursor
This lets pandas know that a line starting with a # is a comment and
should be ignored.

Co-developed-by: Cursor
This commit introduces the ability for verify_results and csv_to_json to
install their needed dependencies if it is not available on the system.
csv_to_json installs pandas, verify_results installs pydantic

Co-developed-by: Cursor
This simplifies the default arguments so argparse takes care of opening
the files with the needed modes, and when the default is stdout/stdin no
other logic needs to be done to swap between file and console IO.

Co-developed-by: Cursor
@kdvalin
Copy link
Member Author

kdvalin commented Aug 27, 2025

Converted to using pandas instead of csvkit

@kdvalin kdvalin marked this pull request as ready for review August 27, 2025 15:51
@kdvalin kdvalin requested a review from a team September 2, 2025 12:22
@@ -200,6 +202,14 @@ do
--usage)
gs_usage_info
;;
--verify_skip)
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to update the usage.

Change --schema_file type to a str, since we never directly read from
the file (this is handled by importlib), and the necessary errors are
already handled.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants