You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/05/16 14:17:04 UTC
[GitHub] [spark] srowen commented on a change in pull request #32555: [SPARK-35408][PYTHON] Improve parameter validation in DataFrame.show
srowen commented on a change in pull request #32555:
URL: https://github.com/apache/spark/pull/32555#discussion_r633096079
##########
File path: python/pyspark/sql/dataframe.py
##########
@@ -482,10 +482,22 @@ def show(self, n=20, truncate=True, vertical=False):
age | 5
name | Bob
"""
+
+ if not isinstance(n, int) or isinstance(n, bool):
Review comment:
Is this trying to catch the case where a user calls `.show(False)` for example, meaning `.show(truncate=False)`? I get it. While I think we could equally check so many other methods like this, maybe this is worth checking more thoroughly here.
##########
File path: python/pyspark/sql/dataframe.py
##########
@@ -482,10 +482,23 @@ def show(self, n=20, truncate=True, vertical=False):
age | 5
name | Bob
"""
+
+ if not isinstance(n, int) or isinstance(n, bool):
+ raise TypeError("Parameter 'n' (number of rows) must be an int")
+
+ if not isinstance(vertical, bool):
+ raise TypeError("Parameter 'vertical' must be a bool")
+
if isinstance(truncate, bool) and truncate:
print(self._jdf.showString(n, 20, vertical))
else:
- print(self._jdf.showString(n, int(truncate), vertical))
+ try:
+ int_truncate = int(truncate)
+ except ValueError:
+ raise ValueError(f"Non-bool parameter 'truncate={truncate}'"
Review comment:
When would this happen, given the check above? Wouldn't this be the "Non-int parameter" case anyway?
--
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org