|
1 |
| -from collections import Counter, OrderedDict, abc, defaultdict |
| 1 | +from collections import Counter, OrderedDict, defaultdict |
2 | 2 | from itertools import chain
|
3 | 3 |
|
4 | 4 | import numpy as np
|
@@ -612,46 +612,21 @@ class DictWithoutMissing(dict):
|
612 | 612 | def test_map_abc_mapping(self):
|
613 | 613 | # https://github.com/pandas-dev/pandas/issues/29733
|
614 | 614 | # Check collections.abc.Mapping support as mapper for Series.map
|
615 |
| - class NonDictMapping(abc.Mapping): |
616 |
| - def __init__(self): |
617 |
| - self._data = {3: "three"} |
618 |
| - |
619 |
| - def __getitem__(self, key): |
620 |
| - return self._data.__getitem__(key) |
621 |
| - |
622 |
| - def __iter__(self): |
623 |
| - return self._data.__iter__() |
624 |
| - |
625 |
| - def __len__(self): |
626 |
| - return self._data.__len__() |
627 |
| - |
628 | 615 | s = Series([1, 2, 3])
|
629 |
| - not_a_dictionary = NonDictMapping() |
| 616 | + not_a_dictionary = tm.TestNonDictMapping({3: "three"}) |
630 | 617 | result = s.map(not_a_dictionary)
|
631 | 618 | expected = Series([np.nan, np.nan, "three"])
|
632 | 619 | tm.assert_series_equal(result, expected)
|
633 | 620 |
|
634 | 621 | def test_map_abc_mapping_with_missing(self):
|
635 | 622 | # https://github.com/pandas-dev/pandas/issues/29733
|
636 | 623 | # Check collections.abc.Mapping support as mapper for Series.map
|
637 |
| - class NonDictMappingWithMissing(abc.Mapping): |
638 |
| - def __init__(self): |
639 |
| - self._data = {3: "three"} |
640 |
| - |
641 |
| - def __getitem__(self, key): |
642 |
| - return self._data.__getitem__(key) |
643 |
| - |
644 |
| - def __iter__(self): |
645 |
| - return self._data.__iter__() |
646 |
| - |
647 |
| - def __len__(self): |
648 |
| - return self._data.__len__() |
649 |
| - |
| 624 | + class NonDictMappingWithMissing(tm.TestNonDictMapping): |
650 | 625 | def __missing__(self, key):
|
651 | 626 | return "missing"
|
652 | 627 |
|
653 | 628 | s = Series([1, 2, 3])
|
654 |
| - not_a_dictionary = NonDictMappingWithMissing() |
| 629 | + not_a_dictionary = NonDictMappingWithMissing({3: "three"}) |
655 | 630 | result = s.map(not_a_dictionary)
|
656 | 631 | # __missing__ is a dict concept, not a Mapping concept,
|
657 | 632 | # so it should not change the result!
|
|
0 commit comments