xinrong-databricks commented on a change in pull request #35706:
URL: https://github.com/apache/spark/pull/35706#discussion_r820448734
##########
File path: python/pyspark/pandas/tests/test_series.py
##########
@@ -1161,13 +1161,36 @@ def test_append(self):
def test_map(self):
pser = pd.Series(["cat", "dog", None, "rabbit"])
psser = ps.from_pandas(pser)
- # Currently Koalas doesn't return NaN as pandas does.
- self.assert_eq(psser.map({}), pser.map({}).replace({pd.np.nan: None}))
+
+ # dict correspondence
+ # Currently pandas API on Spark doesn't return NaN as pandas does.
+ self.assert_eq(psser.map({}), pser.map({}).replace({np.nan: None}))
d = defaultdict(lambda: "abc")
self.assertTrue("abc" in repr(psser.map(d)))
self.assert_eq(psser.map(d), pser.map(d))
+ # series correspondence
+ pser_to_apply = pd.Series(["one", "two", "four"], index=["cat", "dog",
"rabbit"])
+ self.assert_eq(psser.map(pser_to_apply), pser.map(pser_to_apply))
+ self.assert_eq(
+ psser.map(pser_to_apply, na_action="ignore"),
+ pser.map(pser_to_apply, na_action="ignore"),
+ )
+
+ # function correspondence
+ self.assert_eq(
+ psser.map(lambda x: x.upper(), na_action="ignore"),
+ pser.map(lambda x: x.upper(), na_action="ignore"),
+ )
+
+ def to_upper(string) -> str:
+ return string.upper() if string else ""
+
+ self.assert_eq(
+ psser.map(to_upper), pser.map(to_upper),
+ )
Review comment:
Good catch! Thanks :)
--
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]