Skip to content

Commit f7a0921

Browse files
committed
1 parent 67a1748 commit f7a0921

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

pandas-stubs/core/indexes/accessors.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,9 @@ class TimedeltaIndexProperties(
444444
@type_check_only
445445
class DtDescriptor:
446446
@overload
447-
def __get__(self, instance: Series[Never], owner: type[Series]) -> Properties: ...
447+
def __get__(
448+
self, instance: Series[Never], owner: type[Series]
449+
) -> TimestampProperties | TimedeltaProperties | PeriodProperties: ...
448450
@overload
449451
def __get__(
450452
self, instance: Series[Timestamp], owner: type[Series]

tests/series/test_properties.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from pandas.core.indexes.accessors import (
1111
DatetimeProperties,
1212
PeriodProperties,
13-
Properties,
1413
TimedeltaProperties,
1514
)
1615
from pandas.core.indexes.interval import interval_range
@@ -49,12 +48,24 @@ def test_property_dt() -> None:
4948
PeriodProperties,
5049
)
5150

51+
df = DataFrame({"ts": [Timestamp(2025, 12, 6)], "td": [Timedelta(1, "s")]})
52+
# python/mypy#19952: mypy gives Any
53+
check(
54+
assert_type( # type: ignore[assert-type]
55+
df["ts"].dt, "TimestampProperties | TimedeltaProperties | PeriodProperties"
56+
),
57+
DatetimeProperties,
58+
)
59+
check(
60+
assert_type( # type: ignore[assert-type]
61+
df["td"].dt, "TimestampProperties | TimedeltaProperties | PeriodProperties"
62+
),
63+
TimedeltaProperties,
64+
)
65+
5266
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]
67+
_0 = Series([1]).dt # type: ignore[arg-type] # pyright: ignore[reportAttributeAccessIssue]
68+
_1 = Series(["2025-01-01"]).dt # type: ignore[arg-type] # pyright: ignore[reportAttributeAccessIssue]
5869

5970

6071
def test_property_array() -> None:

0 commit comments

Comments
 (0)