Skip to content
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

Merged
merged 1 commit into from
Aug 4, 2020
Merged

Update microservice.R #2239

merged 1 commit into from
Aug 4, 2020

Conversation

LueJian
Copy link
Contributor

@LueJian LueJian commented Aug 4, 2020

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 after create_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:
image

the data schema after create_dataframe(jdf) now:
image

expect data schema after create_dataframe(jdf):
image

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 argument simplifyVector = False to fromJSON(json) can avoid that because the outcome of fromJSON(json, simplifyVector = False) will be "list" class:
image

Then we should add rbind() and lappy() into create_dataframe() to combine those list value and add an argument stringsAsFactors = False in data.frame() to avoid character data type transform to Factor automatically, because it always transform string to Factor using data.frame() by default in R. Therefore, we can get expect dataframe schema:
image

Convert input NULL value to NA

In general, we always express missing value by "" (string) and null (numeric). If we edit the script like demonstrate above, the null value (numeric missing value) will be convert to "NULL" after fromJSON(json, simplifyVectors=False) originally, so we have to add df[df == "NULL"] <- NA in create_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) and create_dataframe() without replace NULL by NA:
image
image

the outcome of fromJSON(json, simplifyVectors=False) and create_dataframe() with replace NULL by NA:
image

Convert response NA value to null

Like descriptions above, in general, we always express missing value by "" (string) and null (numeric), so we have to add an argument na = null to the toJSON() function in create_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?:

Input data type persistence and null value persistence
@seldondev
Copy link
Collaborator

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@LueJian LueJian changed the title Update microsercice.R Update microservice.R Aug 4, 2020
@ukclivecox
Copy link
Contributor

/ok-to-test

@ukclivecox
Copy link
Contributor

@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.

@seldondev
Copy link
Collaborator

Tue Aug 4 06:31:11 UTC 2020
The logs for [lint] [2] will show after the pipeline context has finished.
https://github.com/SeldonIO/seldon-core/blob/gh-pages/jenkins-x/logs/SeldonIO/seldon-core/PR-2239/2.log

impatient try
jx get build logs SeldonIO/seldon-core/PR-2239 --build=2

@seldondev
Copy link
Collaborator

Tue Aug 4 06:31:16 UTC 2020
The logs for [pr-build] [1] will show after the pipeline context has finished.
https://github.com/SeldonIO/seldon-core/blob/gh-pages/jenkins-x/logs/SeldonIO/seldon-core/PR-2239/1.log

impatient try
jx get build logs SeldonIO/seldon-core/PR-2239 --build=1

@ukclivecox
Copy link
Contributor

/approve

@seldondev
Copy link
Collaborator

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@seldondev seldondev merged commit d581969 into SeldonIO:master Aug 4, 2020
@LueJian LueJian deleted the patch-1 branch August 4, 2020 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants