jorisvandenbossche commented on code in PR #55592: URL: https://github.com/apache/arrow/pull/55592#discussion_r4717888685
########## python/pyarrow-stubs/__lib/scalar.pyi: ########## @@ -15,11 +15,378 @@ # specific language governing permissions and limitations # under the License. -# Placeholder stub - complete annotations in future PR. -# At runtime, these symbols are provided by the pyarrow.lib C extension. +import datetime as dt +from collections.abc import Iterator, Mapping, Sequence +from decimal import Decimal +from typing import Any, SupportsIndex, TypeAlias, overload +from uuid import UUID -from typing import Any +import numpy as np +from pyarrow._compute import CastOptions +from pyarrow._stubs_typing import MapsAsPydicts +from pyarrow.lib import ( + Array, + BaseExtensionType, + Buffer, + DataType, + MemoryPool, + MonthDayNano, + Tensor, + _Weakrefable, +) +from typing_extensions import CapsuleType -class ExtensionScalar: ... +class Scalar(_Weakrefable): + @property + def type(self) -> DataType: ... + @property + def is_valid(self) -> bool: ... + def cast( + self, + target_type: DataType | str | None = None, + safe: bool | None = None, + options: CastOptions | None = None, + memory_pool: MemoryPool | None = None, + ) -> Scalar: ... + def validate(self, *, full: bool = False) -> None: ... + def equals(self, other: Scalar) -> bool: ... + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> Any: ... + def __abs__(self) -> Scalar: ... + def __neg__(self) -> Scalar: ... + # The binary operators call the compute functions, which return a scalar, + # or an (chunked) array if the other operand is one. + def __add__(self, other: Any, /) -> Any: ... Review Comment: Maybe for a follow-up, but we could add an overload here to indicate that if `other` is a scalar, the output is a scalar? (and array -> array) ########## python/pyarrow-stubs/__lib/scalar.pyi: ########## @@ -15,11 +15,378 @@ # specific language governing permissions and limitations # under the License. -# Placeholder stub - complete annotations in future PR. -# At runtime, these symbols are provided by the pyarrow.lib C extension. +import datetime as dt +from collections.abc import Iterator, Mapping, Sequence +from decimal import Decimal +from typing import Any, SupportsIndex, TypeAlias, overload +from uuid import UUID -from typing import Any +import numpy as np +from pyarrow._compute import CastOptions +from pyarrow._stubs_typing import MapsAsPydicts +from pyarrow.lib import ( + Array, + BaseExtensionType, + Buffer, + DataType, + MemoryPool, + MonthDayNano, + Tensor, + _Weakrefable, +) +from typing_extensions import CapsuleType -class ExtensionScalar: ... +class Scalar(_Weakrefable): + @property + def type(self) -> DataType: ... + @property + def is_valid(self) -> bool: ... + def cast( + self, + target_type: DataType | str | None = None, + safe: bool | None = None, + options: CastOptions | None = None, + memory_pool: MemoryPool | None = None, + ) -> Scalar: ... + def validate(self, *, full: bool = False) -> None: ... + def equals(self, other: Scalar) -> bool: ... + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> Any: ... + def __abs__(self) -> Scalar: ... + def __neg__(self) -> Scalar: ... + # The binary operators call the compute functions, which return a scalar, + # or an (chunked) array if the other operand is one. + def __add__(self, other: Any, /) -> Any: ... + def __sub__(self, other: Any, /) -> Any: ... + def __mul__(self, other: Any, /) -> Any: ... + def __truediv__(self, other: Any, /) -> Any: ... + def __pow__(self, other: Any, mod: None = None, /) -> Any: ... + def __and__(self, other: Any, /) -> Any: ... + def __or__(self, other: Any, /) -> Any: ... + def __xor__(self, other: Any, /) -> Any: ... + def __lshift__(self, other: Any, /) -> Any: ... + def __rshift__(self, other: Any, /) -> Any: ... -def __getattr__(name: str) -> Any: ... +class NullScalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> None: ... + +NA: NullScalar +_NULL: NullScalar + +class BooleanScalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> bool | None: ... + def __bool__(self) -> bool: ... Review Comment: This method should exist on the base class Scalar? ########## python/pyarrow-stubs/__lib/scalar.pyi: ########## @@ -15,11 +15,378 @@ # specific language governing permissions and limitations # under the License. -# Placeholder stub - complete annotations in future PR. -# At runtime, these symbols are provided by the pyarrow.lib C extension. +import datetime as dt +from collections.abc import Iterator, Mapping, Sequence +from decimal import Decimal +from typing import Any, SupportsIndex, TypeAlias, overload +from uuid import UUID -from typing import Any +import numpy as np +from pyarrow._compute import CastOptions +from pyarrow._stubs_typing import MapsAsPydicts +from pyarrow.lib import ( + Array, + BaseExtensionType, + Buffer, + DataType, + MemoryPool, + MonthDayNano, + Tensor, + _Weakrefable, +) +from typing_extensions import CapsuleType -class ExtensionScalar: ... +class Scalar(_Weakrefable): + @property + def type(self) -> DataType: ... + @property + def is_valid(self) -> bool: ... + def cast( + self, + target_type: DataType | str | None = None, + safe: bool | None = None, + options: CastOptions | None = None, + memory_pool: MemoryPool | None = None, + ) -> Scalar: ... + def validate(self, *, full: bool = False) -> None: ... + def equals(self, other: Scalar) -> bool: ... + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> Any: ... + def __abs__(self) -> Scalar: ... + def __neg__(self) -> Scalar: ... + # The binary operators call the compute functions, which return a scalar, + # or an (chunked) array if the other operand is one. + def __add__(self, other: Any, /) -> Any: ... + def __sub__(self, other: Any, /) -> Any: ... + def __mul__(self, other: Any, /) -> Any: ... + def __truediv__(self, other: Any, /) -> Any: ... + def __pow__(self, other: Any, mod: None = None, /) -> Any: ... + def __and__(self, other: Any, /) -> Any: ... + def __or__(self, other: Any, /) -> Any: ... + def __xor__(self, other: Any, /) -> Any: ... + def __lshift__(self, other: Any, /) -> Any: ... + def __rshift__(self, other: Any, /) -> Any: ... -def __getattr__(name: str) -> Any: ... +class NullScalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> None: ... + +NA: NullScalar +_NULL: NullScalar + +class BooleanScalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> bool | None: ... + def __bool__(self) -> bool: ... + +class UInt8Scalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> int | None: ... + def __index__(self) -> int: ... + +class Int8Scalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> int | None: ... + def __index__(self) -> int: ... + +class UInt16Scalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> int | None: ... + def __index__(self) -> int: ... + +class Int16Scalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> int | None: ... + def __index__(self) -> int: ... + +class UInt32Scalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> int | None: ... + def __index__(self) -> int: ... + +class Int32Scalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> int | None: ... + def __index__(self) -> int: ... + +class UInt64Scalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> int | None: ... + def __index__(self) -> int: ... + +class Int64Scalar(Scalar): + def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> int | None: ... + def __index__(self) -> int: ... + +_IntegerScalar: TypeAlias = ( + UInt8Scalar + | Int8Scalar + | UInt16Scalar + | Int16Scalar + | UInt32Scalar + | Int32Scalar + | UInt64Scalar + | Int64Scalar +) + +class HalfFloatScalar(Scalar): + def as_py( + self, *, maps_as_pydicts: MapsAsPydicts | None = None + ) -> float | None: ... + def __float__(self) -> float: ... + def __int__(self) -> int: ... + +class FloatScalar(Scalar): + def as_py( + self, *, maps_as_pydicts: MapsAsPydicts | None = None + ) -> float | None: ... + def __float__(self) -> float: ... + def __int__(self) -> int: ... + +class DoubleScalar(Scalar): + def as_py( + self, *, maps_as_pydicts: MapsAsPydicts | None = None + ) -> float | None: ... + def __float__(self) -> float: ... Review Comment: FWIW this can actually return None at runtime as well, which then results in `float(scalar)` raising a TypeError. But not sure it is useful to add this to the typing .. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
