Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix test formatting and following project development work flow
- establish the current poetry environment and run a complete test suite
- Use the check (assrt_Type (...)) pattern required by project standards
- Fix import order and code formatting through preset hook
- All tests and type of chips now passionally pass
  • Loading branch information
gamal1osama committed Sep 17, 2025
commit 63a966fc4386d55cf690e87ea0cc8e26bbc7df8e
2 changes: 1 addition & 1 deletion pandas-stubs/core/indexes/datetimes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class DatetimeIndex(
# Override the array property to return DatetimeArray instead of ExtensionArray
@property
def array(self) -> DatetimeArray: ...

# various ignores needed for mypy, as we do want to restrict what can be used in
# arithmetic for these types
@overload # type: ignore[override]
Expand Down
16 changes: 7 additions & 9 deletions tests/indexes/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
import numpy as np
from numpy import typing as npt
import pandas as pd
from pandas.core.arrays import DatetimeArray
from pandas.core.arrays.categorical import Categorical
from pandas.core.indexes.base import Index
from pandas.core.arrays import DatetimeArray
from typing import assert_type
from typing_extensions import (
Never,
assert_type,
Expand Down Expand Up @@ -1520,13 +1519,12 @@ def test_period_index_asof_locs() -> None:
)


def test_datetime_index_array_property():
def test_datetime_index_array_property() -> None:
"""Test that DatetimeIndex.array returns DatetimeArray instead of ExtensionArray."""
# Test with to_datetime
# Test with pd.to_datetime().array - this is the main issue reported
arr = pd.to_datetime(["2020-01-01", "2020-01-02"]).array
assert_type(arr, DatetimeArray)
# Test with DatetimeIndex directly
check(assert_type(arr, DatetimeArray), DatetimeArray)

# Test with DatetimeIndex constructor directly
dt_index = pd.DatetimeIndex(["2020-01-01", "2020-01-02"])
assert_type(dt_index.array, DatetimeArray)

check(assert_type(dt_index.array, DatetimeArray), DatetimeArray)
Loading