Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions python/pyspark/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2136,9 +2136,9 @@ def __getitem__(self, item):

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("__"):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this check because getattr can only be called with strings:

>>> foo = []
>>> getattr(foo, 123)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: getattr(): attribute name must be string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Row already had this check in its __getattr__ call, so I think it's safe to do the same thing here, too.

raise AttributeError(name)
return Column(self._jdf.apply(name))

def alias(self, name):
""" Alias the current DataFrame """
Expand Down
10 changes: 10 additions & 0 deletions python/pyspark/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from fileinput import input
from glob import glob
import os
import pydoc
import re
import shutil
import subprocess
Expand Down Expand Up @@ -1032,6 +1033,15 @@ def test_aggregator(self):
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the case that threw an exception. The other two cases below are just to improve our test-coverage, since those classes also have custom __getattr__ methods.

pydoc.render_doc(df.foo)
pydoc.render_doc(df.take(1))


class InputFormatTests(ReusedPySparkTestCase):

Expand Down