-
Notifications
You must be signed in to change notification settings - Fork 835
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
Update microservice.R #2239
Update microservice.R #2239
Conversation
Input data type persistence and null value persistence
Hi @LueJian. Thanks for your PR. I'm waiting for a SeldonIO member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the jenkins-x/lighthouse repository. |
/ok-to-test |
@LueJian Thanks for this! This is great. It would be great to provide some better examples of real R use cases in the docs in a future PR. |
Tue Aug 4 06:31:11 UTC 2020 impatient try |
Tue Aug 4 06:31:16 UTC 2020 impatient try |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cliveseldon The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Input data type persistence and null value persistence.
What this PR does / why we need it:
Input data type persistence
In all endpoint functions, if there are character and numeric value in input data simultaneously, the default of
fromJSON(json)
always convert numeric value to character type, therefore, the data type of columns in dataframe will be wrong aftercreate_dataframe(jdf)
.if the input data is like that:
json={"data":{"name":["col_must_be_char", "col_must_be_num"], "ndarray":[["A",12],[ "B",20]]}}
the data schema after
fromJSON(json)
now:the data schema after
create_dataframe(jdf)
now:expect data schema after
create_dataframe(jdf)
:The reason is that the outcome of
fromJSON(json)
will be "matrix" class, but the matrix in R only been allowed one data type at the same time. By adding an argumentsimplifyVector = False
tofromJSON(json)
can avoid that because the outcome offromJSON(json, simplifyVector = False)
will be "list" class:Then we should add
rbind()
andlappy()
intocreate_dataframe()
to combine those list value and add an argumentstringsAsFactors = False
indata.frame()
to avoid character data type transform to Factor automatically, because it always transform string to Factor usingdata.frame()
by default in R. Therefore, we can get expect dataframe schema:Convert input NULL value to NA
In general, we always express missing value by
""
(string) andnull
(numeric). If we edit the script like demonstrate above, the null value (numeric missing value) will be convert to"NULL"
afterfromJSON(json, simplifyVectors=False)
originally, so we have to adddf[df == "NULL"] <- NA
increate_dataframe()
to replace NULL by NA.if the input data is like that: (with null)
json={"data":{"name":["col_must_be_char", "col_must_be_num"], "ndarray":[["A",12],[ "",null]]}}
the outcome of
fromJSON(json, simplifyVectors=False)
andcreate_dataframe()
without replace NULL by NA:the outcome of
fromJSON(json, simplifyVectors=False)
andcreate_dataframe()
with replace NULL by NA:Convert response NA value to null
Like descriptions above, in general, we always express missing value by
""
(string) andnull
(numeric), so we have to add an argumentna = null
to thetoJSON()
function increate_response()
, then the NA in output will be null.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: