From 238e1e91a6430eca719d35bc45215dee6a8acf3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Diridollou?= Date: Wed, 17 Dec 2025 09:42:58 -0500 Subject: [PATCH 1/3] Clean up annotations for undocumented elements --- pandas-stubs/core/base.pyi | 5 ++- pandas-stubs/core/computation/engines.pyi | 2 - pandas-stubs/core/computation/expr.pyi | 38 ---------------- pandas-stubs/core/computation/ops.pyi | 40 ++--------------- pandas-stubs/core/computation/pytables.pyi | 50 ++-------------------- pandas-stubs/core/computation/scope.pyi | 8 ---- pyproject.toml | 8 ---- 7 files changed, 11 insertions(+), 140 deletions(-) diff --git a/pandas-stubs/core/base.pyi b/pandas-stubs/core/base.pyi index e4b820d79..1b0668a18 100644 --- a/pandas-stubs/core/base.pyi +++ b/pandas-stubs/core/base.pyi @@ -1,4 +1,5 @@ from collections.abc import ( + Callable, Hashable, Iterator, Sequence, @@ -67,8 +68,8 @@ class SelectionMixin(Generic[NDFrameT]): @final @cache_readonly def ndim(self) -> int: ... - def __getitem__(self, key): ... - def aggregate(self, func, *args: Any, **kwargs: Any): ... + def __getitem__(self, key: Any) -> Any: ... + def aggregate(self, func: Callable[..., Any], *args: Any, **kwargs: Any) -> Any: ... class IndexOpsMixin(OpsMixin, Generic[S1, GenericT_co]): __array_priority__: int = ... diff --git a/pandas-stubs/core/computation/engines.pyi b/pandas-stubs/core/computation/engines.pyi index f2a162329..a2d73fb5a 100644 --- a/pandas-stubs/core/computation/engines.pyi +++ b/pandas-stubs/core/computation/engines.pyi @@ -5,7 +5,6 @@ class AbstractEngine(metaclass=abc.ABCMeta): expr = ... aligned_axes = ... result_type = ... - def __init__(self, expr) -> None: ... def convert(self) -> str: ... def evaluate(self) -> object: ... @@ -14,4 +13,3 @@ class NumExprEngine(AbstractEngine): class PythonEngine(AbstractEngine): has_neg_frac: bool = ... - def evaluate(self): ... diff --git a/pandas-stubs/core/computation/expr.pyi b/pandas-stubs/core/computation/expr.pyi index 8f2d59e3a..02bfa3295 100644 --- a/pandas-stubs/core/computation/expr.pyi +++ b/pandas-stubs/core/computation/expr.pyi @@ -1,5 +1,4 @@ import ast -from typing import Any from pandas.core.computation.ops import Term as Term from pandas.core.computation.scope import Scope as Scope @@ -19,28 +18,6 @@ class BaseExprVisitor(ast.NodeVisitor): parser = ... preparser = ... assigner = ... - def __init__(self, env, engine, parser, preparser=...) -> None: ... - def visit(self, node, **kwargs: Any): ... - def visit_Module(self, node, **kwargs: Any): ... - def visit_Expr(self, node, **kwargs: Any): ... - def visit_BinOp(self, node, **kwargs: Any): ... - def visit_Div(self, node, **kwargs: Any): ... - def visit_UnaryOp(self, node, **kwargs: Any): ... - def visit_Name(self, node, **kwargs: Any): ... - def visit_NameConstant(self, node, **kwargs: Any): ... - def visit_Num(self, node, **kwargs: Any): ... - def visit_Constant(self, node, **kwargs: Any): ... - def visit_Str(self, node, **kwargs: Any): ... - def visit_List(self, node, **kwargs: Any): ... - def visit_Index(self, node, **kwargs: Any): ... - def visit_Subscript(self, node, **kwargs: Any): ... - def visit_Slice(self, node, **kwargs: Any): ... - def visit_Assign(self, node, **kwargs: Any): ... - def visit_Attribute(self, node, **kwargs: Any): ... - def visit_Call(self, node, side=..., **kwargs: Any): ... - def translate_In(self, op): ... - def visit_Compare(self, node, **kwargs: Any): ... - def visit_BoolOp(self, node, **kwargs: Any): ... class Expr: env: Scope @@ -48,18 +25,3 @@ class Expr: parser: str expr = ... terms = ... - def __init__( - self, - expr, - engine: str = ..., - parser: str = ..., - env: Scope | None = ..., - level: int = ..., - ) -> None: ... - @property - def assigner(self): ... - def __call__(self): ... - def __len__(self) -> int: ... - def parse(self): ... - @property - def names(self): ... diff --git a/pandas-stubs/core/computation/ops.pyi b/pandas-stubs/core/computation/ops.pyi index 7cc0f95f9..c5e5668e1 100644 --- a/pandas-stubs/core/computation/ops.pyi +++ b/pandas-stubs/core/computation/ops.pyi @@ -3,56 +3,34 @@ from typing import Any import numpy as np -class UndefinedVariableError(NameError): - def __init__(self, name, is_local: bool = ...) -> None: ... +class UndefinedVariableError(NameError): ... class Term: - def __new__(cls, name, env, side=..., encoding=...): ... is_local: bool env = ... side = ... encoding = ... - def __init__(self, name, env, side=..., encoding=...) -> None: ... @property def local_name(self) -> str: ... - def __call__(self, *args: Any, **kwargs: Any): ... - def evaluate(self, *args: Any, **kwargs: Any): ... - def update(self, value) -> None: ... @property def is_scalar(self) -> bool: ... - @property - def type(self): ... return_type = ... @property def raw(self) -> str: ... @property def is_datetime(self) -> bool: ... @property - def value(self): ... - @value.setter - def value(self, new_value) -> None: ... - @property - def name(self): ... - @property def ndim(self) -> int: ... -class Constant(Term): - @property - def name(self): ... +class Constant(Term): ... class Op: op: str operands = ... encoding = ... - def __init__(self, op: str, operands, *args: Any, **kwargs: Any) -> None: ... - def __iter__(self): ... - @property - def return_type(self): ... @property def has_invalid_return_type(self) -> bool: ... @property - def operand_types(self): ... - @property def is_scalar(self) -> bool: ... @property def is_datetime(self) -> bool: ... @@ -61,21 +39,14 @@ class BinOp(Op): lhs = ... rhs = ... func = ... - def __init__(self, op: str, lhs, rhs, **kwargs: Any) -> None: ... - def __call__(self, env): ... - def evaluate(self, env, engine: str, parser, term_type, eval_in_python): ... - def convert_values(self): ... -def isnumeric(dtype) -> bool: ... +def isnumeric(dtype: type) -> bool: ... -class Div(BinOp): - def __init__(self, lhs, rhs, **kwargs: Any) -> None: ... +class Div(BinOp): ... class UnaryOp(Op): operand = ... func = ... - def __init__(self, op: str, operand) -> None: ... - def __call__(self, env): ... if sys.version_info >= (3, 11): @property def return_type(self) -> np.dtype: ... @@ -85,11 +56,8 @@ class UnaryOp(Op): class MathCall(Op): func = ... - def __init__(self, func, args) -> None: ... - def __call__(self, env): ... class FuncNode: name = ... func = ... def __init__(self, name: str) -> None: ... - def __call__(self, *args: Any): ... diff --git a/pandas-stubs/core/computation/pytables.pyi b/pandas-stubs/core/computation/pytables.pyi index 7e5fc59a0..25cec1021 100644 --- a/pandas-stubs/core/computation/pytables.pyi +++ b/pandas-stubs/core/computation/pytables.pyi @@ -10,80 +10,41 @@ from pandas.core.indexes.base import Index class PyTablesScope(_scope.Scope): queryables: dict[str, Any] - def __init__( - self, - level: int, - global_dict=..., - local_dict=..., - queryables: dict[str, Any] | None = ..., - ) -> None: ... class Term(ops.Term): env = ... - def __new__(cls, name, env, side=..., encoding=...): ... - def __init__(self, name, env: PyTablesScope, side=..., encoding=...) -> None: ... - @property - def value(self): ... - @value.setter - def value(self, new_value) -> None: ... -class Constant(Term): - def __init__(self, name, env: PyTablesScope, side=..., encoding=...) -> None: ... +class Constant(Term): ... class BinOp(ops.BinOp): op: str queryables: dict[str, Any] encoding = ... condition = ... - def __init__( - self, op: str, lhs, rhs, queryables: dict[str, Any], encoding - ) -> None: ... - def prune(self, klass): ... - def conform(self, rhs): ... @property def is_valid(self) -> bool: ... @property def is_in_table(self) -> bool: ... - @property - def kind(self): ... - @property - def meta(self): ... - @property - def metadata(self): ... - def generate(self, v) -> str: ... - def convert_value(self, v) -> TermValue: ... def convert_values(self) -> None: ... class FilterBinOp(BinOp): filter: tuple[Any, Any, Index] | None = ... - def invert(self): ... - def format(self): ... - def generate_filter_op(self, invert: bool = ...): ... class JointFilterBinOp(FilterBinOp): def format(self) -> None: ... class ConditionBinOp(BinOp): def invert(self) -> None: ... - def format(self): ... condition = ... class JointConditionBinOp(ConditionBinOp): condition = ... -class UnaryOp(ops.UnaryOp): - def prune(self, klass): ... +class UnaryOp(ops.UnaryOp): ... class PyTablesExprVisitor(BaseExprVisitor): const_type = ... term_type = ... - def __init__(self, env, engine, parser, **kwargs: Any) -> None: ... - def visit_UnaryOp(self, node, **kwargs: Any): ... - def visit_Index(self, node, **kwargs: Any): ... - def visit_Assign(self, node, **kwargs: Any): ... - def visit_Subscript(self, node, **kwargs: Any): ... - def visit_Attribute(self, node, **kwargs: Any): ... - def translate_In(self, op): ... class PyTablesExpr(expr.Expr): encoding = ... @@ -93,16 +54,13 @@ class PyTablesExpr(expr.Expr): expr = ... def __init__( self, - where, + where: Any, queryables: dict[str, Any] | None = ..., - encoding=..., + encoding: Any = ..., scope_level: int = ..., ) -> None: ... - def evaluate(self): ... class TermValue: value = ... converted = ... kind = ... - def __init__(self, value, converted, kind: str) -> None: ... - def tostring(self, encoding) -> str: ... diff --git a/pandas-stubs/core/computation/scope.pyi b/pandas-stubs/core/computation/scope.pyi index baf99f23f..da8bc480f 100644 --- a/pandas-stubs/core/computation/scope.pyi +++ b/pandas-stubs/core/computation/scope.pyi @@ -4,15 +4,7 @@ class Scope: target = ... resolvers = ... temps = ... - def __init__( - self, level, global_dict=..., local_dict=..., resolvers=..., target=... - ) -> None: ... @property def has_resolvers(self) -> bool: ... - def resolve(self, key: str, is_local: bool): ... - def swapkey(self, old_key: str, new_key: str, new_value=...): ... - def add_tmp(self, value) -> str: ... @property def ntemps(self) -> int: ... - @property - def full_scope(self): ... diff --git a/pyproject.toml b/pyproject.toml index 0663fc85d..6762e3fbe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -205,10 +205,6 @@ ignore = [ "PYI042", # https://docs.astral.sh/ruff/rules/snake-case-type-alias/ "ERA001", "PLR0402", "PLC0105" ] -"*computation*" = [ - # TODO: remove when computations are fully typed - "ANN001", "ANN201", "ANN204", "ANN206", -] "*window*" = [ # TODO: remove when window is fully typed "ANN001", "ANN201", "ANN204", "ANN206", @@ -221,10 +217,6 @@ ignore = [ # TODO: remove when array is fully typed "ANN001", "ANN201", "ANN204", "ANN206", ] -"*core/base.pyi" = [ - # TODO: remove when core/base.pyi is fully typed - "ANN001", "ANN201", "ANN204", "ANN206", -] "*excel/_base.pyi" = [ # TODO: remove when excel/_base.pyi is fully typed "ANN001", "ANN201", "ANN204", "ANN206", From 5532e53620390f13ebbb412fbb5dd1d356a1262c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Diridollou?= Date: Wed, 17 Dec 2025 21:00:53 -0500 Subject: [PATCH 2/3] PR Feedback --- pandas-stubs/core/computation/engines.pyi | 15 --------------- pandas-stubs/core/computation/expr.pyi | 1 - pandas-stubs/core/computation/pytables.pyi | 9 --------- 3 files changed, 25 deletions(-) delete mode 100644 pandas-stubs/core/computation/engines.pyi diff --git a/pandas-stubs/core/computation/engines.pyi b/pandas-stubs/core/computation/engines.pyi deleted file mode 100644 index a2d73fb5a..000000000 --- a/pandas-stubs/core/computation/engines.pyi +++ /dev/null @@ -1,15 +0,0 @@ -import abc - -class AbstractEngine(metaclass=abc.ABCMeta): - has_neg_frac: bool = ... - expr = ... - aligned_axes = ... - result_type = ... - def convert(self) -> str: ... - def evaluate(self) -> object: ... - -class NumExprEngine(AbstractEngine): - has_neg_frac: bool = ... - -class PythonEngine(AbstractEngine): - has_neg_frac: bool = ... diff --git a/pandas-stubs/core/computation/expr.pyi b/pandas-stubs/core/computation/expr.pyi index 02bfa3295..777603159 100644 --- a/pandas-stubs/core/computation/expr.pyi +++ b/pandas-stubs/core/computation/expr.pyi @@ -1,6 +1,5 @@ import ast -from pandas.core.computation.ops import Term as Term from pandas.core.computation.scope import Scope as Scope class BaseExprVisitor(ast.NodeVisitor): diff --git a/pandas-stubs/core/computation/pytables.pyi b/pandas-stubs/core/computation/pytables.pyi index 25cec1021..af797ebb5 100644 --- a/pandas-stubs/core/computation/pytables.pyi +++ b/pandas-stubs/core/computation/pytables.pyi @@ -3,19 +3,10 @@ from typing import Any from pandas.core.computation import ( expr as expr, ops as ops, - scope as _scope, ) from pandas.core.computation.expr import BaseExprVisitor as BaseExprVisitor from pandas.core.indexes.base import Index -class PyTablesScope(_scope.Scope): - queryables: dict[str, Any] - -class Term(ops.Term): - env = ... - -class Constant(Term): ... - class BinOp(ops.BinOp): op: str queryables: dict[str, Any] From 4c16435a3cf769b8efb75b2775d0cd1f378bfdca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Diridollou?= Date: Thu, 18 Dec 2025 11:37:00 -0500 Subject: [PATCH 3/3] PR Feedback --- pandas-stubs/core/computation/pytables.pyi | 16 ---------------- pandas-stubs/io/excel/_base.pyi | 4 ++-- pandas-stubs/io/formats/style.pyi | 4 ++-- tests/test_io.py | 4 ++-- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/pandas-stubs/core/computation/pytables.pyi b/pandas-stubs/core/computation/pytables.pyi index af797ebb5..66abbb7a3 100644 --- a/pandas-stubs/core/computation/pytables.pyi +++ b/pandas-stubs/core/computation/pytables.pyi @@ -21,22 +21,6 @@ class BinOp(ops.BinOp): class FilterBinOp(BinOp): filter: tuple[Any, Any, Index] | None = ... -class JointFilterBinOp(FilterBinOp): - def format(self) -> None: ... - -class ConditionBinOp(BinOp): - def invert(self) -> None: ... - condition = ... - -class JointConditionBinOp(ConditionBinOp): - condition = ... - -class UnaryOp(ops.UnaryOp): ... - -class PyTablesExprVisitor(BaseExprVisitor): - const_type = ... - term_type = ... - class PyTablesExpr(expr.Expr): encoding = ... condition = ... diff --git a/pandas-stubs/io/excel/_base.pyi b/pandas-stubs/io/excel/_base.pyi index 2c451dd29..fb676a64c 100644 --- a/pandas-stubs/io/excel/_base.pyi +++ b/pandas-stubs/io/excel/_base.pyi @@ -24,8 +24,8 @@ from typing_extensions import ( TypeVar, ) from xlrd.book import Book -from xlsxwriter.workbook import ( - Workbook as XlsxWorkbook, # pyright: ignore[reportMissingTypeStubs] +from xlsxwriter.workbook import ( # pyright: ignore[reportMissingTypeStubs] + Workbook as XlsxWorkbook, ) from pandas._libs.lib import _NoDefaultDoNotUse diff --git a/pandas-stubs/io/formats/style.pyi b/pandas-stubs/io/formats/style.pyi index c793b19ea..be17b49aa 100644 --- a/pandas-stubs/io/formats/style.pyi +++ b/pandas-stubs/io/formats/style.pyi @@ -17,8 +17,8 @@ from openpyxl.workbook.workbook import Workbook as OpenXlWorkbook from pandas.core.frame import DataFrame from pandas.core.series import Series from typing_extensions import Self -from xlsxwriter.workbook import ( - Workbook as XlsxWorkbook, # pyright: ignore[reportMissingTypeStubs] +from xlsxwriter.workbook import ( # pyright: ignore[reportMissingTypeStubs] + Workbook as XlsxWorkbook, ) from pandas._typing import ( diff --git a/tests/test_io.py b/tests/test_io.py index b05b81d96..ecf4cfd8a 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -47,8 +47,8 @@ import sqlalchemy.orm import sqlalchemy.orm.decl_api from typing_extensions import assert_type -from xlsxwriter.workbook import ( - Workbook as XlsxWorkbook, # pyright: ignore[reportMissingTypeStubs] +from xlsxwriter.workbook import ( # pyright: ignore[reportMissingTypeStubs] + Workbook as XlsxWorkbook, ) from tests import (