|
8 | 8 | from pandas._libs import iNaT, lib |
9 | 9 |
|
10 | 10 | from pandas.core.dtypes.common import is_categorical_dtype, is_datetime64tz_dtype |
11 | | -from pandas.core.dtypes.dtypes import CategoricalDtype |
| 11 | +from pandas.core.dtypes.dtypes import ( |
| 12 | + CategoricalDtype, |
| 13 | + DatetimeTZDtype, |
| 14 | + IntervalDtype, |
| 15 | + PeriodDtype, |
| 16 | +) |
12 | 17 |
|
13 | 18 | import pandas as pd |
14 | 19 | from pandas import ( |
15 | 20 | Categorical, |
16 | 21 | DataFrame, |
17 | 22 | Index, |
| 23 | + Interval, |
18 | 24 | IntervalIndex, |
19 | 25 | MultiIndex, |
20 | 26 | NaT, |
| 27 | + Period, |
21 | 28 | Series, |
22 | 29 | Timestamp, |
23 | 30 | date_range, |
@@ -1075,6 +1082,26 @@ def test_constructor_dict_order(self): |
1075 | 1082 | expected = Series([1, 0, 2], index=list("bac")) |
1076 | 1083 | tm.assert_series_equal(result, expected) |
1077 | 1084 |
|
| 1085 | + @pytest.mark.parametrize( |
| 1086 | + "data,dtype", |
| 1087 | + [ |
| 1088 | + (Period("2020-01"), PeriodDtype("M")), |
| 1089 | + (Interval(left=0, right=5), IntervalDtype("int64")), |
| 1090 | + ( |
| 1091 | + Timestamp("2011-01-01", tz="US/Eastern"), |
| 1092 | + DatetimeTZDtype(tz="US/Eastern"), |
| 1093 | + ), |
| 1094 | + ], |
| 1095 | + ) |
| 1096 | + def test_constructor_dict_extension(self, data, dtype): |
| 1097 | + d = {"a": data} |
| 1098 | + result = Series(d, index=["a"]) |
| 1099 | + expected = Series(data, index=["a"], dtype=dtype) |
| 1100 | + |
| 1101 | + assert result.dtype == dtype |
| 1102 | + |
| 1103 | + tm.assert_series_equal(result, expected) |
| 1104 | + |
1078 | 1105 | @pytest.mark.parametrize("value", [2, np.nan, None, float("nan")]) |
1079 | 1106 | def test_constructor_dict_nan_key(self, value): |
1080 | 1107 | # GH 18480 |
|
0 commit comments