Skip to content

Commit 005c85f

Browse files
mutricylLaurent Mutricy
and
Laurent Mutricy
authored
add reduce/accumulate methods stubs + minimal tests, resolves #850 (#923)
* add reduce/accumulate methods stubs + minimal tests, resolves #850 * use np.integer --------- Co-authored-by: Laurent Mutricy <laurent.mutricy@ekium.eu>
1 parent feebd47 commit 005c85f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pandas-stubs/core/arrays/base.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class ExtensionArray:
5656
def view(self, dtype=...) -> Self | np.ndarray: ...
5757
def ravel(self, order=...) -> Self: ...
5858
def tolist(self) -> list: ...
59+
def _reduce(
60+
self, name: str, *, skipna: bool = ..., keepdims: bool = ..., **kwargs
61+
) -> object: ...
62+
def _accumulate(self, name: str, *, skipna: bool = ..., **kwargs) -> Self: ...
5963

6064
class ExtensionOpsMixin:
6165
@classmethod

tests/test_extension.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import decimal
22

3+
import numpy as np
34
import pandas as pd
5+
from pandas.arrays import IntegerArray
46
from typing_extensions import assert_type
57

68
from tests import check
@@ -25,3 +27,12 @@ def test_tolist() -> None:
2527
check(assert_type(s.array.tolist(), list), list)
2628
check(assert_type(s1.array.tolist(), list), list)
2729
check(assert_type(pd.array([1, 2, 3]).tolist(), list), list)
30+
31+
32+
def test_ExtensionArray_reduce_accumulate() -> None:
33+
_data = IntegerArray(
34+
values=np.array([1, 2, 3], dtype=int),
35+
mask=np.array([True, False, False], dtype=bool),
36+
)
37+
check(assert_type(_data._reduce("max"), object), np.integer)
38+
check(assert_type(_data._accumulate("cumsum"), IntegerArray), IntegerArray)

0 commit comments

Comments
 (0)