Skip to content

Commit 34d0498

Browse files
TYP: numba stub (#44233)
1 parent 63faec3 commit 34d0498

File tree

7 files changed

+57
-17
lines changed

7 files changed

+57
-17
lines changed

ci/code_checks.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ if [[ -z "$CHECK" || "$CHECK" == "typing" ]]; then
106106
mypy --version
107107

108108
MSG='Performing static analysis using mypy' ; echo $MSG
109-
mypy pandas
109+
mypy
110110
RET=$(($RET + $?)) ; echo $MSG "DONE"
111111

112112
# run pyright, if it is installed

doc/source/development/contributing_codebase.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ pandas uses `mypy <http://mypy-lang.org>`_ and `pyright <https://github.com/micr
399399

400400
.. code-block:: shell
401401
402-
mypy pandas
402+
mypy
403403
404404
# let pre-commit setup and run pyright
405405
pre-commit run --hook-stage manual --all-files pyright

pandas/core/_numba/kernels/mean_.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
from pandas.core._numba.kernels.shared import is_monotonic_increasing
1515

1616

17-
# error: Untyped decorator makes function "add_mean" untyped
18-
@numba.jit(nopython=True, nogil=True, parallel=False) # type: ignore[misc]
17+
@numba.jit(nopython=True, nogil=True, parallel=False)
1918
def add_mean(
2019
val: float, nobs: int, sum_x: float, neg_ct: int, compensation: float
2120
) -> tuple[int, float, int, float]:
@@ -30,8 +29,7 @@ def add_mean(
3029
return nobs, sum_x, neg_ct, compensation
3130

3231

33-
# error: Untyped decorator makes function "remove_mean" untyped
34-
@numba.jit(nopython=True, nogil=True, parallel=False) # type: ignore[misc]
32+
@numba.jit(nopython=True, nogil=True, parallel=False)
3533
def remove_mean(
3634
val: float, nobs: int, sum_x: float, neg_ct: int, compensation: float
3735
) -> tuple[int, float, int, float]:
@@ -46,8 +44,7 @@ def remove_mean(
4644
return nobs, sum_x, neg_ct, compensation
4745

4846

49-
# error: Untyped decorator makes function "sliding_mean" untyped
50-
@numba.jit(nopython=True, nogil=True, parallel=False) # type: ignore[misc]
47+
@numba.jit(nopython=True, nogil=True, parallel=False)
5148
def sliding_mean(
5249
values: np.ndarray,
5350
start: np.ndarray,

pandas/core/_numba/kernels/shared.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
import numpy as np
33

44

5-
# error: Untyped decorator makes function "is_monotonic_increasing" untyped
6-
@numba.jit( # type: ignore[misc]
7-
numba.boolean(numba.int64[:]), nopython=True, nogil=True, parallel=False
5+
@numba.jit(
6+
# error: Any? not callable
7+
numba.boolean(numba.int64[:]), # type: ignore[misc]
8+
nopython=True,
9+
nogil=True,
10+
parallel=False,
811
)
912
def is_monotonic_increasing(bounds: np.ndarray) -> bool:
1013
"""Check if int64 values are monotonically increasing."""

pandas/core/_numba/kernels/sum_.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
from pandas.core._numba.kernels.shared import is_monotonic_increasing
1515

1616

17-
# error: Untyped decorator makes function "add_sum" untyped
18-
@numba.jit(nopython=True, nogil=True, parallel=False) # type: ignore[misc]
17+
@numba.jit(nopython=True, nogil=True, parallel=False)
1918
def add_sum(
2019
val: float, nobs: int, sum_x: float, compensation: float
2120
) -> tuple[int, float, float]:
@@ -28,8 +27,7 @@ def add_sum(
2827
return nobs, sum_x, compensation
2928

3029

31-
# error: Untyped decorator makes function "remove_sum" untyped
32-
@numba.jit(nopython=True, nogil=True, parallel=False) # type: ignore[misc]
30+
@numba.jit(nopython=True, nogil=True, parallel=False)
3331
def remove_sum(
3432
val: float, nobs: int, sum_x: float, compensation: float
3533
) -> tuple[int, float, float]:
@@ -42,8 +40,7 @@ def remove_sum(
4240
return nobs, sum_x, compensation
4341

4442

45-
# error: Untyped decorator makes function "sliding_sum" untyped
46-
@numba.jit(nopython=True, nogil=True, parallel=False) # type: ignore[misc]
43+
@numba.jit(nopython=True, nogil=True, parallel=False)
4744
def sliding_sum(
4845
values: np.ndarray,
4946
start: np.ndarray,

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ markers = [
6060

6161
[tool.mypy]
6262
# Import discovery
63+
mypy_path = "typings"
64+
files = ["pandas", "typings"]
6365
namespace_packages = false
6466
explicit_package_bases = false
6567
ignore_missing_imports = true

typings/numba.pyi

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from typing import (
2+
Any,
3+
Callable,
4+
Literal,
5+
overload,
6+
)
7+
8+
import numba
9+
10+
from pandas._typing import F
11+
12+
def __getattr__(name: str) -> Any: ... # incomplete
13+
@overload
14+
def jit(
15+
signature_or_function: F = ...,
16+
) -> F: ...
17+
@overload
18+
def jit(
19+
signature_or_function: str
20+
| list[str]
21+
| numba.core.types.abstract.Type
22+
| list[numba.core.types.abstract.Type] = ...,
23+
locals: dict = ..., # TODO: Mapping of local variable names to Numba types
24+
cache: bool = ...,
25+
pipeline_class: numba.compiler.CompilerBase = ...,
26+
boundscheck: bool | None = ...,
27+
*,
28+
nopython: bool = ...,
29+
forceobj: bool = ...,
30+
looplift: bool = ...,
31+
error_model: Literal["python", "numpy"] = ...,
32+
inline: Literal["never", "always"] | Callable = ...,
33+
# TODO: If a callable is provided it will be called with the call expression
34+
# node that is requesting inlining, the caller's IR and callee's IR as
35+
# arguments, it is expected to return Truthy as to whether to inline.
36+
target: Literal["cpu", "gpu", "npyufunc", "cuda"] = ..., # deprecated
37+
nogil: bool = ...,
38+
parallel: bool = ...,
39+
) -> Callable[[F], F]: ...
40+
41+
njit = jit

0 commit comments

Comments
 (0)