Skip to content

Commit f654b39

Browse files
rgbkrkholdenk
authored andcommitted
[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 <[email protected]> Closes #17662 from rgbkrk/repr.
1 parent 1f81dda commit f654b39

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

python/pyspark/context.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,32 @@ def signal_handler(signal, frame):
240240
if isinstance(threading.current_thread(), threading._MainThread):
241241
signal.signal(signal.SIGINT, signal_handler)
242242

243+
def __repr__(self):
244+
return "<SparkContext master={master} appName={appName}>".format(
245+
master=self.master,
246+
appName=self.appName,
247+
)
248+
249+
def _repr_html_(self):
250+
return """
251+
<div>
252+
<p><b>SparkContext</b></p>
253+
254+
<p><a href="{sc.uiWebUrl}">Spark UI</a></p>
255+
256+
<dl>
257+
<dt>Version</dt>
258+
<dd><code>v{sc.version}</code></dd>
259+
<dt>Master</dt>
260+
<dd><code>{sc.master}</code></dd>
261+
<dt>AppName</dt>
262+
<dd><code>{sc.appName}</code></dd>
263+
</dl>
264+
</div>
265+
""".format(
266+
sc=self
267+
)
268+
243269
def _initialize_context(self, jconf):
244270
"""
245271
Initialize SparkContext in function to allow subclass specific initialization

python/pyspark/sql/session.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ def __init__(self, sparkContext, jsparkSession=None):
221221
or SparkSession._instantiatedSession._sc._jsc is None:
222222
SparkSession._instantiatedSession = self
223223

224+
def _repr_html_(self):
225+
return """
226+
<div>
227+
<p><b>SparkSession - {catalogImplementation}</b></p>
228+
{sc_HTML}
229+
</div>
230+
""".format(
231+
catalogImplementation=self.conf.get("spark.sql.catalogImplementation"),
232+
sc_HTML=self.sparkContext._repr_html_()
233+
)
234+
224235
@since(2.0)
225236
def newSession(self):
226237
"""

0 commit comments

Comments
 (0)