|
8 | 8 | from pandas.core.arrays.timedeltas import TimedeltaArray |
9 | 9 | from pandas.core.frame import DataFrame |
10 | 10 | from pandas.core.indexes.accessors import ( |
| 11 | + CombinedDatetimelikeProperties, |
11 | 12 | DatetimeProperties, |
12 | 13 | PeriodProperties, |
13 | | - Properties, |
14 | 14 | TimedeltaProperties, |
15 | 15 | ) |
16 | 16 | from pandas.core.indexes.interval import interval_range |
@@ -49,12 +49,37 @@ def test_property_dt() -> None: |
49 | 49 | PeriodProperties, |
50 | 50 | ) |
51 | 51 |
|
| 52 | + df = DataFrame({"ts": [Timestamp(2025, 12, 6)], "td": [Timedelta(1, "s")]}) |
| 53 | + # python/mypy#19952: mypy gives Any |
| 54 | + check( |
| 55 | + assert_type( # type: ignore[assert-type] |
| 56 | + df["ts"].dt, CombinedDatetimelikeProperties |
| 57 | + ), |
| 58 | + DatetimeProperties, |
| 59 | + ) |
| 60 | + check( |
| 61 | + assert_type( # type: ignore[assert-type] |
| 62 | + df["td"].dt, CombinedDatetimelikeProperties |
| 63 | + ), |
| 64 | + TimedeltaProperties, |
| 65 | + ) |
| 66 | + |
| 67 | + check( |
| 68 | + assert_type(df["ts"].dt.year, "Series[int]"), # type: ignore[assert-type] |
| 69 | + Series, |
| 70 | + np.integer, |
| 71 | + ) |
| 72 | + check( |
| 73 | + assert_type( # type: ignore[assert-type] |
| 74 | + df["td"].dt.total_seconds(), "Series[float]" |
| 75 | + ), |
| 76 | + Series, |
| 77 | + np.floating, |
| 78 | + ) |
| 79 | + |
52 | 80 | if TYPE_CHECKING_INVALID_USAGE: |
53 | | - s = DataFrame({"a": [1]})["a"] |
54 | | - # python/mypy#19952: mypy believes Properties and its subclasses have a |
55 | | - # conflict and gives Any for s.dt |
56 | | - assert_type(s.dt, Properties) # type: ignore[assert-type] |
57 | | - _1 = Series([1]).dt # type: ignore[arg-type] # pyright: ignore[reportAttributeAccessIssue] |
| 81 | + _0 = Series([1]).dt # type: ignore[arg-type] # pyright: ignore[reportAttributeAccessIssue] |
| 82 | + _1 = Series(["2025-01-01"]).dt # type: ignore[arg-type] # pyright: ignore[reportAttributeAccessIssue] |
58 | 83 |
|
59 | 84 |
|
60 | 85 | def test_property_array() -> None: |
|
0 commit comments