-
-
Notifications
You must be signed in to change notification settings - Fork 150
feat(array): #624 accumulate #1400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Dr-Irv
merged 4 commits into
pandas-dev:main
from
cmp0xff:feature/cmp0xff/624-extension-array-accumulate
Oct 3, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from pandas.core.arrays.integer import IntegerArray | ||
from pandas.core.construction import array | ||
from typing_extensions import assert_type | ||
|
||
from pandas._libs.missing import NA | ||
|
||
from tests import check | ||
|
||
|
||
def test_construction() -> None: | ||
check(assert_type(array([1]), IntegerArray), IntegerArray) | ||
check(assert_type(array([1, NA]), IntegerArray), IntegerArray) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from pandas.core.arrays.integer import IntegerArray | ||
from pandas.core.construction import array | ||
from typing_extensions import assert_type | ||
|
||
from pandas._libs.missing import NA | ||
|
||
from tests import check | ||
|
||
|
||
def test_cumul_int64dtype() -> None: | ||
arr = array([1, NA, 2]) | ||
|
||
check(assert_type(arr._accumulate("cummin"), IntegerArray), IntegerArray) | ||
check(assert_type(arr._accumulate("cummax"), IntegerArray), IntegerArray) | ||
check(assert_type(arr._accumulate("cumsum"), IntegerArray), IntegerArray) | ||
check(assert_type(arr._accumulate("cumprod"), IntegerArray), IntegerArray) | ||
|
||
check( | ||
assert_type(arr._accumulate("cummin", skipna=False), IntegerArray), | ||
IntegerArray, | ||
) | ||
check( | ||
assert_type(arr._accumulate("cummax", skipna=False), IntegerArray), | ||
IntegerArray, | ||
) | ||
check( | ||
assert_type(arr._accumulate("cumsum", skipna=False), IntegerArray), | ||
IntegerArray, | ||
) | ||
check( | ||
assert_type(arr._accumulate("cumprod", skipna=False), IntegerArray), | ||
IntegerArray, | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
from typing import ( | ||
TYPE_CHECKING, | ||
cast, | ||
) | ||
|
||
import numpy as np | ||
import pandas as pd | ||
from pandas.core.arrays import DatetimeArray | ||
from pandas.core.arrays.base import ExtensionArray | ||
from pandas.core.arrays.categorical import Categorical | ||
from pandas.core.arrays.integer import ( | ||
Int64Dtype, | ||
IntegerArray, | ||
) | ||
from pandas.core.arrays.interval import IntervalArray | ||
from pandas.core.arrays.timedeltas import TimedeltaArray | ||
from pandas.core.frame import DataFrame | ||
from pandas.core.indexes.accessors import ( | ||
DatetimeProperties, | ||
PeriodProperties, | ||
Properties, | ||
TimedeltaProperties, | ||
) | ||
from pandas.core.indexes.interval import interval_range | ||
from pandas.core.indexes.period import period_range | ||
from pandas.core.series import Series | ||
from typing_extensions import assert_type | ||
|
||
from pandas._libs.interval import Interval | ||
from pandas._libs.missing import NA | ||
from pandas._libs.tslibs.timedeltas import Timedelta | ||
from pandas._libs.tslibs.timestamps import Timestamp | ||
|
||
from tests import ( | ||
TYPE_CHECKING_INVALID_USAGE, | ||
check, | ||
|
@@ -25,58 +39,61 @@ | |
from pandas.core.indexes.accessors import TimestampProperties # noqa: F401 | ||
|
||
|
||
def test_dt_property() -> None: | ||
def test_property_dt() -> None: | ||
"""Test the Series.dt property""" | ||
check( | ||
assert_type(pd.Series([pd.Timestamp(2025, 9, 28)]).dt, "TimestampProperties"), | ||
assert_type(Series([Timestamp(2025, 9, 28)]).dt, "TimestampProperties"), | ||
DatetimeProperties, | ||
) | ||
check( | ||
assert_type(pd.Series([pd.Timedelta(1, "s")]).dt, TimedeltaProperties), | ||
assert_type(Series([Timedelta(1, "s")]).dt, TimedeltaProperties), | ||
TimedeltaProperties, | ||
) | ||
check( | ||
assert_type( | ||
pd.period_range(start="2022-06-01", periods=10).to_series().dt, | ||
period_range(start="2022-06-01", periods=10).to_series().dt, | ||
PeriodProperties, | ||
), | ||
PeriodProperties, | ||
) | ||
|
||
if TYPE_CHECKING_INVALID_USAGE: | ||
s = pd.DataFrame({"a": [1]})["a"] | ||
s = DataFrame({"a": [1]})["a"] | ||
# python/mypy#19952: mypy believes Properties and its subclasses have a | ||
# conflict and gives Any for s.dt | ||
assert_type(s.dt, Properties) # type: ignore[assert-type] | ||
_1 = pd.Series([1]).dt # type: ignore[arg-type] # pyright: ignore[reportAttributeAccessIssue] | ||
_1 = Series([1]).dt # type: ignore[arg-type] # pyright: ignore[reportAttributeAccessIssue] | ||
|
||
|
||
def test_array_property() -> None: | ||
def test_property_array() -> None: | ||
"""Test that Series.array returns ExtensionArray and its subclasses""" | ||
check( | ||
assert_type(Series([1], dtype="category").array, Categorical), Categorical, int | ||
) | ||
# cast will be removed if pandas-dev/pandas-stubs#1395 is resolved | ||
check( | ||
assert_type( | ||
pd.Series([1], dtype="category").array, | ||
pd.Categorical, | ||
cast("Series[Int64Dtype]", Series([1, NA], dtype="Int64")).array, | ||
|
||
IntegerArray, | ||
), | ||
pd.Categorical, | ||
int, | ||
IntegerArray, | ||
) | ||
check( | ||
assert_type(pd.Series(pd.interval_range(0, 1)).array, IntervalArray), | ||
assert_type(Series(interval_range(0, 1)).array, IntervalArray), | ||
IntervalArray, | ||
pd.Interval, | ||
Interval, | ||
) | ||
check( | ||
assert_type(pd.Series([pd.Timestamp(2025, 9, 28)]).array, DatetimeArray), | ||
assert_type(Series([Timestamp(2025, 9, 28)]).array, DatetimeArray), | ||
DatetimeArray, | ||
pd.Timestamp, | ||
Timestamp, | ||
) | ||
check( | ||
assert_type(pd.Series([pd.Timedelta(1, "s")]).array, TimedeltaArray), | ||
assert_type(Series([Timedelta(1, "s")]).array, TimedeltaArray), | ||
TimedeltaArray, | ||
pd.Timedelta, | ||
Timedelta, | ||
) | ||
check(assert_type(pd.Series([1]).array, ExtensionArray), ExtensionArray, np.integer) | ||
check(assert_type(Series([1]).array, ExtensionArray), ExtensionArray, np.integer) | ||
# python/mypy#19952: mypy believes ExtensionArray and its subclasses have a | ||
# conflict and gives Any for s.array | ||
check(assert_type(pd.Series([1, "s"]).array, ExtensionArray), ExtensionArray) # type: ignore[assert-type] | ||
check(assert_type(Series([1, "s"]).array, ExtensionArray), ExtensionArray) # type: ignore[assert-type] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should exist because
Int64Dtype
is inS1
, and I don't want to introduce that now, because it will open up a whole set of new issues.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3a6710b