xinrong-databricks commented on a change in pull request #33714:
URL: https://github.com/apache/spark/pull/33714#discussion_r697730179



##########
File path: python/pyspark/pandas/tests/test_ops_on_diff_frames.py
##########
@@ -1955,6 +1960,48 @@ def test_pow_and_rpow(self):
         with self.assertRaisesRegex(ValueError, "Cannot combine the series or 
dataframe"):
             psser.rpow(psser_other)
 
+    def test_combine_first(self):
+        pdf = pd.DataFrame(
+            {
+                "A": {"falcon": 330.0, "eagle": 160.0},
+                "B": {"falcon": 345.0, "eagle": 200.0, "duck": 30.0},
+            }
+        )
+        pser1, pser2 = pdf.A, pdf.B
+        psdf = ps.from_pandas(pdf)
+        psser1, psser2 = psdf.A, psdf.B
+
+        self.assert_eq(
+            psser1.combine_first(psser2).sort_index(), 
pser1.combine_first(pser2).sort_index()
+        )
+
+        psser1.name = pser1.name = ("X", "A")
+        psser2.name = pser2.name = ("Y", "B")
+
+        self.assert_eq(
+            psser1.combine_first(psser2).sort_index(), 
pser1.combine_first(pser2).sort_index()
+        )

Review comment:
       Sounds good.

##########
File path: python/pyspark/pandas/tests/test_ops_on_diff_frames.py
##########
@@ -1955,6 +1960,48 @@ def test_pow_and_rpow(self):
         with self.assertRaisesRegex(ValueError, "Cannot combine the series or 
dataframe"):
             psser.rpow(psser_other)
 
+    def test_combine_first(self):
+        pdf = pd.DataFrame(
+            {
+                "A": {"falcon": 330.0, "eagle": 160.0},
+                "B": {"falcon": 345.0, "eagle": 200.0, "duck": 30.0},
+            }
+        )
+        pser1, pser2 = pdf.A, pdf.B
+        psdf = ps.from_pandas(pdf)
+        psser1, psser2 = psdf.A, psdf.B
+
+        self.assert_eq(
+            psser1.combine_first(psser2).sort_index(), 
pser1.combine_first(pser2).sort_index()
+        )
+
+        psser1.name = pser1.name = ("X", "A")
+        psser2.name = pser2.name = ("Y", "B")
+
+        self.assert_eq(
+            psser1.combine_first(psser2).sort_index(), 
pser1.combine_first(pser2).sort_index()
+        )
+
+        pdf = pd.DataFrame(
+            {("X", "A"): [None, 0], ("X", "B"): [4, None], ("Y", "C"): [3, 3], 
("Y", "B"): [1, 1]}
+        )
+        pdf1, pdf2 = pdf["X"], pdf["Y"]
+        psdf = ps.from_pandas(pdf)
+        psdf1, psdf2 = psdf["X"], psdf["Y"]
+
+        if LooseVersion(pd.__version__) >= LooseVersion("1.2.0"):
+            self.assert_eq(pdf1.combine_first(pdf2), 
psdf1.combine_first(psdf2))
+        else:
+            # pandas < 1.2.0 returns unexpected dtypes,
+            # please refer to 
https://github.com/pandas-dev/pandas/issues/28481 for details
+            expected_pdf = pd.DataFrame({"A": [None, 0], "B": [4.0, 1.0], "C": 
[3, 3]})
+            self.assert_eq(expected_pdf, psdf1.combine_first(psdf2))

Review comment:
       Moved.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to