-
Notifications
You must be signed in to change notification settings - Fork 1
Mtcars services fix #23
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
Conversation
…ing into services, attempted to add new model for whole mtcars dataset but that still wont pass integration test
…coding from services as it was not needed with new method, removed mtcarlist data model
removed extra newline
jdhoffa
left a comment
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.
Reviewed and tested locally, looks and works great!
Thanks @samhuestis
| 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()) |
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.
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
src/services/mtcars.py
Outdated
| 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): |
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.
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
left a comment
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.
A few minor changes, then looks good!
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.