spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From HyukjinKwon <...@git.apache.org>
Subject [GitHub] spark pull request #18926: [SPARK-21712] [PySpark] Clarify type error for Co...
Date Sun, 13 Aug 2017 10:27:46 GMT
Github user HyukjinKwon commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18926#discussion_r132837359
  
    --- Diff: python/pyspark/sql/column.py ---
    @@ -406,7 +406,13 @@ def substr(self, startPos, length):
             [Row(col=u'Ali'), Row(col=u'Bob')]
             """
             if type(startPos) != type(length):
    -            raise TypeError("Can not mix the type")
    +            raise TypeError(
    +                "startPos and length must be the same type. "
    +                "Got {startPos_t} and {length_t}, respectively."
    +                .format(
    +                    startPos_t=type(startPos),
    +                    length_t=type(length),
    +                ))
             if isinstance(startPos, (int, long)):
    --- End diff --
    
    @nchammas, supporting `long` with Python 2 is not documented in the docstring and looks
we throw unexpected exception by `long` with Python 2 as below:
    
    ```python
    from pyspark.sql import Row
    df = spark.createDataFrame([Row(name=u'Tom', height=80), Row(name=u'Alice', height=None)])
    df.select(df.name.substr(long(1), long(3)).alias("col")).collect()
    ```
    
    ```
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File ".../spark/python/pyspark/sql/column.py", line 411, in substr
        jc = self._jc.substr(startPos, length)
      File ".../spark/python/lib/py4j-0.10.6-src.zip/py4j/java_gateway.py", line 1160, in
__call__
      File ".../spark/python/pyspark/sql/utils.py", line 63, in deco
        return f(*a, **kw)
      File ".../spark/python/lib/py4j-0.10.6-src.zip/py4j/protocol.py", line 324, in get_return_value
    py4j.protocol.Py4JError: An error occurred while calling o47.substr. Trace:
    py4j.Py4JException: Method substr([class java.lang.Long, class java.lang.Long]) does not
exist
    	at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
    	at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
    	at py4j.Gateway.invoke(Gateway.java:274)
    	at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    	at py4j.commands.CallCommand.execute(CallCommand.java:79)
    	at py4j.GatewayConnection.run(GatewayConnection.java:214)
    	at java.lang.Thread.run(Thread.java:745)
    ```
    
    Would you mind double checking this and taking `long` out with a simple test with Python
2 as well? I think this will also address @gatorsmile's concern above as well.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


Mime
View raw message