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



##########
File path: python/pyspark/pandas/tests/test_dataframe.py
##########
@@ -5726,6 +5726,56 @@ def test_iter_dataframe(self):
         for value_psdf, value_pdf in zip(psdf, pdf):
             self.assert_eq(value_psdf, value_pdf)
 
+    def test_combine_first(self):
+        pdf1 = pd.DataFrame({"A": [None, 0], "B": [4, None]})
+        psdf1 = ps.from_pandas(pdf1)
+        pdf2 = pd.DataFrame({"C": [3, 3], "B": [1, 1]})
+        psdf2 = ps.from_pandas(pdf2)
+
+        with option_context("compute.ops_on_diff_frames", True):
+            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))
+
+        pdf1.columns = pd.MultiIndex.from_tuples([("A", "willow"), ("B", 
"pine")])
+        psdf1 = ps.from_pandas(pdf1)
+        pdf2.columns = pd.MultiIndex.from_tuples([("C", "oak"), ("B", "pine")])
+        psdf2 = ps.from_pandas(pdf2)
+
+        with option_context("compute.ops_on_diff_frames", True):
+            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]})
+                expected_pdf.columns = pd.MultiIndex.from_tuples(
+                    [("A", "willow"), ("B", "pine"), ("C", "oak")]
+                )
+                self.assert_eq(expected_pdf, psdf1.combine_first(psdf2))
+
+        self.assertRaises(TypeError, lambda: psdf1.combine_first(ps.Series([1, 
2])))
+
+    def test_combine_first(self):

Review comment:
       Let's keep this one here.

##########
File path: python/pyspark/pandas/tests/test_dataframe.py
##########
@@ -5726,6 +5726,56 @@ def test_iter_dataframe(self):
         for value_psdf, value_pdf in zip(psdf, pdf):
             self.assert_eq(value_psdf, value_pdf)
 
+    def test_combine_first(self):
+        pdf1 = pd.DataFrame({"A": [None, 0], "B": [4, None]})
+        psdf1 = ps.from_pandas(pdf1)
+        pdf2 = pd.DataFrame({"C": [3, 3], "B": [1, 1]})
+        psdf2 = ps.from_pandas(pdf2)
+
+        with option_context("compute.ops_on_diff_frames", True):
+            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))
+
+        pdf1.columns = pd.MultiIndex.from_tuples([("A", "willow"), ("B", 
"pine")])
+        psdf1 = ps.from_pandas(pdf1)
+        pdf2.columns = pd.MultiIndex.from_tuples([("C", "oak"), ("B", "pine")])
+        psdf2 = ps.from_pandas(pdf2)
+
+        with option_context("compute.ops_on_diff_frames", True):
+            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]})
+                expected_pdf.columns = pd.MultiIndex.from_tuples(
+                    [("A", "willow"), ("B", "pine"), ("C", "oak")]
+                )
+                self.assert_eq(expected_pdf, psdf1.combine_first(psdf2))
+
+        self.assertRaises(TypeError, lambda: psdf1.combine_first(ps.Series([1, 
2])))

Review comment:
       This must be in `test_ops_on_diff_frames.py` and seems already there, so 
we can remove this.




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