aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPrashant Sharma <prashsh1@in.ibm.com>2016-06-28 17:11:06 +0530
committerPrashant Sharma <prashsh1@in.ibm.com>2016-06-28 17:11:06 +0530
commitf6b497fcdddc705a9e1022e20b0dbc15da1b5a5a (patch)
treeb28b241100d7ec0cbd79b0e7b79ac3f0a98dae04 /python
parent4cbf611c1dc88111ff49d005e902ad5864799ede (diff)
downloadspark-f6b497fcdddc705a9e1022e20b0dbc15da1b5a5a.tar.gz
spark-f6b497fcdddc705a9e1022e20b0dbc15da1b5a5a.tar.bz2
spark-f6b497fcdddc705a9e1022e20b0dbc15da1b5a5a.zip
[SPARK-16128][SQL] Allow setting length of characters to be truncated to, in Dataset.show function.
## What changes were proposed in this pull request? Allowing truncate to a specific number of character is convenient at times, especially while operating from the REPL. Sometimes those last few characters make all the difference, and showing everything brings in whole lot of noise. ## How was this patch tested? Existing tests. + 1 new test in DataFrameSuite. For SparkR and pyspark, existing tests and manual testing. Author: Prashant Sharma <prashsh1@in.ibm.com> Author: Prashant Sharma <prashant@apache.org> Closes #13839 from ScrapCodes/add_truncateTo_DF.show.
Diffstat (limited to 'python')
-rw-r--r--python/pyspark/sql/dataframe.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/python/pyspark/sql/dataframe.py b/python/pyspark/sql/dataframe.py
index acf9d08b23..a2443ed3d6 100644
--- a/python/pyspark/sql/dataframe.py
+++ b/python/pyspark/sql/dataframe.py
@@ -271,7 +271,9 @@ class DataFrame(object):
"""Prints the first ``n`` rows to the console.
:param n: Number of rows to show.
- :param truncate: Whether truncate long strings and align cells right.
+ :param truncate: If set to True, truncate strings longer than 20 chars by default.
+ If set to a number greater than one, truncates long strings to length ``truncate``
+ and align cells right.
>>> df
DataFrame[age: int, name: string]
@@ -282,8 +284,18 @@ class DataFrame(object):
| 2|Alice|
| 5| Bob|
+---+-----+
- """
- print(self._jdf.showString(n, truncate))
+ >>> df.show(truncate=3)
+ +---+----+
+ |age|name|
+ +---+----+
+ | 2| Ali|
+ | 5| Bob|
+ +---+----+
+ """
+ if isinstance(truncate, bool) and truncate:
+ print(self._jdf.showString(n, 20))
+ else:
+ print(self._jdf.showString(n, int(truncate)))
def __repr__(self):
return "DataFrame[%s]" % (", ".join("%s: %s" % c for c in self.dtypes))