Skip to content

Commit e8f9d27

Browse files
committed
TST: test series.map on Counter & defaultdict
1 parent 614a48e commit e8f9d27

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pandas/tests/series/test_apply.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding=utf-8
22
# pylint: disable-msg=E1101,W0612
33

4-
from collections import OrderedDict
4+
from collections import Counter, defaultdict, OrderedDict
55
import numpy as np
66
import pandas as pd
77

@@ -411,6 +411,23 @@ def test_map_dict_with_tuple_keys(self):
411411
tm.assert_series_equal(df['labels'], df['expected_labels'],
412412
check_names=False)
413413

414+
def test_map_counter(self):
415+
s = Series(['a', 'b', 'c'], index=[1, 2, 3])
416+
counter = Counter()
417+
counter['b'] = 5
418+
counter['c'] += 1
419+
result = s.map(counter)
420+
expected = Series([0, 5, 1], index=[1, 2, 3])
421+
assert_series_equal(result, expected)
422+
423+
def test_map_defaultdict(self):
424+
s = Series([1, 2, 3], index=['a', 'b', 'c'])
425+
default_dict = defaultdict(lambda: 'blank')
426+
default_dict[1] = 'stuff'
427+
result = s.map(default_dict)
428+
expected = Series(['stuff', 'blank', 'blank'], index=['a', 'b', 'c'])
429+
assert_series_equal(result, expected)
430+
414431
def test_map_box(self):
415432
vals = [pd.Timestamp('2011-01-01'), pd.Timestamp('2011-01-02')]
416433
s = pd.Series(vals)

0 commit comments

Comments
 (0)