-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-14639][PYTHON][R] Add bround function in Python/R.
#12509
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 all commits
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 |
|---|---|---|
|
|
@@ -125,6 +125,7 @@ exportMethods("%in%", | |
| "between", | ||
| "bin", | ||
| "bitwiseNOT", | ||
| "bround", | ||
| "cast", | ||
| "cbrt", | ||
| "ceil", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -467,16 +467,29 @@ def randn(seed=None): | |
| @since(1.5) | ||
| def round(col, scale=0): | ||
| """ | ||
| Round the value of `e` to `scale` decimal places if `scale` >= 0 | ||
| Round the given value to `scale` decimal places using HALF_UP rounding mode if `scale` >= 0 | ||
| or at integral part when `scale` < 0. | ||
|
|
||
| >>> sqlContext.createDataFrame([(2.546,)], ['a']).select(round('a', 1).alias('r')).collect() | ||
| [Row(r=2.5)] | ||
| >>> sqlContext.createDataFrame([(2.5,)], ['a']).select(round('a', 0).alias('r')).collect() | ||
|
||
| [Row(r=3.0)] | ||
| """ | ||
| sc = SparkContext._active_spark_context | ||
| return Column(sc._jvm.functions.round(_to_java_column(col), scale)) | ||
|
|
||
|
|
||
| @since(2.0) | ||
| def bround(col, scale=0): | ||
| """ | ||
| Round the given value to `scale` decimal places using HALF_EVEN rounding mode if `scale` >= 0 | ||
| or at integral part when `scale` < 0. | ||
|
|
||
| >>> sqlContext.createDataFrame([(2.5,)], ['a']).select(bround('a', 0).alias('r')).collect() | ||
| [Row(r=2.0)] | ||
| """ | ||
| sc = SparkContext._active_spark_context | ||
| return Column(sc._jvm.functions.bround(_to_java_column(col), scale)) | ||
|
|
||
|
|
||
| @since(1.5) | ||
| def shiftLeft(col, numBits): | ||
| """Shift the given value numBits left. | ||
|
|
||
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.
Could you give a more detailed example of where it gets rounded down and where it gets rounded up ?
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.
Sure. Thank you for review. I'll add more example.