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/13 22:36:46 UTC

[GitHub] [spark] ueshin commented on a change in pull request #33968: [SPARK-36722][PYTHON] Fix Series.update with another in same frame

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



##########
File path: python/pyspark/pandas/series.py
##########
@@ -4548,22 +4548,31 @@ def update(self, other: "Series") -> None:
         if not isinstance(other, Series):
             raise TypeError("'other' must be a Series")
 
-        combined = combine_frames(self._psdf, other._psdf, how="leftouter")
+        if same_anchor(self, other):
+            scol = F.when(other.spark.column.isNotNull(), other.spark.column).otherwise(
+                self.spark.column
+            )
+            internal = self._psdf._internal.with_new_spark_column(
+                self._column_label, scol  # TODO: dtype?
+            )
+            self._psdf._update_internal_frame(internal.resolved_copy)

Review comment:
       Could you also modify tests to check above?

##########
File path: python/pyspark/pandas/series.py
##########
@@ -4548,22 +4548,31 @@ def update(self, other: "Series") -> None:
         if not isinstance(other, Series):
             raise TypeError("'other' must be a Series")
 
-        combined = combine_frames(self._psdf, other._psdf, how="leftouter")
+        if same_anchor(self, other):
+            scol = F.when(other.spark.column.isNotNull(), other.spark.column).otherwise(
+                self.spark.column
+            )
+            internal = self._psdf._internal.with_new_spark_column(
+                self._column_label, scol  # TODO: dtype?
+            )
+            self._psdf._update_internal_frame(internal.resolved_copy)

Review comment:
       I don't think we need `resolved_copy` to keep the anchor same.
   
   It also fixes the issue below:
   
   ```py
   >>> pdf = pd.DataFrame(
   ...     {"a": [None, 2, 3, 4, 5, 6, 7, 8, None], "b": [None, 5, None, 3, 2, 1, None, 0, 0]},
   ... )
   >>> pser = pdf.a
   >>> pser.update(pdf.b)
   >>> pser
   0    NaN
   1    5.0
   2    3.0
   3    3.0
   4    2.0
   5    1.0
   6    7.0
   7    0.0
   8    0.0
   Name: a, dtype: float64
   ```
   
   whereas:
   
   ```py
   >>> psdf = ps.from_pandas(pdf)
   >>> psser = psdf.a
   >>> psser.update(psdf.b)
   >>> psser
   0    NaN
   1    2.0
   2    3.0
   3    4.0
   4    5.0
   5    6.0
   6    7.0
   7    8.0
   8    NaN
   Name: a, dtype: float64
   ```




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