HyukjinKwon commented on a change in pull request #34007:
URL: https://github.com/apache/spark/pull/34007#discussion_r709156586
##########
File path: python/pyspark/pandas/tests/test_dataframe.py
##########
@@ -4428,6 +4428,28 @@ def f2(_) -> ps.Series[int]:
pdf.apply(lambda x: len(x), axis=1).sort_index(),
)
+ def test_apply_with_type(self):
+ pdf = self.pdf
+ psdf = ps.from_pandas(pdf)
+
+ def identify1(x) -> ps.DataFrame[int, int]:
+ return x
+
+ # Type hints set the default column names, and we use default index for
+ # pandas API on Spark. Here we ignore both diff.
+ actual = psdf.apply(identify1, axis=1)
+ expected = pdf.apply(identify1, axis=1)
+ self.assert_eq(sorted(actual["c0"].to_numpy()),
sorted(expected["a"].to_numpy()))
+ self.assert_eq(sorted(actual["c1"].to_numpy()),
sorted(expected["b"].to_numpy()))
+
+ def identify2(x) -> ps.DataFrame[slice("a", int), slice("b", int)]: #
noqa: F405
Review comment:
I used slice because mypy fails. FYI, the new syntax doesn't fail w/
mypy.
--
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]