Closed
Description
Describe the bug
When I form the intersection
of two pd.DatetimeIndex
, the return type is Index
. This leads to problems with index entries: mypy complains about intersection[0].date()
.
To Reproduce
- Minimal example
import pandas as pd
intersection = pd.DatetimeIndex().intersection(pd.DatetimeIndex)
reveal_type(intersection) # Index
reveal_type(intersection[0]) # "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex"
-
mypy
-
error message
agri_data/utils.py:96: error: Item "str" of "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex" has no attribute "date" [union-attr]
agri_data/utils.py:96: error: Item "bytes" of "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex" has no attribute "date" [union-attr]
agri_data/utils.py:96: error: Item "date" of "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex" has no attribute "date" [union-attr]
agri_data/utils.py:96: error: Item "timedelta" of "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex" has no attribute "date" [union-attr]
agri_data/utils.py:96: error: Item "datetime64" of "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex" has no attribute "date" [union-attr]
agri_data/utils.py:96: error: Item "timedelta64" of "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex" has no attribute "date" [union-attr]
agri_data/utils.py:96: error: Item "bool" of "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex" has no attribute "date" [union-attr]
agri_data/utils.py:96: error: Item "int" of "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex" has no attribute "date" [union-attr]
agri_data/utils.py:96: error: Item "float" of "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex" has no attribute "date" [union-attr]
agri_data/utils.py:96: error: Item "Timedelta" of "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex" has no attribute "date" [union-attr]
agri_data/utils.py:96: error: Item "complex" of "str | bytes | date | datetime | timedelta | datetime64 | timedelta64 | bool | int | float | Timestamp | Timedelta | complex" has no attribute "date" [union-attr]
- Expected type:
reveal_type(intersection[0]) # Timestamp
Please complete the following information:
- OS: Ubuntu
- OS Version: bullseye
- python version: 3.11.1
- version of type checker: 1.2.0
- version of installed
pandas-stubs
: 2.0.2.230605
Additional context
Possibly related: #723