Skip to content

Commit a383fbe

Browse files
committed
Merge branch 'main' into hotfix/cmp0xff/1372-cumprod
2 parents 78e240a + c98adb3 commit a383fbe

File tree

5 files changed

+55
-3
lines changed

5 files changed

+55
-3
lines changed

pandas-stubs/core/frame.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,9 @@ class DataFrame(NDFrame, OpsMixin, _GetItemHack):
549549
| Mapping[str, Any]
550550
| Mapping[str, SequenceNotStr[Any]]
551551
),
552-
index: str | SequenceNotStr[Hashable] | None = None,
553-
columns: ListLike | None = None,
552+
index: str | Axes | None = None,
554553
exclude: ListLike | None = None,
554+
columns: ListLike | None = None,
555555
coerce_float: bool = False,
556556
nrows: int | None = None,
557557
) -> Self: ...

pandas-stubs/core/indexes/datetimes.pyi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ from pandas import (
2020
TimedeltaIndex,
2121
Timestamp,
2222
)
23+
from pandas.core.arrays import DatetimeArray
2324
from pandas.core.indexes.accessors import DatetimeIndexProperties
2425
from pandas.core.indexes.datetimelike import DatetimeTimedeltaMixin
2526
from pandas.core.series import (
@@ -61,6 +62,11 @@ class DatetimeIndex(
6162
name: Hashable = ...,
6263
) -> Self: ...
6364
def __reduce__(self): ...
65+
66+
# Override the array property to return DatetimeArray instead of ExtensionArray
67+
@property
68+
def array(self) -> DatetimeArray: ...
69+
6470
# various ignores needed for mypy, as we do want to restrict what can be used in
6571
# arithmetic for these types
6672
@overload # type: ignore[override]

tests/indexes/test_indexes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import numpy as np
1313
from numpy import typing as npt
1414
import pandas as pd
15+
from pandas.core.arrays import DatetimeArray
1516
from pandas.core.arrays.categorical import Categorical
1617
from pandas.core.indexes.base import Index
1718
from typing_extensions import (
@@ -1516,3 +1517,14 @@ def test_period_index_asof_locs() -> None:
15161517
assert_type(idx.asof_locs(where, mask), np_1darray[np.intp]),
15171518
np_1darray[np.intp],
15181519
)
1520+
1521+
1522+
def test_datetime_index_array_property() -> None:
1523+
"""Test that DatetimeIndex.array returns DatetimeArray instead of ExtensionArray."""
1524+
# Test with pd.to_datetime().array - this is the main issue reported
1525+
arr = pd.to_datetime(["2020-01-01", "2020-01-02"]).array
1526+
check(assert_type(arr, DatetimeArray), DatetimeArray)
1527+
1528+
# Test with DatetimeIndex constructor directly
1529+
dt_index = pd.DatetimeIndex(["2020-01-01", "2020-01-02"])
1530+
check(assert_type(dt_index.array, DatetimeArray), DatetimeArray)

tests/series/test_cumul.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
)
99

1010

11-
def test_cumul_any_int() -> None:
11+
def test_cumul_any_float() -> None:
1212
series = pd.DataFrame({"A": [1.0, float("nan"), 2.0]})["A"]
1313
check(assert_type(series.cumprod(), pd.Series), pd.Series, np.floating)
1414

tests/test_frame.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4815,6 +4815,40 @@ def test_from_records() -> None:
48154815
pd.DataFrame,
48164816
)
48174817

4818+
# GH1358
4819+
data, py_l = [[1, 2, 3], [4, 5, 6]], ["a", "b"]
4820+
4821+
check(
4822+
assert_type(pd.DataFrame.from_records(data, pd.Index(py_l)), pd.DataFrame),
4823+
pd.DataFrame,
4824+
)
4825+
check(
4826+
assert_type(pd.DataFrame.from_records(data, pd.Series(py_l)), pd.DataFrame),
4827+
pd.DataFrame,
4828+
)
4829+
check(
4830+
assert_type(
4831+
pd.DataFrame.from_records(data, pd.Series(py_l).array), pd.DataFrame
4832+
),
4833+
pd.DataFrame,
4834+
)
4835+
check(
4836+
assert_type(
4837+
pd.DataFrame.from_records(data, pd.Series(py_l).values), pd.DataFrame
4838+
),
4839+
pd.DataFrame,
4840+
)
4841+
check(
4842+
assert_type(pd.DataFrame.from_records(data, np.asarray(py_l)), pd.DataFrame),
4843+
pd.DataFrame,
4844+
)
4845+
check(
4846+
assert_type(
4847+
pd.DataFrame.from_records(data, np.asarray(py_l, np.str_)), pd.DataFrame
4848+
),
4849+
pd.DataFrame,
4850+
)
4851+
48184852

48194853
def test_frame_index_setter() -> None:
48204854
"""Test DataFrame.index setter property GH1366."""

0 commit comments

Comments
 (0)