forked from pandas-dev/pandas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_to_dict.py
38 lines (31 loc) · 1.14 KB
/
test_to_dict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import collections
import numpy as np
import pytest
from pandas import Series
import pandas._testing as tm
class TestSeriesToDict:
@pytest.mark.parametrize(
"mapping", (dict, collections.defaultdict(list), collections.OrderedDict)
)
def test_to_dict(self, mapping, datetime_series):
# GH#16122
result = Series(datetime_series.to_dict(mapping), name="ts")
expected = datetime_series.copy()
expected.index = expected.index._with_freq(None)
tm.assert_series_equal(result, expected)
from_method = Series(datetime_series.to_dict(collections.Counter))
from_constructor = Series(collections.Counter(datetime_series.items()))
tm.assert_series_equal(from_method, from_constructor)
@pytest.mark.parametrize(
"input",
(
{"a": np.int64(64), "b": 10},
{"a": np.int64(64), "b": 10, "c": "ABC"},
{"a": np.uint64(64), "b": 10, "c": "ABC"},
),
)
def test_to_dict_return_types(self, input):
# GH25969
d = Series(input).to_dict()
assert isinstance(d["a"], int)
assert isinstance(d["b"], int)