-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-21712] [PySpark] Clarify type error for Column.substr() #18926
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -406,7 +406,13 @@ def substr(self, startPos, length): | |
| [Row(col=u'Ali'), Row(col=u'Bob')] | ||
| """ | ||
| if type(startPos) != type(length): | ||
| raise TypeError("Can not mix the type") | ||
| raise TypeError( | ||
| "startPos and length must be the same type. " | ||
| "Got {startPos_t} and {length_t}, respectively." | ||
| .format( | ||
| startPos_t=type(startPos), | ||
| length_t=type(length), | ||
| )) | ||
| if isinstance(startPos, (int, long)): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nchammas, supporting from pyspark.sql import Row
df = spark.createDataFrame([Row(name=u'Tom', height=80), Row(name=u'Alice', height=None)])
df.select(df.name.substr(long(1), long(3)).alias("col")).collect()Would you mind double checking this and taking |
||
| jc = self._jc.substr(startPos, length) | ||
| elif isinstance(startPos, Column): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
->
startPos: {startPos_t}; length: {length_t}.BTW, why we do the type checking here, instead of doing it in the actual Scala impl of
substr?In addition, we do not support the mixed cases? For example,
startPosis int,lengthis long.Uh oh!
There was an error while loading. Please reload this page.
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.
Do you mean exposing Java types in the error message is better or suggesting method signature change in Scala impl of
substrwith the check logic?In Python, I guess it makes sense calling
intin general.longandintare unified in Python 3 and this PR looks targeting only the exception message fix.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 PySpark always needs to check the types, are we doing the same things in all the other function calls?
In addition, why not directly checking
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.
It needs to check the types in general and we need to hide the error message related with Java types. It is also true that we also need to make such logics in to Scala one to deduplicate this logic if they are duplicated. R has also a similar problem in some places. I don't think we should change this case anyway.
It looks we should ...
or we should introduce bridge methods in Scala side and implement this checking logic IIRC.
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.
For the latter, It looks we should call either
substrwith column,column or with int,int. I would like to avoid changing these If either way does not reduce the code diff and is virtually same, if I understood correctly.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.
cc @ueshin
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'm sorry for the delay.
I guess we can support
longby casting tointand also the "mixed" cases @gatorsmile metioned.What do you think @HyukjinKwon ?
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.
Yea, I think we could support
long. I think this PR basically targets exception message fix. Could we make this separate?I guess supporting the case above requires a set of regression tests with min/max of int, fix for documentation and etc, which I think is rather loosely related with the JIRA.