Skip to content

Commit e394c53

Browse files
authored
TYP: enable disallow_untyped_decorators (#43828)
1 parent 199cacb commit e394c53

28 files changed

+153
-59
lines changed

pandas/_libs/properties.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# pyright: reportIncompleteStub = false
2+
from typing import Any
3+
4+
# note: this is a lie to make type checkers happy (they special
5+
# case property). cache_readonly uses attribute names similar to
6+
# property (fget) but it does not provide fset and fdel.
7+
cache_readonly = property
8+
9+
def __getattr__(name: str) -> Any: ... # incomplete

pandas/_libs/properties.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ from cpython.dict cimport (
1010
cdef class CachedProperty:
1111

1212
cdef readonly:
13-
object func, name, __doc__
13+
object fget, name, __doc__
1414

15-
def __init__(self, func):
16-
self.func = func
17-
self.name = func.__name__
18-
self.__doc__ = getattr(func, '__doc__', None)
15+
def __init__(self, fget):
16+
self.fget = fget
17+
self.name = fget.__name__
18+
self.__doc__ = getattr(fget, '__doc__', None)
1919

2020
def __get__(self, obj, typ):
2121
if obj is None:
@@ -34,7 +34,7 @@ cdef class CachedProperty:
3434
# not necessary to Py_INCREF
3535
val = <object>PyDict_GetItem(cache, self.name)
3636
else:
37-
val = self.func(obj)
37+
val = self.fget(obj)
3838
PyDict_SetItem(cache, self.name, val)
3939
return val
4040

pandas/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Dtypes
1818
- Misc
1919
"""
20+
# pyright: reportUntypedFunctionDecorator = false
2021

2122
from collections import abc
2223
from datetime import (

pandas/core/_numba/executor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def generate_shared_aggregator(
4444

4545
numba = import_optional_dependency("numba")
4646

47-
@numba.jit(nopython=nopython, nogil=nogil, parallel=parallel)
47+
# error: Untyped decorator makes function "column_looper" untyped
48+
@numba.jit(nopython=nopython, nogil=nogil, parallel=parallel) # type: ignore[misc]
4849
def column_looper(
4950
values: np.ndarray,
5051
start: np.ndarray,

pandas/core/_numba/kernels/mean_.py

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

1616

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

3132

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

4648

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

pandas/core/_numba/kernels/shared.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import numpy as np
33

44

5-
@numba.jit(numba.boolean(numba.int64[:]), nopython=True, nogil=True, parallel=False)
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
8+
)
69
def is_monotonic_increasing(bounds: np.ndarray) -> bool:
710
"""Check if int64 values are monotonically increasing."""
811
n = len(bounds)

pandas/core/_numba/kernels/sum_.py

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

1616

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

2930

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

4244

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

pandas/core/arrays/categorical.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2699,7 +2699,7 @@ def _get_codes_for_values(values, categories: Index) -> np.ndarray:
26992699
"""
27002700
dtype_equal = is_dtype_equal(values.dtype, categories.dtype)
27012701

2702-
if is_extension_array_dtype(categories.dtype) and is_object_dtype(values):
2702+
if isinstance(categories.dtype, ExtensionDtype) and is_object_dtype(values):
27032703
# Support inferring the correct extension dtype from an array of
27042704
# scalar objects. e.g.
27052705
# Categorical(array[Period, Period], categories=PeriodIndex(...))

pandas/core/arrays/period.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,9 @@ def fillna(self, value=None, method=None, limit=None) -> PeriodArray:
669669
# view as dt64 so we get treated as timelike in core.missing
670670
dta = self.view("M8[ns]")
671671
result = dta.fillna(value=value, method=method, limit=limit)
672-
return result.view(self.dtype)
672+
# error: Incompatible return value type (got "Union[ExtensionArray,
673+
# ndarray[Any, Any]]", expected "PeriodArray")
674+
return result.view(self.dtype) # type: ignore[return-value]
673675
return super().fillna(value=value, method=method, limit=limit)
674676

675677
# ------------------------------------------------------------------

pandas/core/groupby/generic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,11 @@ def apply_series_value_counts():
675675
# multi-index components
676676
codes = self.grouper.reconstructed_codes
677677
codes = [rep(level_codes) for level_codes in codes] + [llab(lab, inc)]
678-
levels = [ping.group_index for ping in self.grouper.groupings] + [lev]
678+
# error: List item 0 has incompatible type "Union[ndarray[Any, Any], Index]";
679+
# expected "Index"
680+
levels = [ping.group_index for ping in self.grouper.groupings] + [
681+
lev # type: ignore[list-item]
682+
]
679683
names = self.grouper.names + [self.obj.name]
680684

681685
if dropna:

0 commit comments

Comments
 (0)