-
Notifications
You must be signed in to change notification settings - Fork 18
ENH: Refactor server handling #155
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4da0740
move data handling to handler
isabelizimm 053289d
singledispatch _prepare_data
isabelizimm 25baff1
refactor tests for api
isabelizimm 000f017
expect a list of prototypes if checking prototype
isabelizimm 22d88cd
http and validation error handlers
isabelizimm a8472df
pretty plaintext errors
isabelizimm c2b7f8b
use helpers to convert api data to frame
isabelizimm 0dbcf40
parameterize sklearn tests
isabelizimm 8f686e5
remove tolist from API
isabelizimm 2e99db2
move api_data_to_frame to server
isabelizimm 5f28f61
add response_to_frame function
isabelizimm e134efa
import RSConnectServer as courtesy
isabelizimm 4e8ef02
Merge branch 'main' into server-refactor
isabelizimm 60d07f5
requests requires data, not content
isabelizimm f509f16
better docs for response_to_frame
isabelizimm 0495c31
clean up comments
isabelizimm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| from functools import singledispatch | ||
| import pandas as pd | ||
| import pydantic | ||
|
|
||
|
|
||
| @singledispatch | ||
| def api_data_to_frame(pred_data) -> pd.DataFrame: | ||
| """Convert prototype to dataframe data | ||
|
|
||
| Parameters | ||
| ---------- | ||
| pred_data : pydantic.BaseModel | ||
| User data from given to API endpoint | ||
|
|
||
| Returns | ||
| ------- | ||
| pd.DataFrame | ||
| BaseModel data translated into DataFrame | ||
| """ | ||
|
|
||
| raise TypeError("Data should be list, pydantic.BaseModel, pd.DataFrame") | ||
|
|
||
|
|
||
| @api_data_to_frame.register(pydantic.BaseModel) | ||
| @api_data_to_frame.register(list) | ||
| def _(pred_data): | ||
|
|
||
| return pd.DataFrame([dict(s) for s in pred_data]) | ||
|
|
||
|
|
||
| @api_data_to_frame.register(dict) | ||
| def _dict(pred_data): | ||
| return api_data_to_frame([pred_data]) | ||
|
|
||
|
|
||
| def response_to_frame(response: dict) -> pd.DataFrame: | ||
| """Convert API JSON response to data frame | ||
|
|
||
| Parameters | ||
| ---------- | ||
| response : dict | ||
| Response from API endpoint | ||
|
|
||
| Returns | ||
| ------- | ||
| pd.DataFrame | ||
| Response translated into DataFrame | ||
| """ | ||
| response_df = pd.DataFrame.from_dict(response.json()) | ||
|
|
||
| return response_df |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think this (or immediately after this PR) is the good time to add a module
docstringfor all the whats and the whys aboutHandlers. I will do a PR after this one.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.
Awesome! That would be a great addition for more context on Handlers.