tadeja commented on code in PR #55592:
URL: https://github.com/apache/arrow/pull/55592#discussion_r4746598518


##########
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:
   It looks like it's not in base Scalar
   ```python
   import pyarrow as pa
   hasattr(pa.Scalar, "__bool__") # result: False
   bool(pa.scalar(0)) # result: True
   pa.scalar(0).__bool__()
   ```
   ```console
   Traceback (most recent call last):
     File "<python-input-6>", line 1, in <module>
       pa.scalar(0).__bool__()
       ^^^^^^^^^^^^^^^^^^^^^
   AttributeError: 'pyarrow.lib.Int64Scalar' object has no attribute 
'__bool__'. Did you mean: '__doc__'?
   ```
   
    <details><summary>Also rejected in stubtest if added to scalar.pyi</summary>
    <p>
   
    ```diff
      +++ b/python/pyarrow-stubs/__lib/scalar.pyi
      @@ -53,6 +53,7 @@ class Scalar(_Weakrefable):
           def as_py(self, *, maps_as_pydicts: MapsAsPydicts | None = None) -> 
Any: ...
           def __abs__(self) -> Scalar: ...
      +    def __bool__(self) -> bool: ...
    ```
   
    ```console
      python % python scripts/run_stubtest.py
      error: pyarrow.__lib.scalar.Scalar.__bool__ is not present at runtime
      Stub: in file .../pyarrow/__lib/scalar.pyi:56
      def (self: pyarrow.__lib.scalar.Scalar) -> bool
      Runtime:
      MISSING
    ```
   
    </p>
    </details> 



-- 
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]

Reply via email to