File tree 1 file changed +21
-1
lines changed
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 1
- from collections import Counter , OrderedDict , defaultdict
1
+ from collections import Counter , OrderedDict , defaultdict , abc
2
2
from itertools import chain
3
3
4
4
import numpy as np
@@ -609,6 +609,26 @@ class DictWithoutMissing(dict):
609
609
expected = Series ([np .nan , np .nan , "three" ])
610
610
tm .assert_series_equal (result , expected )
611
611
612
+ def test_map_abc_mapping (self ):
613
+ class NonDictMapping (abc .Mapping ):
614
+ def __init__ (self ):
615
+ self ._data = {3 : "three" }
616
+
617
+ def __getitem__ (self , key ):
618
+ return self ._data .__getitem__ (key )
619
+
620
+ def __iter__ (self ):
621
+ return self ._data .__iter__ ()
622
+
623
+ def __len__ (self ):
624
+ return self ._data .__len__ ()
625
+
626
+ s = Series ([1 , 2 , 3 ])
627
+ not_a_dictionary = NonDictMapping ()
628
+ result = s .map (not_a_dictionary )
629
+ expected = Series ([np .nan , np .nan , "three" ])
630
+ tm .assert_series_equal (result , expected )
631
+
612
632
def test_map_box (self ):
613
633
vals = [pd .Timestamp ("2011-01-01" ), pd .Timestamp ("2011-01-02" )]
614
634
s = pd .Series (vals )
You can’t perform that action at this time.
0 commit comments