Repository navigation
Conversation
|
|
Add type annotation stubs for compute, _compute, _compute_docstring, and _acero modules. These are the stubs of apacheGH-49201 as they were, at their original paths. The type checker accommodations that apacheGH-49201 made in compute.py, acero.py and the PyArrow tests are left out, as the type checkers no longer run on pyarrow/ (see apacheGH-55264).
Add type annotation stubs for compute, _compute, _compute_docstring, and _acero modules. These are the stubs of apacheGH-49201 as they were, at their original paths. The type checker accommodations that apacheGH-49201 made in compute.py, acero.py and the PyArrow tests are left out, as the type checkers no longer run on pyarrow/ (see apacheGH-55264).
Add type annotation stubs for compute, _compute, _compute_docstring, and _acero modules. These are the stubs of apacheGH-49201 as they were, at their original paths. The type checker accommodations that apacheGH-49201 made in compute.py, acero.py and the PyArrow tests are left out, as the type checkers no longer run on pyarrow/ (see apacheGH-55264).
d3f0fb7 to
a78bedf
Compare
29a6b0b to
fb3204a
Compare
|
Given there were changes in the data types PR you might want to rebase or merge them here @AlenkaF. |
e8779e3 to
300602b
Compare
|
Oh, should have squashed, sorry. |
300602b to
bc6a844
Compare
| check(assert_type(field.equals(pc.field("a")), bool), bool) | ||
|
|
||
| # Calling a compute function with an expression builds an expression. | ||
| check(pc.count(field), pc.Expression) |
There was a problem hiding this comment.
Note to myself: add assert_type checks once the scalar stubs land.
|
|
||
| # =============================== Aggregations ======================================== | ||
| def all( | ||
| array: BooleanScalar | _ArrayOrChunkedArray | Expression, |
There was a problem hiding this comment.
To be consistent with decisions made in array.pyi we should use general Scalar class in parameters, not narrow types like BooleanScalar and aliases like _NumericScalar. The narrow types stay for returns.
… clean up the tests
7d4856e to
0394026
Compare
| def list_functions() -> list[str]: ... | ||
| def call_function( | ||
| name: str, | ||
| args: list[Any], |
There was a problem hiding this comment.
🤖 Match Function.call so callers can pass tuples or other iterables to call_function, not just lists.
| args: list[Any], | |
| args: Iterable[Any], |
|
|
||
| def __init__( | ||
| self, | ||
| target_type: DataType | str | None = None, |
There was a problem hiding this comment.
🤖 Reject str in CastOptions.__init__: _CastOptions._set_options expects a DataType at runtime (unlike safe()/unsafe(), which call ensure_type).
| target_type: DataType | str | None = None, | |
| target_type: DataType | None = None, |
| ) -> None: ... | ||
|
|
||
| class MatchSubstringOptions(FunctionOptions): | ||
| def __init__(self, pattern: str, *, ignore_case: bool = False) -> None: ... |
There was a problem hiding this comment.
🤖 Allow bytes here to match the corresponding compute.pyi signatures (which accept str | bytes and convert via tobytes()). The same applies to TrimOptions, ReplaceSubstringOptions, ExtractRegexOptions, ExtractRegexSpanOptions, ReplaceSliceOptions, SplitPatternOptions, StrptimeOptions, StrftimeOptions, and AssumeTimezoneOptions.
| def __init__(self, pattern: str, *, ignore_case: bool = False) -> None: ... | |
| def __init__(self, pattern: str | bytes, *, ignore_case: bool = False) -> None: ... |
|
|
||
| class CumulativeOptions(FunctionOptions): | ||
| def __init__( | ||
| self, start: Scalar | None = None, *, skip_nulls: bool = False |
There was a problem hiding this comment.
🤖 Allow numeric values for start to match cumulative_sum in compute.pyi (and _CumulativeOptions._set_options, which wraps non-Scalar inputs with lib.scalar()).
| self, start: Scalar | None = None, *, skip_nulls: bool = False | |
| self, start: float | Scalar | None = None, *, skip_nulls: bool = False |
| func: Callable[..., Any], | ||
| function_name: str, | ||
| function_doc: _FunctionDoc | dict[str, str], | ||
| in_types: dict[str, DataType | str], |
There was a problem hiding this comment.
🤖 Because dict is invariant in its value type, dict[str, DataType | str] rejects typed dicts like in_types = {"array": pa.int64()} (dict[str, Int64Type] / dict[str, DataType]) or dict[str, str]. Introducing a bounded type variable _InType = TypeVar("_InType", bound=DataType | str) and using in_types: dict[str, _InType] across all four register_*_function signatures keeps the runtime dict requirement while accepting subtype value dicts.
| self, | ||
| factory_name: str, | ||
| options: ExecNodeOptions, | ||
| inputs: list[Declaration] | None = None, |
There was a problem hiding this comment.
🤖 Accept any iterable of declarations to match from_sequence and _acero.pyx.
| inputs: list[Declaration] | None = None, | |
| inputs: Iterable[Declaration] | None = None, |
| # scalars. float covers int, np.generic covers NumPy scalars | ||
| NumericLiteral: TypeAlias = float | Decimal | np.generic | ||
| TemporalLiteral: TypeAlias = dt.date | dt.time | dt.timedelta | np.generic |
There was a problem hiding this comment.
🤖 Narrow np.generic to np.number[Any] / np.datetime64 | np.timedelta64 so non-numeric or non-temporal NumPy scalars (like np.str_) don't pass numeric/temporal compute stubs, matching NDArray[np.bool_] and NDArray[np.integer[Any]] above.
| # scalars. float covers int, np.generic covers NumPy scalars | |
| NumericLiteral: TypeAlias = float | Decimal | np.generic | |
| TemporalLiteral: TypeAlias = dt.date | dt.time | dt.timedelta | np.generic | |
| # scalars. float covers int. | |
| NumericLiteral: TypeAlias = float | Decimal | np.number[Any] | |
| TemporalLiteral: TypeAlias = ( | |
| dt.date | dt.time | dt.timedelta | np.datetime64 | np.timedelta64 | |
| ) |
| _StrOrExpr: TypeAlias = str | Expression | ||
| _IntoField: TypeAlias = str | int | Expression | ||
| _Target: TypeAlias = _IntoField | Sequence[_IntoField] | ||
| _Aggregate: TypeAlias = tuple[_Target, _AggregationName, _AggregateOptions | None, str] | ||
|
|
||
| _JoinType: TypeAlias = Literal[ | ||
| "left semi", | ||
| "right semi", | ||
| "left anti", | ||
| "right anti", | ||
| "inner", | ||
| "left outer", | ||
| "right outer", | ||
| "full outer", | ||
| ] |
There was a problem hiding this comment.
🤖 To simplify these aliases and avoid introducing a _stubs_typing ↔ _compute cycle (either here or in your follow-up PR), we can unify _StrOrExpr/_IntoField/_Target around _ensure_field_ref and split shared aliases by what they depend on:
_stubs_typing.pyi(pureLiterals, no_computeimports):JoinType,AggregationName_compute.pyi(ownsExpressionand*Options):_FieldRef = str | int | Expression(reused by_SortKey) and_AggregateOptions(from__lib/table.pyi, removing_acero.pyi's import frompyarrow.__lib.table)_acero.pyi(Acero-only):_FieldRefs = _FieldRef | Sequence[_FieldRef](used byAggregateNodeOptions,HashJoinNodeOptions, andAsofJoinNodeOptions) and_Aggregate
| # PyArrow can be built without Acero. | ||
| pytest.importorskip("pyarrow._acero") |
There was a problem hiding this comment.
👨 Are we going to test without acero?
| _UnsignedIntegerScalar: TypeAlias = ( | ||
| UInt8Scalar | UInt16Scalar | UInt32Scalar | UInt64Scalar | ||
| ) | ||
| _IntegerScalar: TypeAlias = _SignedIntegerScalar | _UnsignedIntegerScalar |
There was a problem hiding this comment.
Agreed this should be done and agreed to do it in a separate PR.
Rationale for this change
Closes: #49194
What changes are included in this PR?
Adds type annotation stubs for compute, _compute, _compute_docstring, and _acero modules. Includes source fixes in compute.py and acero.py, and type-ignore annotations in related tests.
Are these changes tested?
Yes, by CI.
Are there any user-facing changes?
Compute module functions will be type annotated.