Skip to content

Commit

Permalink
add reduce/accumulate methods stubs + minimal tests, resolves #850 (#923
Browse files Browse the repository at this point in the history
)

* add reduce/accumulate methods stubs + minimal tests, resolves #850

* use np.integer

---------

Co-authored-by: Laurent Mutricy <laurent.mutricy@ekium.eu>
  • Loading branch information
mutricyl and Laurent Mutricy committed May 14, 2024
1 parent feebd47 commit 005c85f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pandas-stubs/core/arrays/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class ExtensionArray:
def view(self, dtype=...) -> Self | np.ndarray: ...
def ravel(self, order=...) -> Self: ...
def tolist(self) -> list: ...
def _reduce(
self, name: str, *, skipna: bool = ..., keepdims: bool = ..., **kwargs
) -> object: ...
def _accumulate(self, name: str, *, skipna: bool = ..., **kwargs) -> Self: ...

class ExtensionOpsMixin:
@classmethod
Expand Down
11 changes: 11 additions & 0 deletions tests/test_extension.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import decimal

import numpy as np
import pandas as pd
from pandas.arrays import IntegerArray
from typing_extensions import assert_type

from tests import check
Expand All @@ -25,3 +27,12 @@ def test_tolist() -> None:
check(assert_type(s.array.tolist(), list), list)
check(assert_type(s1.array.tolist(), list), list)
check(assert_type(pd.array([1, 2, 3]).tolist(), list), list)


def test_ExtensionArray_reduce_accumulate() -> None:
_data = IntegerArray(
values=np.array([1, 2, 3], dtype=int),
mask=np.array([True, False, False], dtype=bool),
)
check(assert_type(_data._reduce("max"), object), np.integer)
check(assert_type(_data._accumulate("cumsum"), IntegerArray), IntegerArray)

0 comments on commit 005c85f

Please sign in to comment.