Skip to content

Conversation

@samhuestis
Copy link
Collaborator

Changed services to validate each row when reading in csv against mtcar model. Updated routers as list of mtcars now being passed to the router rather than a json object (fast api will encode the list into json). Created new test to validate that each item in the list at api/dataset is valid mtcar item.

Copy link
Collaborator

@jdhoffa jdhoffa left a comment

Choose a reason for hiding this comment

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

Reviewed and tested locally, looks and works great!
Thanks @samhuestis

Comment on lines +13 to +19
try:
# replaces the space in the model of each row, so it will be a valid url later
row["model"] = row["model"].replace(" ", "")
# validates row of csv against mtcar model
validated_row = mtcar.model_validate(row)
# dumps individual validated "mtcar" into list mtcars_data
mtcars_data.append(validated_row.model_dump())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm happy to merge this as-is, but it would be interesting to see what the performance trade-offs are with validating each row on read.

Something to look into in the future

mtcars[key] = row
return mtcars
# Function to read in csv, validate using mtcar model and output mtcars data in JSON
def csv_to_dict(mtcars_path):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given that this function is no longer a generalized csv_to_dict function, but now very precisely an mtcars_vsc_to_dict() function (given it validates the input against the mtcars pydantic model) , I would suggest renaming the function to be more accurate.

@jdhoffa jdhoffa self-requested a review February 27, 2025 09:25
Copy link
Collaborator

@jdhoffa jdhoffa left a comment

Choose a reason for hiding this comment

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

A few minor changes, then looks good!

@jdhoffa jdhoffa merged commit 819abaf into main Feb 27, 2025
2 checks passed
@jdhoffa jdhoffa deleted the mtcars_services_fix branch February 27, 2025 10:10
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.

3 participants