Skip to content

Commit a8dc3f7

Browse files
committed
address comments
1 parent cf7a7bb commit a8dc3f7

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

python/pyspark/sql/functions.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ def _create_binary_mathfunction(name, doc=""):
5656
def _(col1, col2):
5757
sc = SparkContext._active_spark_context
5858
# users might write ints for simplicity. This would throw an error on the JVM side.
59-
if type(col1) is int:
60-
col1 = col1 * 1.0
61-
if type(col2) is int:
62-
col2 = col2 * 1.0
63-
jc = getattr(sc._jvm.functions, name)(col1._jc if isinstance(col1, Column) else col1,
64-
col2._jc if isinstance(col2, Column) else col2)
59+
jc = getattr(sc._jvm.functions, name)(col1._jc if isinstance(col1, Column) else float(col1),
60+
col2._jc if isinstance(col2, Column) else float(col2))
6561
return Column(jc)
6662
_.__name__ = name
6763
_.__doc__ = doc
@@ -103,9 +99,9 @@ def _(col1, col2):
10399
'sinh': 'Computes the hyperbolic sine of the given value.',
104100
'tan': 'Computes the tangent of the given value.',
105101
'tanh': 'Computes the hyperbolic tangent of the given value.',
106-
'toDeg': 'Converts an angle measured in radians to an approximately equivalent angle ' +
102+
'toDegrees': 'Converts an angle measured in radians to an approximately equivalent angle ' +
107103
'measured in degrees.',
108-
'toRad': 'Converts an angle measured in degrees to an approximately equivalent angle ' +
104+
'toRadians': 'Converts an angle measured in degrees to an approximately equivalent angle ' +
109105
'measured in radians.',
110106

111107
'max': 'Aggregate function: returns the maximum value of the expression in a group.',

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ExpressionEvaluationSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,11 +1217,11 @@ class ExpressionEvaluationSuite extends ExpressionEvaluationBaseSuite {
12171217
unaryMathFunctionEvaluation(Tanh, math.tanh)
12181218
}
12191219

1220-
test("toDeg") {
1220+
test("toDegrees") {
12211221
unaryMathFunctionEvaluation(ToDegrees, math.toDegrees)
12221222
}
12231223

1224-
test("toRad") {
1224+
test("toRadians") {
12251225
unaryMathFunctionEvaluation(ToRadians, math.toRadians)
12261226
}
12271227

sql/core/src/main/scala/org/apache/spark/sql/functions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,28 +897,28 @@ object functions {
897897
*
898898
* @group math_funcs
899899
*/
900-
def toDeg(e: Column): Column = ToDegrees(e.expr)
900+
def toDegrees(e: Column): Column = ToDegrees(e.expr)
901901

902902
/**
903903
* Converts an angle measured in radians to an approximately equivalent angle measured in degrees.
904904
*
905905
* @group math_funcs
906906
*/
907-
def toDeg(columnName: String): Column = toDeg(Column(columnName))
907+
def toDegrees(columnName: String): Column = toDegrees(Column(columnName))
908908

909909
/**
910910
* Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
911911
*
912912
* @group math_funcs
913913
*/
914-
def toRad(e: Column): Column = ToRadians(e.expr)
914+
def toRadians(e: Column): Column = ToRadians(e.expr)
915915

916916
/**
917917
* Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
918918
*
919919
* @group math_funcs
920920
*/
921-
def toRad(columnName: String): Column = toRad(Column(columnName))
921+
def toRadians(columnName: String): Column = toRadians(Column(columnName))
922922

923923

924924
//////////////////////////////////////////////////////////////////////////////////////////////

sql/core/src/test/scala/org/apache/spark/sql/MathExpressionsSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ class MathExpressionsSuite extends QueryTest {
158158
}
159159

160160
test("toDeg") {
161-
testOneToOneMathFunction(toDeg, math.toDegrees)
161+
testOneToOneMathFunction(toDegrees, math.toDegrees)
162162
}
163163

164164
test("toRad") {
165-
testOneToOneMathFunction(toRad, math.toRadians)
165+
testOneToOneMathFunction(toRadians, math.toRadians)
166166
}
167167

168168
test("cbrt") {

0 commit comments

Comments
 (0)