aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Kelley <rgbkrk@gmail.com>2017-04-18 12:35:27 -0700
committerHolden Karau <holden@us.ibm.com>2017-04-18 12:35:27 -0700
commitf654b39a63d4f9b118733733c7ed2a1b58649e3d (patch)
treee60fbffbaf6a17fb8d83a2fd45f37cc980825688
parent1f81dda37cfc2049fabd6abd93ef3720d0aa03ea (diff)
downloadspark-f654b39a63d4f9b118733733c7ed2a1b58649e3d.tar.gz
spark-f654b39a63d4f9b118733733c7ed2a1b58649e3d.tar.bz2
spark-f654b39a63d4f9b118733733c7ed2a1b58649e3d.zip
[SPARK-20360][PYTHON] reprs for interpreters
## What changes were proposed in this pull request? Establishes a very minimal `_repr_html_` for PySpark's `SparkContext`. ## How was this patch tested? nteract: ![screen shot 2017-04-17 at 3 41 29 pm](https://cloud.githubusercontent.com/assets/836375/25107701/d57090ba-2385-11e7-8147-74bc2c50a41b.png) Jupyter: ![screen shot 2017-04-17 at 3 53 19 pm](https://cloud.githubusercontent.com/assets/836375/25107725/05bf1fe8-2386-11e7-93e1-07a20c917dde.png) Hydrogen: ![screen shot 2017-04-17 at 3 49 55 pm](https://cloud.githubusercontent.com/assets/836375/25107664/a75e1ddc-2385-11e7-8477-258661833007.png) Author: Kyle Kelley <rgbkrk@gmail.com> Closes #17662 from rgbkrk/repr.
-rw-r--r--python/pyspark/context.py26
-rw-r--r--python/pyspark/sql/session.py11
2 files changed, 37 insertions, 0 deletions
diff --git a/python/pyspark/context.py b/python/pyspark/context.py
index 2961cda553..3be07325f4 100644
--- a/python/pyspark/context.py
+++ b/python/pyspark/context.py
@@ -240,6 +240,32 @@ class SparkContext(object):
if isinstance(threading.current_thread(), threading._MainThread):
signal.signal(signal.SIGINT, signal_handler)
+ def __repr__(self):
+ return "<SparkContext master={master} appName={appName}>".format(
+ master=self.master,
+ appName=self.appName,
+ )
+
+ def _repr_html_(self):
+ return """
+ <div>
+ <p><b>SparkContext</b></p>
+
+ <p><a href="{sc.uiWebUrl}">Spark UI</a></p>
+
+ <dl>
+ <dt>Version</dt>
+ <dd><code>v{sc.version}</code></dd>
+ <dt>Master</dt>
+ <dd><code>{sc.master}</code></dd>
+ <dt>AppName</dt>
+ <dd><code>{sc.appName}</code></dd>
+ </dl>
+ </div>
+ """.format(
+ sc=self
+ )
+
def _initialize_context(self, jconf):
"""
Initialize SparkContext in function to allow subclass specific initialization
diff --git a/python/pyspark/sql/session.py b/python/pyspark/sql/session.py
index 9f4772eec9..c1bf2bd76f 100644
--- a/python/pyspark/sql/session.py
+++ b/python/pyspark/sql/session.py
@@ -221,6 +221,17 @@ class SparkSession(object):
or SparkSession._instantiatedSession._sc._jsc is None:
SparkSession._instantiatedSession = self
+ def _repr_html_(self):
+ return """
+ <div>
+ <p><b>SparkSession - {catalogImplementation}</b></p>
+ {sc_HTML}
+ </div>
+ """.format(
+ catalogImplementation=self.conf.get("spark.sql.catalogImplementation"),
+ sc_HTML=self.sparkContext._repr_html_()
+ )
+
@since(2.0)
def newSession(self):
"""