|
3 | 3 | import pandas.core.dtypes.concat as _concat |
4 | 4 |
|
5 | 5 | import pandas as pd |
6 | | -from pandas import DatetimeIndex, Period, PeriodIndex, Series, TimedeltaIndex |
| 6 | +from pandas import Series |
7 | 7 | import pandas._testing as tm |
8 | 8 |
|
9 | 9 |
|
10 | | -@pytest.mark.parametrize( |
11 | | - "to_concat, expected", |
12 | | - [ |
13 | | - # int/float/str |
14 | | - ([["a"], [1, 2]], ["i", "object"]), |
15 | | - ([[3, 4], [1, 2]], ["i"]), |
16 | | - ([[3, 4], [1, 2.1]], ["i", "f"]), |
17 | | - # datetimelike |
18 | | - ([DatetimeIndex(["2011-01-01"]), DatetimeIndex(["2011-01-02"])], ["datetime"]), |
19 | | - ([TimedeltaIndex(["1 days"]), TimedeltaIndex(["2 days"])], ["timedelta"]), |
20 | | - # datetimelike object |
21 | | - ( |
22 | | - [ |
23 | | - DatetimeIndex(["2011-01-01"]), |
24 | | - DatetimeIndex(["2011-01-02"], tz="US/Eastern"), |
25 | | - ], |
26 | | - ["datetime", "datetime64[ns, US/Eastern]"], |
27 | | - ), |
28 | | - ( |
29 | | - [ |
30 | | - DatetimeIndex(["2011-01-01"], tz="Asia/Tokyo"), |
31 | | - DatetimeIndex(["2011-01-02"], tz="US/Eastern"), |
32 | | - ], |
33 | | - ["datetime64[ns, Asia/Tokyo]", "datetime64[ns, US/Eastern]"], |
34 | | - ), |
35 | | - ([TimedeltaIndex(["1 days"]), TimedeltaIndex(["2 hours"])], ["timedelta"]), |
36 | | - ( |
37 | | - [ |
38 | | - DatetimeIndex(["2011-01-01"], tz="Asia/Tokyo"), |
39 | | - TimedeltaIndex(["1 days"]), |
40 | | - ], |
41 | | - ["datetime64[ns, Asia/Tokyo]", "timedelta"], |
42 | | - ), |
43 | | - ], |
44 | | -) |
45 | | -def test_get_dtype_kinds(index_or_series, to_concat, expected): |
46 | | - to_concat_klass = [index_or_series(c) for c in to_concat] |
47 | | - result = _concat._get_dtype_kinds(to_concat_klass) |
48 | | - assert result == set(expected) |
49 | | - |
50 | | - |
51 | | -@pytest.mark.parametrize( |
52 | | - "to_concat, expected", |
53 | | - [ |
54 | | - ( |
55 | | - [PeriodIndex(["2011-01"], freq="M"), PeriodIndex(["2011-01"], freq="M")], |
56 | | - ["period[M]"], |
57 | | - ), |
58 | | - ( |
59 | | - [ |
60 | | - Series([Period("2011-01", freq="M")]), |
61 | | - Series([Period("2011-02", freq="M")]), |
62 | | - ], |
63 | | - ["period[M]"], |
64 | | - ), |
65 | | - ( |
66 | | - [PeriodIndex(["2011-01"], freq="M"), PeriodIndex(["2011-01"], freq="D")], |
67 | | - ["period[M]", "period[D]"], |
68 | | - ), |
69 | | - ( |
70 | | - [ |
71 | | - Series([Period("2011-01", freq="M")]), |
72 | | - Series([Period("2011-02", freq="D")]), |
73 | | - ], |
74 | | - ["period[M]", "period[D]"], |
75 | | - ), |
76 | | - ], |
77 | | -) |
78 | | -def test_get_dtype_kinds_period(to_concat, expected): |
79 | | - result = _concat._get_dtype_kinds(to_concat) |
80 | | - assert result == set(expected) |
81 | | - |
82 | | - |
83 | 10 | def test_concat_mismatched_categoricals_with_empty(): |
84 | 11 | # concat_compat behavior on series._values should match pd.concat on series |
85 | 12 | ser1 = Series(["a", "b", "c"], dtype="category") |
|
0 commit comments