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

[SPARK-13647][SQL] also check if numeric value is within allowed range in _verify_type #11492

Closed
wants to merge 2 commits into from

Conversation

cloud-fan
Copy link
Contributor

What changes were proposed in this pull request?

This PR makes the _verify_type in types.py more strict, also check if numeric value is within allowed range.

How was this patch tested?

newly added doc test.

@SparkQA
Copy link

SparkQA commented Mar 3, 2016

Test build #52391 has finished for PR 11492 at commit 23222b6.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

from struct import pack, unpack

if not isinf(obj):
f = unpack("f", pack("f", obj))[0]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I try to convert the obj to binary string as a float32, and then convert it back. If it becomes an inf, then it means the obj can not fit in float32.

Is there a better way to check if a python float can fit in float32?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried that this will be super slow, I think we don't need this.

If overflow happens, it will become infinity.

@cloud-fan
Copy link
Contributor Author

cc @yhuai @davies

@SparkQA
Copy link

SparkQA commented Mar 4, 2016

Test build #52436 has finished for PR 11492 at commit 58b1e88.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@davies
Copy link
Contributor

davies commented Mar 4, 2016

LGTM

@davies
Copy link
Contributor

davies commented Mar 4, 2016

Merging this into master, thanks!

@asfgit asfgit closed this in 15d57f9 Mar 4, 2016
roygao94 pushed a commit to roygao94/spark that referenced this pull request Mar 22, 2016
…ge in _verify_type

## What changes were proposed in this pull request?

This PR makes the `_verify_type` in `types.py` more strict, also check if numeric value is within allowed range.

## How was this patch tested?

newly added doc test.

Author: Wenchen Fan <wenchen@databricks.com>

Closes apache#11492 from cloud-fan/py-verify.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants