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
fix: make TablesClient.predict permissive to input data types #13
Conversation
The current implementation checks input instance's data type according to column spec's data type. E.g., if the column spec is float, it requires the input to be float or int, but not string. However, this is not the same as tables API contract: float column data type could be string or number values. The current code raises exception with error messages like TypeError: '0' has type str, but expected one of: int, long, float when passed in a string value for numeric columns, which should be allowed. This PR changes the logic so that Python SDK side will be permissive for the input data type - basically all JSON compatible data types are allow. And rely on backend for the validation.
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.
lgtm
# This check needs to happen before isinstance(value, int), | ||
# isinstance(value, int) returns True when value is bool. | ||
return struct_pb2.Value(bool_value=value), None | ||
if isinstance(value, six.integer_types) or isinstance(value, float): |
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.
if or elif should work for all of these?
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.
Sorry I don't quite understand, do you mean if these if-elif statements (from line 55 to 85) covers all supported data types? Yes.
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.
sorry poor communication. just an observation, on this line, you started a new if clause. this if can be elif OR all of the elif can be if. no change necessary.
@busunkim96 could you take a look? Thanks! |
🤖 I have created a release \*beep\* \*boop\* --- ## [1.0.0](https://www.github.com/googleapis/python-automl/compare/v0.10.0...v1.0.0) (2020-06-18) ### Features * release as production/stable ([#37](https://www.github.com/googleapis/python-automl/issues/37)) ([915c502](https://www.github.com/googleapis/python-automl/commit/915c5029a8c342871738b24395534fdaebb681bc)) ### Bug Fixes * make TablesClient.predict permissive to input data types ([#13](https://www.github.com/googleapis/python-automl/issues/13)) ([ddc9f71](https://www.github.com/googleapis/python-automl/commit/ddc9f7106eab91d4adea2db65e69e3a870a7cd46)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please).
The current implementation checks input instance's data type according
to column spec's data type. E.g., if the column spec is float, it
requires the input to be float or int, but not string. However, this
is not the same as tables API contract:
The current code raises exception with error messages like
This PR changes the logic so that Python SDK side will be permissive
for the input data type - basically all JSON compatible data types are
allow. And rely on backend for the validation.