Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
brkyvz committed May 6, 2015
1 parent cf7a7bb commit a8dc3f7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
12 changes: 4 additions & 8 deletions python/pyspark/sql/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,8 @@ def _create_binary_mathfunction(name, doc=""):
def _(col1, col2):
sc = SparkContext._active_spark_context
# users might write ints for simplicity. This would throw an error on the JVM side.
if type(col1) is int:
col1 = col1 * 1.0
if type(col2) is int:
col2 = col2 * 1.0
jc = getattr(sc._jvm.functions, name)(col1._jc if isinstance(col1, Column) else col1,
col2._jc if isinstance(col2, Column) else col2)
jc = getattr(sc._jvm.functions, name)(col1._jc if isinstance(col1, Column) else float(col1),
col2._jc if isinstance(col2, Column) else float(col2))
return Column(jc)
_.__name__ = name
_.__doc__ = doc
Expand Down Expand Up @@ -103,9 +99,9 @@ def _(col1, col2):
'sinh': 'Computes the hyperbolic sine of the given value.',
'tan': 'Computes the tangent of the given value.',
'tanh': 'Computes the hyperbolic tangent of the given value.',
'toDeg': 'Converts an angle measured in radians to an approximately equivalent angle ' +
'toDegrees': 'Converts an angle measured in radians to an approximately equivalent angle ' +
'measured in degrees.',
'toRad': 'Converts an angle measured in degrees to an approximately equivalent angle ' +
'toRadians': 'Converts an angle measured in degrees to an approximately equivalent angle ' +
'measured in radians.',

'max': 'Aggregate function: returns the maximum value of the expression in a group.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1217,11 +1217,11 @@ class ExpressionEvaluationSuite extends ExpressionEvaluationBaseSuite {
unaryMathFunctionEvaluation(Tanh, math.tanh)
}

test("toDeg") {
test("toDegrees") {
unaryMathFunctionEvaluation(ToDegrees, math.toDegrees)
}

test("toRad") {
test("toRadians") {
unaryMathFunctionEvaluation(ToRadians, math.toRadians)
}

Expand Down
8 changes: 4 additions & 4 deletions sql/core/src/main/scala/org/apache/spark/sql/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -897,28 +897,28 @@ object functions {
*
* @group math_funcs
*/
def toDeg(e: Column): Column = ToDegrees(e.expr)
def toDegrees(e: Column): Column = ToDegrees(e.expr)

/**
* Converts an angle measured in radians to an approximately equivalent angle measured in degrees.
*
* @group math_funcs
*/
def toDeg(columnName: String): Column = toDeg(Column(columnName))
def toDegrees(columnName: String): Column = toDegrees(Column(columnName))

/**
* Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
*
* @group math_funcs
*/
def toRad(e: Column): Column = ToRadians(e.expr)
def toRadians(e: Column): Column = ToRadians(e.expr)

/**
* Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
*
* @group math_funcs
*/
def toRad(columnName: String): Column = toRad(Column(columnName))
def toRadians(columnName: String): Column = toRadians(Column(columnName))


//////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ class MathExpressionsSuite extends QueryTest {
}

test("toDeg") {
testOneToOneMathFunction(toDeg, math.toDegrees)
testOneToOneMathFunction(toDegrees, math.toDegrees)
}

test("toRad") {
testOneToOneMathFunction(toRad, math.toRadians)
testOneToOneMathFunction(toRadians, math.toRadians)
}

test("cbrt") {
Expand Down

0 comments on commit a8dc3f7

Please sign in to comment.