You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/09/16 17:28:36 UTC

[GitHub] [spark] ueshin commented on a change in pull request #34005: [SPARK-36762][PYTHON] Fix Series.isin when Series has NaN values

ueshin commented on a change in pull request #34005:
URL: https://github.com/apache/spark/pull/34005#discussion_r710324982



##########
File path: python/pyspark/pandas/base.py
##########
@@ -873,7 +873,11 @@ def isin(self: IndexOpsLike, values: Sequence[Any]) -> IndexOpsLike:
             )
 
         values = values.tolist() if isinstance(values, np.ndarray) else list(values)
-        return self._with_new_scol(self.spark.column.isin([SF.lit(v) for v in values]))
+
+        other = [SF.lit(v) for v in values]
+        scol = self.spark.column.isin(other)
+
+        return self._with_new_scol(F.when(scol.isNull(), False).otherwise(scol))

Review comment:
       I guess `F.coalesce` is better? `F.coalesce(scol, F.lit(False))`

##########
File path: python/pyspark/pandas/base.py
##########
@@ -873,7 +873,11 @@ def isin(self: IndexOpsLike, values: Sequence[Any]) -> IndexOpsLike:
             )
 
         values = values.tolist() if isinstance(values, np.ndarray) else list(values)
-        return self._with_new_scol(self.spark.column.isin([SF.lit(v) for v in values]))
+
+        other = [SF.lit(v) for v in values]
+        scol = self.spark.column.isin(other)
+
+        return self._with_new_scol(F.when(scol.isNull(), False).otherwise(scol))

Review comment:
       Btw, we can mange `field` here?
   `field=self._internal.data_fields[0].copy(dtype=np.dtype("bool"), spark_type=BooleanType(), nullable=False)`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



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