You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Sean Owen (JIRA)" <ji...@apache.org> on 2019/01/16 23:08:00 UTC

[jira] [Created] (SPARK-26638) Pyspark vector classes always return error for unary negation

Sean Owen created SPARK-26638:
---------------------------------

             Summary: Pyspark vector classes always return error for unary negation
                 Key: SPARK-26638
                 URL: https://issues.apache.org/jira/browse/SPARK-26638
             Project: Spark
          Issue Type: Bug
          Components: ML, PySpark
    Affects Versions: 2.4.0, 2.3.2
            Reporter: Sean Owen
            Assignee: Sean Owen


It looks like the implementation of {{__neg__}} for Pyspark vector classes is wrong:

{code}
    def _delegate(op):
        def func(self, other):
            if isinstance(other, DenseVector):
                other = other.array
            return DenseVector(getattr(self.array, op)(other))
        return func

    __neg__ = _delegate("__neg__")
{code}

This delegation works for binary operators but not for unary, and indeed, it doesn't work at all:

{code}
from pyspark.ml.linalg import DenseVector
v = DenseVector([1,2,3])
-v
...
TypeError: func() missing 1 required positional argument: 'other'
{code}

This was spotted by static analyis on lgtm.com:
https://lgtm.com/projects/g/apache/spark/alerts/?mode=tree&lang=python&ruleFocus=7850093

Easy to fix and add a test for, as I presume we want this to be implemented.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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