Skip to content

Commit 0bb15f2

Browse files
JoshRosenrxin
authored andcommitted
[SPARK-5464] Fix help() for Python DataFrame instances
This fixes an exception that prevented users from calling `help()` on Python DataFrame instances. Author: Josh Rosen <[email protected]> Closes apache#4278 from JoshRosen/SPARK-5464-python-dataframe-help-command and squashes the following commits: 08f95f7 [Josh Rosen] Fix exception when calling help() on Python DataFrame instances
1 parent c00d517 commit 0bb15f2

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

python/pyspark/sql.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,9 +2136,9 @@ def __getitem__(self, item):
21362136

21372137
def __getattr__(self, name):
21382138
""" Return the column by given name """
2139-
if isinstance(name, basestring):
2140-
return Column(self._jdf.apply(name))
2141-
raise AttributeError
2139+
if name.startswith("__"):
2140+
raise AttributeError(name)
2141+
return Column(self._jdf.apply(name))
21422142

21432143
def alias(self, name):
21442144
""" Alias the current DataFrame """

python/pyspark/tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from fileinput import input
2424
from glob import glob
2525
import os
26+
import pydoc
2627
import re
2728
import shutil
2829
import subprocess
@@ -1032,6 +1033,15 @@ def test_aggregator(self):
10321033
from pyspark.sql import Aggregator as Agg
10331034
# self.assertEqual((0, '100'), tuple(g.agg(Agg.first(df.key), Agg.last(df.value)).first()))
10341035

1036+
def test_help_command(self):
1037+
# Regression test for SPARK-5464
1038+
rdd = self.sc.parallelize(['{"foo":"bar"}', '{"foo":"baz"}'])
1039+
df = self.sqlCtx.jsonRDD(rdd)
1040+
# render_doc() reproduces the help() exception without printing output
1041+
pydoc.render_doc(df)
1042+
pydoc.render_doc(df.foo)
1043+
pydoc.render_doc(df.take(1))
1044+
10351045

10361046
class InputFormatTests(ReusedPySparkTestCase):
10371047

0 commit comments

Comments
 (0)