sarutak commented on a change in pull request #33988:
URL: https://github.com/apache/spark/pull/33988#discussion_r710144894
##########
File path: python/pyspark/sql/tests/test_functions.py
##########
@@ -157,6 +159,32 @@ def test_inverse_trig_functions(self):
for c in cols:
self.assertIn(f"{alias}(a)", repr(f(c)))
+ def test_reciprocal_trig_functions(self):
+ # SPARK-36683: Add new built-in SQL functions: SEC and CSC
Review comment:
This test includes missing tests for `cot` so how about `# SPARK-36683:
Tests for reciprocal trig functions (SEC, CSC and COT)`?
##########
File path: python/pyspark/sql/tests/test_functions.py
##########
@@ -157,6 +159,32 @@ def test_inverse_trig_functions(self):
for c in cols:
self.assertIn(f"{alias}(a)", repr(f(c)))
+ def test_reciprocal_trig_functions(self):
+ # SPARK-36683: Add new built-in SQL functions: SEC and CSC
+ list = [0.0, math.pi/6, math.pi/4, math.pi/3, math.pi/2,
+ math.pi, 3 * math.pi / 2, 2 * math.pi]
+
+ df = self.spark.createDataFrame(list, types.DoubleType())
+
+ def to_reciprocal_trig(func):
+ return [1.0 / func(i) if func(i) != 0 else math.inf for i in list]
+
+ def get_values(l):
Review comment:
`get_values` and `assert_close` are almost the same as ones defined in
`test_math_functions`.
https://github.com/apache/spark/blob/adbea252db0f61ed3aaa45ea20b704bad6c47408/python/pyspark/sql/tests/test_functions.py#L114-L120
Can we move them to `testing/sqlutils.py` to avoid duplication?
@HyukjinKwon What do you think?
##########
File path: python/pyspark/sql/tests/test_functions.py
##########
@@ -157,6 +159,32 @@ def test_inverse_trig_functions(self):
for c in cols:
self.assertIn(f"{alias}(a)", repr(f(c)))
+ def test_reciprocal_trig_functions(self):
+ # SPARK-36683: Add new built-in SQL functions: SEC and CSC
+ list = [0.0, math.pi/6, math.pi/4, math.pi/3, math.pi/2,
+ math.pi, 3 * math.pi / 2, 2 * math.pi]
+
+ df = self.spark.createDataFrame(list, types.DoubleType())
+
+ def to_reciprocal_trig(func):
+ return [1.0 / func(i) if func(i) != 0 else math.inf for i in list]
+
+ def get_values(l):
+ return [j[0] for j in l]
+
+ def assert_close(a, b):
+ c = get_values(b)
+ diff = [abs(v - c[k]) < 1e-6 if v != math.inf else v == c[k]
Review comment:
If we decide to move `assert_close` to `testing/sqlutils.py`, it's
better to consider the case of `-math.inf`.
##########
File path: python/pyspark/sql/tests/test_functions.py
##########
@@ -157,6 +159,32 @@ def test_inverse_trig_functions(self):
for c in cols:
self.assertIn(f"{alias}(a)", repr(f(c)))
+ def test_reciprocal_trig_functions(self):
+ # SPARK-36683: Add new built-in SQL functions: SEC and CSC
+ list = [0.0, math.pi/6, math.pi/4, math.pi/3, math.pi/2,
Review comment:
Let's put a whitespace between operator and operand like `math.pi / 6`.
Also, `list` is a keyword in Python so we should avoid to use it for an
identifier.
##########
File path: python/pyspark/sql/functions.pyi
##########
@@ -301,6 +301,7 @@ def column(col: str) -> Column: ...
def cos(col: ColumnOrName) -> Column: ...
def cosh(col: ColumnOrName) -> Column: ...
def cot(col: ColumnOrName) -> Column: ...
+def csc(col: ColumnOrName) -> Column: ...
Review comment:
It's better to let `csc` sit after `count`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]