xinrong-databricks commented on a change in pull request #33929: URL: https://github.com/apache/spark/pull/33929#discussion_r704654955
########## File path: python/pyspark/pandas/tests/test_dataframe.py ########## @@ -1287,8 +1278,42 @@ def test_drop(self): pdf = pd.DataFrame({10: [1, 2], 20: [3, 4], 30: [5, 6]}, index=np.random.rand(2)) psdf = ps.from_pandas(pdf) - self.assert_eq(psdf.drop(10), pdf.drop(10, axis=1)) - self.assert_eq(psdf.drop([20, 30]), pdf.drop([20, 30], axis=1)) + self.assert_eq(psdf.drop(10, axis=1), pdf.drop(10, axis=1)) + self.assert_eq(psdf.drop([20, 30], axis=1), pdf.drop([20, 30], axis=1)) + + # + # Drop rows by index + # + + pdf = pd.DataFrame({"X": [1, 2, 3], "Y": [4, 5, 6], "Z": [7, 8, 9]}, index=["A", "B", "C"]) + psdf = ps.from_pandas(pdf) + + # Given labels (and axis = 0) + self.assert_eq(psdf.drop(labels="A", axis=0), pdf.drop(labels="A", axis=0)) + self.assert_eq(psdf.drop(labels="A"), pdf.drop(labels="A")) + self.assert_eq(psdf.drop(labels=["A", "C"], axis=0), pdf.drop(labels=["A", "C"], axis=0)) + self.assert_eq( + psdf.drop(labels=["A", "B", "C"], axis=0), pdf.drop(labels=["A", "B", "C"], axis=0) + ) + + # Given index + self.assert_eq(psdf.drop(index="A"), pdf.drop(index="A")) + self.assert_eq(psdf.drop(index=["A", "C"]), pdf.drop(index=["A", "C"])) + self.assert_eq(psdf.drop(index=["A", "B", "C"]), pdf.drop(index=["A", "B", "C"])) + + # Non-string names + pdf.index = [10, 20, 30] + psdf = ps.from_pandas(pdf) + self.assert_eq(psdf.drop(labels=10, axis=0), pdf.drop(labels=10, axis=0)) + self.assert_eq(psdf.drop(labels=[10, 30], axis=0), pdf.drop(labels=[10, 30], axis=0)) + self.assert_eq( + psdf.drop(labels=[10, 20, 30], axis=0), pdf.drop(labels=[10, 20, 30], axis=0) + ) + + # MultiIndex + pdf.index = pd.MultiIndex.from_tuples([("a", "x"), ("b", "y"), ("c", "z")]) + psdf = ps.from_pandas(pdf) + self.assertRaises(NotImplementedError, lambda: psdf.drop(labels=[("a", "x")])) Review comment: Good point! Let me support that in this PR. -- 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-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org