14
14
Index ,
15
15
MultiIndex ,
16
16
Series ,
17
+ bdate_range ,
17
18
isna ,
18
19
timedelta_range ,
19
20
)
@@ -154,8 +155,13 @@ def test_list_raises(string_series):
154
155
string_series .map ([lambda x : x ])
155
156
156
157
157
- def test_map (datetime_series ):
158
- index , data = tm .getMixedTypeDict ()
158
+ def test_map ():
159
+ data = {
160
+ "A" : [0.0 , 1.0 , 2.0 , 3.0 , 4.0 ],
161
+ "B" : [0.0 , 1.0 , 0.0 , 1.0 , 0.0 ],
162
+ "C" : ["foo1" , "foo2" , "foo3" , "foo4" , "foo5" ],
163
+ "D" : bdate_range ("1/1/2009" , periods = 5 ),
164
+ }
159
165
160
166
source = Series (data ["B" ], index = data ["C" ])
161
167
target = Series (data ["C" ][:4 ], index = data ["D" ][:4 ])
@@ -171,10 +177,14 @@ def test_map(datetime_series):
171
177
for k , v in merged .items ():
172
178
assert v == source [target [k ]]
173
179
180
+
181
+ def test_map_datetime (datetime_series ):
174
182
# function
175
183
result = datetime_series .map (lambda x : x * 2 )
176
184
tm .assert_series_equal (result , datetime_series * 2 )
177
185
186
+
187
+ def test_map_category ():
178
188
# GH 10324
179
189
a = Series ([1 , 2 , 3 , 4 ])
180
190
b = Series (["even" , "odd" , "even" , "odd" ], dtype = "category" )
@@ -185,6 +195,8 @@ def test_map(datetime_series):
185
195
exp = Series (["odd" , "even" , "odd" , np .nan ])
186
196
tm .assert_series_equal (a .map (c ), exp )
187
197
198
+
199
+ def test_map_category_numeric ():
188
200
a = Series (["a" , "b" , "c" , "d" ])
189
201
b = Series ([1 , 2 , 3 , 4 ], index = pd .CategoricalIndex (["b" , "c" , "d" , "e" ]))
190
202
c = Series ([1 , 2 , 3 , 4 ], index = Index (["b" , "c" , "d" , "e" ]))
@@ -194,6 +206,8 @@ def test_map(datetime_series):
194
206
exp = Series ([np .nan , 1 , 2 , 3 ])
195
207
tm .assert_series_equal (a .map (c ), exp )
196
208
209
+
210
+ def test_map_category_string ():
197
211
a = Series (["a" , "b" , "c" , "d" ])
198
212
b = Series (
199
213
["B" , "C" , "D" , "E" ],
0 commit comments