-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-12158] [SparkR] [SQL] Fix 'sample' functions that break R unit test cases #10160
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
ec77010
2ab89e8
34d0118
4337c35
a78109e
ad3ea31
493b368
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -677,25 +677,44 @@ setMethod("unique", | |||
| #' collect(sample(df, TRUE, 0.5)) | ||||
| #'} | ||||
| setMethod("sample", | ||||
| # TODO : Figure out how to send integer as java.lang.Long to JVM so | ||||
| # we can send seed as an argument through callJMethod | ||||
| signature(x = "DataFrame", withReplacement = "logical", | ||||
| fraction = "numeric"), | ||||
| function(x, withReplacement, fraction) { | ||||
| fraction = "numeric", seed = "missing"), | ||||
| function(x, withReplacement, fraction, seed) { | ||||
|
Contributor
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. @felixcheung Shouldn't we document this param in the roxygen doc above ? Otherwise how would anybody know we support a
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. yes we should add a |
||||
| if (fraction < 0.0) stop(cat("Negative fraction value:", fraction)) | ||||
| sdf <- callJMethod(x@sdf, "sample", withReplacement, fraction) | ||||
| dataFrame(sdf) | ||||
| }) | ||||
|
|
||||
| #' @rdname sample | ||||
| #' @name sample | ||||
| setMethod("sample", | ||||
| # we can send seed as an argument through callJMethod | ||||
| signature(x = "DataFrame", withReplacement = "logical", | ||||
| fraction = "numeric", seed = "numeric"), | ||||
|
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. you could in fact merge these overload/variant into one. Please see this for an example: Line 1177 in 5011f26
Contributor
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. +1 |
||||
| function(x, withReplacement, fraction, seed) { | ||||
| if (fraction < 0.0) stop(cat("Negative fraction value:", fraction)) | ||||
| sdf <- callJMethod(x@sdf, "sample", withReplacement, fraction, as.integer(seed)) | ||||
| dataFrame(sdf) | ||||
| }) | ||||
|
|
||||
| #' @rdname sample | ||||
| #' @name sample_frac | ||||
| setMethod("sample_frac", | ||||
| signature(x = "DataFrame", withReplacement = "logical", | ||||
| fraction = "numeric"), | ||||
| function(x, withReplacement, fraction) { | ||||
| fraction = "numeric", seed = "missing"), | ||||
| function(x, withReplacement, fraction, seed) { | ||||
| sample(x, withReplacement, fraction) | ||||
| }) | ||||
|
|
||||
| #' @rdname sample | ||||
| #' @name sample_frac | ||||
| setMethod("sample_frac", | ||||
| signature(x = "DataFrame", withReplacement = "logical", | ||||
| fraction = "numeric", seed = "numeric"), | ||||
| function(x, withReplacement, fraction, seed) { | ||||
| sample(x, withReplacement, fraction, as.integer(seed)) | ||||
|
||||
| }) | ||||
|
|
||||
| #' nrow | ||||
| #' | ||||
| #' Returns the number of rows in a DataFrame | ||||
|
|
||||
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.
don't delete this comment. move it close to as.integer(seed). This is a known limitation of serde now.
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.
True. Added it back.