Skip to content

Commit

Permalink
Fix python style
Browse files Browse the repository at this point in the history
Signed-off-by: Karen Feng <karen.feng@databricks.com>
  • Loading branch information
karenfeng committed Oct 5, 2020
1 parent df1fc36 commit 0ff60f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 7 additions & 7 deletions python/pyspark/sql/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ def xxhash64(*cols):


@since(3.1)
def assert_true(col, errMsg = None):
def assert_true(col, errMsg=None):
"""
Returns null if the input column is true; throws an exception with the provided error message
otherwise.
Expand All @@ -1618,9 +1618,9 @@ def assert_true(col, errMsg = None):
)

errMsg = (
_create_column_from_literal(errMsg)
if isinstance(errMsg, str)
else _to_java_column(errMsg)
_create_column_from_literal(errMsg)
if isinstance(errMsg, str)
else _to_java_column(errMsg)
)
return Column(sc._jvm.functions.assert_true(_to_java_column(col), errMsg))

Expand All @@ -1637,9 +1637,9 @@ def raise_error(errMsg):

sc = SparkContext._active_spark_context
errMsg = (
_create_column_from_literal(errMsg)
if isinstance(errMsg, str)
else _to_java_column(errMsg)
_create_column_from_literal(errMsg)
if isinstance(errMsg, str)
else _to_java_column(errMsg)
)
return Column(sc._jvm.functions.raise_error(errMsg))

Expand Down
10 changes: 8 additions & 2 deletions python/pyspark/sql/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,10 @@ def test_assert_true(self):

with self.assertRaises(TypeError) as cm:
df.select(assert_true(df.id < 2, 5))
self.assertEquals("errMsg should be a Column or a str, got <class 'int'>", str(cm.exception))
self.assertEquals(
"errMsg should be a Column or a str, got <class 'int'>",
str(cm.exception)
)

def test_raise_error(self):
from pyspark.sql.functions import raise_error
Expand All @@ -566,7 +569,10 @@ def test_raise_error(self):

with self.assertRaises(TypeError) as cm:
df.select(raise_error(None))
self.assertEquals("errMsg should be a Column or a str, got <class 'NoneType'>", str(cm.exception))
self.assertEquals(
"errMsg should be a Column or a str, got <class 'NoneType'>",
str(cm.exception)
)


if __name__ == "__main__":
Expand Down

0 comments on commit 0ff60f4

Please sign in to comment.