Skip to content

Commit fc98bcb

Browse files
committed
TST - Added a test for Series.map with dict-like (abc.Mapping) mapper
1 parent 969b4f9 commit fc98bcb

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

pandas/tests/series/test_apply.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections import Counter, OrderedDict, defaultdict
1+
from collections import Counter, OrderedDict, defaultdict, abc
22
from itertools import chain
33

44
import numpy as np
@@ -609,6 +609,26 @@ class DictWithoutMissing(dict):
609609
expected = Series([np.nan, np.nan, "three"])
610610
tm.assert_series_equal(result, expected)
611611

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+
612632
def test_map_box(self):
613633
vals = [pd.Timestamp("2011-01-01"), pd.Timestamp("2011-01-02")]
614634
s = pd.Series(vals)

0 commit comments

Comments
 (0)