You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by viirya <gi...@git.apache.org> on 2017/05/01 00:10:22 UTC

[GitHub] spark pull request #17605: [SPARK-20290][MINOR][PYTHON][SQL] Add PySpark wra...

Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17605#discussion_r114088222
  
    --- Diff: python/pyspark/sql/column.py ---
    @@ -171,6 +171,58 @@ def __init__(self, jc):
         __ge__ = _bin_op("geq")
         __gt__ = _bin_op("gt")
     
    +    _eqNullSafe_doc = """
    +    Equality test that is safe for null values.
    +
    +    :param other: a value or :class:`Column`
    +
    +    >>> from pyspark.sql import Row
    +    >>> df1 = spark.createDataFrame([
    +    ...     Row(id=1, value='foo'),
    +    ...     Row(id=2, value=None)
    +    ... ])
    +    >>> df1.select(
    +    ...     df1['value'] == 'foo',
    +    ...     df1['value'].eqNullSafe('foo'),
    +    ...     df1['value'].eqNullSafe(None)
    +    ... ).show()
    +    +-------------+---------------+----------------+
    +    |(value = foo)|(value <=> foo)|(value <=> NULL)|
    +    +-------------+---------------+----------------+
    +    |         true|           true|           false|
    +    |         null|          false|            true|
    +    +-------------+---------------+----------------+
    +    >>> df2 = spark.createDataFrame([
    +    ...     Row(value = 'bar'),
    +    ...     Row(value = None)
    +    ... ])
    +    >>> df1.join(df2, df1["value"] == df2["value"]).count()
    +    0
    +    >>> df1.join(df2, df1["value"].eqNullSafe(df2["value"])).count()
    +    1
    +    >>> df2 = spark.createDataFrame([
    +    ...     Row(id=1, value=float('NaN')),
    +    ...     Row(id=2, value=42.0),
    +    ...     Row(id=3, value=None)
    +    ... ])
    +    >>> df2.select(
    +    ...     df2['value'].eqNullSafe(None),
    +    ...     df2['value'].eqNullSafe(float('NaN')),
    +    ...     df2['value'].eqNullSafe(42.0)
    +    ... ).show()
    +    +----------------+---------------+----------------+
    +    |(value <=> NULL)|(value <=> NaN)|(value <=> 42.0)|
    +    +----------------+---------------+----------------+
    +    |           false|           true|           false|
    --- End diff --
    
    In Pandas/numpy,  the `nan`'s don\u2019t compare equal, i.e., `np.nan` != `np.nan`, but in Spark we treat them as equal. Shall we document it too?


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