Skip to content

Conversation

@zero323
Copy link
Member

@zero323 zero323 commented Nov 10, 2020

What changes were proposed in this pull request?

Removes encoding of the JVM response in pyspark.sql.column.Column.__repr__.

Why are the changes needed?

API consistency and improved readability of the expressions.

Does this PR introduce any user-facing change?

Before this change

col("abc")
col("wąż")

result in

Column<b'abc'>
Column<b'w\xc4\x85\xc5\xbc'>

After this change we'll get

Column<'abc'>
Column<'wąż'>

How was this patch tested?

Existing tests and manual inspection.

@zero323
Copy link
Member Author

zero323 commented Nov 10, 2020

cc @davies (current behavior has been introduced with #4645, so I'd appreciate if you take a look and let me know if you have any feedback. TIA)


def __repr__(self):
return 'Column<%s>' % self._jc.toString().encode('utf8')
return "Column<'%s'>" % self._jc.toString()
Copy link
Member

Choose a reason for hiding this comment

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

python3 uses utf8 for strings by default, so this change seems fine. cc: @HyukjinKwon @viirya @srowen

Copy link
Member

Choose a reason for hiding this comment

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

Do we have any more instances of decode()?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, the change looks good, and yeah, are there more instances like this?

Copy link
Member

Choose a reason for hiding this comment

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

Seems fine. Is it originally for non printable characters in unicode?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we have any more instances of decode()?

We do a bit of encoding / decoding when we communicate with JVM, but purpose there is clear.

The only other place when we encode strings intended for user consumption is RDD.toDebugString. It also something that could be fixed, as it messing with the output a bit (as print won't respect line breaks).

Seems fine. Is it originally for non printable characters in unicode?

I believe the point was to have str object as the output, instead of unicode. If I recall correctly, unicode (py4j returns JVM Strings as unicode in Python 2 and as a result the whole expression would evaluate to unicode) in __repr__, wasn't handled correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

For example in IPython

>>> import sys
>>> sys.version_info
sys.version_info(major=2, minor=7, micro=15, releaselevel='final', serial=0)
>>> class Foo:
...     def __repr__(self):
...         return u"œ"
...     
...     
>>> Foo().__repr__()
u'\u0153'
>>> Foo()
Traceback (most recent call last):
  File "/path/to/lib/python2.7/site-packages/IPython/core/formatters.py", line 686, in __call__
    return repr(obj)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0153' in position 0: ordinal not in range(128)

@maropu
Copy link
Member

maropu commented Nov 10, 2020

Why WIP? btw, could you add tests?

@SparkQA
Copy link

SparkQA commented Nov 10, 2020

Test build #130892 has finished for PR 30322 at commit 49543e8.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 10, 2020

Test build #130893 has finished for PR 30322 at commit 88f0c50.

  • This patch fails Python style tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 10, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/35498/

@zero323
Copy link
Member Author

zero323 commented Nov 11, 2020

Why WIP?

Just out of habit after working on docs.

btw, could you add tests?

Of course, done.

@zero323 zero323 marked this pull request as ready for review November 11, 2020 00:02
@SparkQA
Copy link

SparkQA commented Nov 11, 2020

Test build #130894 has finished for PR 30322 at commit ec72805.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Nov 11, 2020

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/35498/

@SparkQA
Copy link

SparkQA commented Nov 11, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/35499/

@SparkQA
Copy link

SparkQA commented Nov 11, 2020

Kubernetes integration test starting
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/35500/

@SparkQA
Copy link

SparkQA commented Nov 11, 2020

Kubernetes integration test status success
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/35499/

@SparkQA
Copy link

SparkQA commented Nov 11, 2020

Kubernetes integration test status failure
URL: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder-K8s/35500/

@HyukjinKwon
Copy link
Member

Let me merge this in for now as this PR fixes what it aims.

Merged to master.

@zero323
Copy link
Member Author

zero323 commented Nov 11, 2020

Thanks everyone!

@zero323 zero323 deleted the SPARK-33415 branch November 11, 2020 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants