Closed
Description
Describe the bug
The stubs for ExtensionArray (in pandas-stubs/core/arrays/base.pyi
) does not provide type signatures for _accumulate and _reduce. To properly add typing information to the Pint-Pandas project, these need to be defined.
To Reproduce
- Minimal Runnable Example:
import numpy as np
import pandas as pd
from typing import reveal_type
from pandas.arrays import IntegerArray
from pandas.api.extensions import ExtensionArray
_data: ExtensionArray = IntegerArray(values=np.array([1, 2, 3], dtype=int), mask=np.array([True, True, True], dtype=bool))
if isinstance(_data, ExtensionArray):
reveal_type(_data)
reveal_type(_data._accumulate)
reveal_type(_data._reduce)
- Using
mypy
- Show the error message received from that type checker while checking your example.
(pint-dev) % pre-commit run mypy --files foo.py
mypy.....................................................................Failed
- hook id: mypy
- duration: 1.41s
- exit code: 1
foo.py:9: note: Revealed type is "pandas.core.arrays.base.ExtensionArray"
foo.py:10: error: "ExtensionArray" has no attribute "_accumulate" [attr-defined]
foo.py:10: note: Revealed type is "Any"
foo.py:11: error: "ExtensionArray" has no attribute "_reduce" [attr-defined]
foo.py:11: note: Revealed type is "Any"
Found 2 errors in 1 file (checked 1 source file)
Note that running the script in python works, because it uses actual Pandas code, not Pandas-Stubs:
(pint-dev) % python foo.py
Runtime type is 'IntegerArray'
Runtime type is 'method'
Runtime type is 'method'
Please complete the following information:
- OS: Mac OS
- OS Version 14.1.2
- python 3.11.4
- mypy 1.8.0
- version of installed
pandas-stubs
: 2.1.4.231227
Additional context
Add any other context about the problem here.