You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by rx...@apache.org on 2015/01/30 01:23:24 UTC

spark git commit: [SPARK-5464] Fix help() for Python DataFrame instances

Repository: spark
Updated Branches:
  refs/heads/master c00d517d6 -> 0bb15f22d


[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 <jo...@databricks.com>

Closes #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


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/0bb15f22
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/0bb15f22
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/0bb15f22

Branch: refs/heads/master
Commit: 0bb15f22d1694d3ac0476eb14142b1b1cc781690
Parents: c00d517
Author: Josh Rosen <jo...@databricks.com>
Authored: Thu Jan 29 16:23:20 2015 -0800
Committer: Reynold Xin <rx...@databricks.com>
Committed: Thu Jan 29 16:23:20 2015 -0800

----------------------------------------------------------------------
 python/pyspark/sql.py   |  6 +++---
 python/pyspark/tests.py | 10 ++++++++++
 2 files changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/0bb15f22/python/pyspark/sql.py
----------------------------------------------------------------------
diff --git a/python/pyspark/sql.py b/python/pyspark/sql.py
index e636f99..3f2d7ac 100644
--- a/python/pyspark/sql.py
+++ b/python/pyspark/sql.py
@@ -2136,9 +2136,9 @@ class DataFrame(object):
 
     def __getattr__(self, name):
         """ Return the column by given name """
-        if isinstance(name, basestring):
-            return Column(self._jdf.apply(name))
-        raise AttributeError
+        if name.startswith("__"):
+            raise AttributeError(name)
+        return Column(self._jdf.apply(name))
 
     def alias(self, name):
         """ Alias the current DataFrame """

http://git-wip-us.apache.org/repos/asf/spark/blob/0bb15f22/python/pyspark/tests.py
----------------------------------------------------------------------
diff --git a/python/pyspark/tests.py b/python/pyspark/tests.py
index 081a77f..bec1961 100644
--- a/python/pyspark/tests.py
+++ b/python/pyspark/tests.py
@@ -23,6 +23,7 @@ from array import array
 from fileinput import input
 from glob import glob
 import os
+import pydoc
 import re
 import shutil
 import subprocess
@@ -1032,6 +1033,15 @@ class SQLTests(ReusedPySparkTestCase):
         from pyspark.sql import Aggregator as Agg
         # self.assertEqual((0, '100'), tuple(g.agg(Agg.first(df.key), Agg.last(df.value)).first()))
 
+    def test_help_command(self):
+        # Regression test for SPARK-5464
+        rdd = self.sc.parallelize(['{"foo":"bar"}', '{"foo":"baz"}'])
+        df = self.sqlCtx.jsonRDD(rdd)
+        # render_doc() reproduces the help() exception without printing output
+        pydoc.render_doc(df)
+        pydoc.render_doc(df.foo)
+        pydoc.render_doc(df.take(1))
+
 
 class InputFormatTests(ReusedPySparkTestCase):
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org