@@ -3230,3 +3230,47 @@ def test_operator_constistency() -> None:
3230
3230
pd .Series ,
3231
3231
pd .Timedelta ,
3232
3232
)
3233
+
3234
+
3235
+ def test_map () -> None :
3236
+ s = pd .Series ([1 , 2 , 3 ])
3237
+
3238
+ mapping = {1 : "a" , 2 : "b" , 3 : "c" }
3239
+ check (
3240
+ assert_type (s .map (mapping , na_action = "ignore" ), "pd.Series[str]" ),
3241
+ pd .Series ,
3242
+ str ,
3243
+ )
3244
+
3245
+ def callable (x : int ) -> str :
3246
+ return str (x )
3247
+
3248
+ check (
3249
+ assert_type (s .map (callable , na_action = "ignore" ), "pd.Series[str]" ),
3250
+ pd .Series ,
3251
+ str ,
3252
+ )
3253
+
3254
+ series = pd .Series (["a" , "b" , "c" ])
3255
+ check (
3256
+ assert_type (s .map (series , na_action = "ignore" ), "pd.Series[str]" ), pd .Series , str
3257
+ )
3258
+
3259
+
3260
+ def test_map_na () -> None :
3261
+ s : pd .Series [int ] = pd .Series ([1 , pd .NA , 3 ])
3262
+
3263
+ mapping = {1 : "a" , 2 : "b" , 3 : "c" }
3264
+ check (assert_type (s .map (mapping , na_action = None ), "pd.Series[str]" ), pd .Series , str )
3265
+
3266
+ def callable (x : int | NAType ) -> str | NAType :
3267
+ if isinstance (x , int ):
3268
+ return str (x )
3269
+ return x
3270
+
3271
+ check (
3272
+ assert_type (s .map (callable , na_action = None ), "pd.Series[str]" ), pd .Series , str
3273
+ )
3274
+
3275
+ series = pd .Series (["a" , "b" , "c" ])
3276
+ check (assert_type (s .map (series , na_action = None ), "pd.Series[str]" ), pd .Series , str )
0 commit comments