-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-24868][PYTHON]add sequence function in Python #21820
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
Conversation
|
Test build #93303 has finished for PR 21820 at commit
|
HyukjinKwon
left a comment
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
python/pyspark/sql/functions.py
Outdated
| @since(2.4) | ||
| def sequence(start, stop, step=None): | ||
| """ | ||
| Generate a sequence of integers from start to stop, incrementing by step. |
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.
Let's quite them `start` and `stop`
| >>> df1 = spark.createDataFrame([(-2, 2)], ('C1', 'C2')) | ||
| >>> df1.select(sequence('C1', 'C2').alias('r')).collect() | ||
| [Row(r=[-2, -1, 0, 1, 2])] | ||
| >>> df2 = spark.createDataFrame([(4, -4, -2)], ('C1', 'C2', 'C3')) |
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.
What happens if the step is positive in this case?
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 will throw java.lang.IllegalArgumentException.
There is a check in collectionOperations.scala
require(
(step > num.zero && start <= stop)
|| (step < num.zero && start >= stop)
|| (step == num.zero && start == stop),
s"Illegal sequence boundaries: $start to $stop by $step")
|
Test build #93317 has finished for PR 21820 at commit
|
|
Merged to master |
|
@HyukjinKwon Thanks! |
What changes were proposed in this pull request?
Add
sequencein functions.pyHow was this patch tested?
Add doctest.