You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "rok (via GitHub)" <gi...@apache.org> on 2025/12/22 00:15:44 UTC

[PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

rok opened a new pull request, #48618:
URL: https://github.com/apache/arrow/pull/48618

   ### Rationale for this change
   
   This is the first in series of PRs adding type annotations to pyarrow and resolving #32609.
   
   ### What changes are included in this PR?
   
   This PR establishes infrastructure for type checking:
   
   - Adds CI workflow for running mypy, pyright, and ty type checkers on linux, macos and windows
   - Configures type checkers to validate stub files (excluding source files for now)
   - Adds PEP 561 `py.typed` marker to enable type checking
   - Updates wheel build scripts to include stub files in distributions
   - Creates initial minimal stub directory structure
   - Updates developer documentation with type checking workflow
   
   ### Are these changes tested?
   
   No. This is mostly a CI change.
   
   ### Are there any user-facing changes?
   
   This does not add any actual annotations (only `py.typed` marker) so user should not be affected.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2723060923


##########
.github/workflows/python.yml:
##########
@@ -239,6 +239,11 @@ jobs:
       - name: Test
         shell: bash
         run: ci/scripts/python_test.sh $(pwd) $(pwd)/build
+      - name: Test annotations
+        shell: bash
+        env:
+          PYARROW_TEST_ANNOTATIONS: "ON"
+        run: ci/scripts/python_test_type_annotations.sh $(pwd)/python

Review Comment:
   It's too bad. I reverted back to workflow approach, but only put the annotation job into a [single workflow](https://github.com/apache/arrow/actions/runs/21296430064/job/61303194983?pr=48618#step:6:8634) now.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2722011277


##########
python/pyarrow-stubs/pyarrow/__init__.pyi:
##########
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Type stubs for PyArrow.
+
+This is a placeholder stub file.
+Complete type annotations will be added in subsequent PRs.
+"""
+
+from typing import Any
+
+def __getattr__(name: str) -> Any: ...

Review Comment:
   https://github.com/apache/arrow/issues/48970



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3751078698

   @github-actions crossbow submit wheel-manylinux-2-28-cp311-cp311-amd64


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3750756088

   Revision: c23cb9ce13e819417d96eab04cb4a75fab36815a
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-286c26b719](https://github.com/ursacomputing/crossbow/branches/all?query=actions-286c26b719)
   
   |Task|Status|
   |----|------|
   |wheel-manylinux-2-28-cp311-cp311-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-286c26b719-github-wheel-manylinux-2-28-cp311-cp311-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21003765891/job/60380568543)|


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3750842254

   @raulcd I've factored out `griffe` and `click`, but we still need `libcst` (using `ast` would not provide stable syntax here). I think wheel builds should now pass. Please take another look when you have time.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "dangotbanned (via GitHub)" <gi...@apache.org>.
dangotbanned commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2720997888


##########
python/pyarrow-stubs/pyarrow/__init__.pyi:
##########
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Type stubs for PyArrow.
+
+This is a placeholder stub file.
+Complete type annotations will be added in subsequent PRs.
+"""
+
+from typing import Any
+
+def __getattr__(name: str) -> Any: ...

Review Comment:
   IIUC this isn't intended to be permanent.
   But I thought you *might* want to consider adding a note/opening an issue to remove it before release.
   
   Here's some examples of how it can mask runtime errors:
   
   - https://github.com/narwhals-dev/narwhals/pull/3333
   - https://github.com/pola-rs/polars/issues/24334



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3796617719

   @kou thanks for the review. Annotations test now runs on the pre-commit as well.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3801949429

   ```
   Unable to match any tasks for `wheel-314`
   The Archery job run can be found at: https://github.com/apache/arrow/actions/runs/21375451226
   ```


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3801905952

   @github-actions crossbow submit wheel-314


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749655642


##########
python/setup.py:
##########
@@ -121,8 +121,28 @@ def build_extensions(self):
 
     def run(self):
         self._run_cmake()
+        self._update_stubs()
         _build_ext.run(self)
 
+    def _update_stubs(self):
+        """Update stub docstrings and copy to build directory."""
+        stubs_dir = pjoin(setup_dir, 'pyarrow-stubs')
+        if not os.path.exists(stubs_dir):
+            return
+
+        build_cmd = self.get_finalized_command('build')
+        build_lib = os.path.abspath(build_cmd.build_lib)
+
+        # Import here to avoid hard dependency on the dev script

Review Comment:
   I forget what the thought was. Removed.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3686108349

   Yes, let's wait for Raul 👍 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2727483814


##########
ci/scripts/python_wheel_macos_build.sh:
##########
@@ -177,6 +177,11 @@ export CMAKE_PREFIX_PATH=${build_dir}/install
 export SETUPTOOLS_SCM_PRETEND_VERSION=${PYARROW_VERSION}
 
 pushd ${source_dir}/python
+# We first populate stub docstrings and then build the wheel
+python setup.py build_ext --inplace

Review Comment:
   Yes, we're building twice. Once to get docstrings at runtime, which we then insert into annotations and then we build one more time to get a wheel with annotations (with docstrings) included. If there's a way to avoid one build I'd be interested!



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749610654


##########
dev/update_stub_docstrings.py:
##########
@@ -0,0 +1,233 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Extract docstrings from pyarrow runtime and insert them into stub files.
+
+Usage (from python/ directory with pyarrow built):
+    python ../dev/update_stub_docstrings.py pyarrow-stubs
+"""
+
+import argparse
+import importlib
+import inspect
+import shutil
+import sys
+from pathlib import Path
+from textwrap import indent
+
+import libcst
+from libcst import matchers as m
+
+
+def _resolve_object(module, path):
+    """Resolve an object by dotted path from a module."""
+    if not path:
+        return module, None, module.__name__
+
+    parts = path.split(".")
+    parent = None
+    obj = module
+
+    for part in parts:
+        parent = obj
+        try:
+            obj = getattr(obj, part)
+        except AttributeError:
+            try:
+                obj = vars(parent).get(part)
+                if obj is not None:
+                    continue
+            except TypeError:
+                pass
+            return None, None, None
+
+    return obj, parent, getattr(obj, "__name__", parts[-1])
+
+
+def _get_docstring(name, module, indentation):
+    """Extract and format a docstring for insertion into a stub file."""
+    obj, parent, obj_name = _resolve_object(module, name)
+    if obj is None:
+        print(f"{name} not found in {module.__name__}")
+        return None
+
+    docstring = inspect.getdoc(obj)
+    if not docstring:
+        return None
+
+    # Remove signature prefix
+    parent_name = getattr(parent, "__name__", None) if parent else None
+    if docstring.startswith(obj_name) or (
+        parent_name and docstring.startswith(f"{parent_name}.{obj_name}")
+    ):
+        docstring = "\n".join(docstring.splitlines()[2:])
+
+    # Skip empty docstrings
+    if not docstring.strip():
+        return None
+
+    prefix = "    " * indentation
+    return '"""\n' + indent(docstring + '\n"""', prefix)
+
+
+class DocstringInserter(libcst.CSTTransformer):
+    """CST transformer that inserts docstrings into stub file nodes."""
+
+    def __init__(self, module, namespace):
+        self.module = module
+        self.base_namespace = namespace
+        self.stack = []
+        self.indentation = 0
+
+    def _full_name(self):
+        name = ".".join(self.stack)
+        return f"{self.base_namespace}.{name}" if self.base_namespace else name
+
+    def leave_Module(self, original_node, updated_node):
+        new_body = []
+        clone_matcher = m.SimpleStatementLine(
+            body=[m.Assign(value=m.Call(func=m.Name(value="_clone_signature"))),
+                  m.ZeroOrMore()]
+        )
+        for stmt in updated_node.body:
+            new_body.append(stmt)
+            if m.matches(stmt, clone_matcher):
+                name = stmt.body[0].targets[0].target.value
+                if self.base_namespace:
+                    name = f"{self.base_namespace}.{name}"
+                docstring = _get_docstring(name, self.module, 0)
+                if docstring:
+                    new_body.append(libcst.SimpleStatementLine(
+                        body=[libcst.Expr(value=libcst.SimpleString(docstring))]))
+        return updated_node.with_changes(body=new_body)
+
+    def visit_ClassDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_ClassDef(self, original_node, updated_node):
+        name = self._full_name()
+        docstring = _get_docstring(name, self.module, self.indentation)
+
+        if docstring:
+            ellipsis_class = m.ClassDef(body=m.IndentedBlock(body=[
+                m.SimpleStatementLine(body=[
+                    m.Expr(m.Ellipsis()), m.ZeroOrMore()]), m.ZeroOrMore()]))
+            func_class = m.ClassDef(body=m.IndentedBlock(
+                body=[m.FunctionDef(), m.ZeroOrMore()]))
+
+            if m.matches(updated_node, ellipsis_class):
+                updated_node = updated_node.deep_replace(
+                    updated_node.body.body[0].body[0].value,
+                    libcst.SimpleString(value=docstring))
+            elif m.matches(updated_node, func_class):
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=updated_node.body.with_changes(
+                        body=[docstring_stmt] + list(updated_node.body.body)))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+    def visit_FunctionDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_FunctionDef(self, original_node, updated_node):
+        name = self._full_name()
+        ellipsis_func = m.FunctionDef(
+            body=m.SimpleStatementSuite(body=[m.Expr(m.Ellipsis())]))
+
+        if m.matches(original_node, ellipsis_func):
+            docstring = _get_docstring(name, self.module, self.indentation)
+            if docstring:
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=libcst.IndentedBlock(body=[docstring_stmt]))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+
+LIB_MODULES = {"array", "builder", "compat", "config", "device", "error", "io",
+               "_ipc", "memory", "pandas_shim", "scalar", "table", "tensor", "_types"}
+
+
+def add_docstrings_to_stubs(stubs_dir):
+    """Update all stub files in stubs_dir with docstrings from pyarrow runtime."""
+    stubs_dir = Path(stubs_dir)
+    print(f"Updating stub docstrings in: {stubs_dir}")
+
+    pyarrow = importlib.import_module("pyarrow")
+
+    for stub_file in stubs_dir.rglob('*.pyi'):
+        if stub_file.name == "_stubs_typing.pyi":
+            continue
+
+        module_name = stub_file.stem
+        if module_name in LIB_MODULES:
+            namespace = "lib"
+        elif stub_file.parent.name in ("parquet", "interchange"):
+            namespace = f"{stub_file.parent.name}.{module_name}"
+        elif module_name == "__init__":
+            namespace = ""
+        else:
+            namespace = module_name
+
+        print(f"  {stub_file.name} -> {namespace or '(root)'}")
+        tree = libcst.parse_module(stub_file.read_text())
+        modified = tree.visit(DocstringInserter(pyarrow, namespace))
+        stub_file.write_text(modified.code)
+
+
+def copy_stubs(src_dir, dest_dir):
+    """Copy .pyi files from src_dir to dest_dir."""
+    src_dir, dest_dir = Path(src_dir), Path(dest_dir)
+    if not src_dir.exists():
+        return
+
+    print(f"Copying stubs: {src_dir} -> {dest_dir}")
+    for src in src_dir.rglob('*.pyi'):
+        dest = dest_dir / src.relative_to(src_dir)
+        dest.parent.mkdir(parents=True, exist_ok=True)
+        shutil.copy2(src, dest)
+
+
+def update_stubs_for_build(stubs_dir, build_lib):
+    """Entry point for setup.py: update docstrings and copy stubs to build dir."""
+    stubs_dir, build_lib = Path(stubs_dir), Path(build_lib)
+
+    sys.path.insert(0, str(build_lib))
+    try:
+        add_docstrings_to_stubs(stubs_dir)
+        copy_stubs(stubs_dir / "pyarrow", build_lib / "pyarrow")
+    finally:
+        sys.path.pop(0)
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument("stubs_dir", type=Path, help="Path to pyarrow-stubs folder")
+    args = parser.parse_args()
+
+    sys.path.insert(0, ".")

Review Comment:
   Using `setup_dir` now.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749625197


##########
python/scripts/update_stub_docstrings.py:
##########


Review Comment:
   Moved.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3828707275

   :warning: GitHub issue #49102 **has been automatically assigned in GitHub** to PR creator.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2690106092


##########
ci/scripts/python_wheel_macos_build.sh:
##########
@@ -175,6 +175,11 @@ export CMAKE_PREFIX_PATH=${build_dir}/install
 export SETUPTOOLS_SCM_PRETEND_VERSION=${PYARROW_VERSION}
 
 pushd ${source_dir}/python
+# We first populate stub docstrings and then build the wheel
+python setup.py build_ext --inplace
+python -m pip install griffe libcst
+python ../dev/update_stub_docstrings.py pyarrow-stubs

Review Comment:
   this is not necessary, right?



##########
ci/scripts/python_wheel_validate_contents.py:
##########
@@ -35,6 +35,11 @@ def validate_wheel(path):
     assert not outliers, f"Unexpected contents in wheel: {sorted(outliers)}"
     print(f"The wheel: {wheels[0]} seems valid.")
 
+    candidates = [info for info in f.filelist if info.filename.endswith('compute.pyi')]

Review Comment:
   We should remove this until we have real annotations otherwise it will fail, `compute.pyi` won't exist, right?



##########
ci/scripts/python_wheel_windows_build.bat:
##########
@@ -135,6 +135,10 @@ pushd C:\arrow\python
 @REM Build wheel
 %PYTHON_CMD% setup.py bdist_wheel || exit /B 1
 
+@REM We first populate stub docstrings and then build the wheel
+%PYTHON_CMD% setup.py build_ext --inplace
+%PYTHON_CMD% -m pip install griffe libcst

Review Comment:
   Until we have real annotations this isn't necessary, right?



##########
compose.yaml:
##########
@@ -1001,14 +1003,16 @@ services:
       ARROW_S3: "OFF"
       ARROW_SUBSTRAIT: "OFF"
       ARROW_WITH_OPENTELEMETRY: "OFF"
+      PYARROW_TEST_ANNOTATIONS: "ON"

Review Comment:
   I think is worth it if instead of using a separate `ci/scripts/python_test_type_annotations.sh` we use `ci/scripts/python_test.sh` and we use the `PYARROW_TEST_ANNOTATIONS` variable to manage whether we want annotations to be tested or not as part of python testing.
   If we decide we want to have two separate scripts I think this env var should be removed.
   I lean towards having a single python test script that can allow us to also test annotations but I can find arguments for both so not an issue.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2690911440


##########
ci/scripts/python_wheel_validate_contents.py:
##########
@@ -35,6 +35,11 @@ def validate_wheel(path):
     assert not outliers, f"Unexpected contents in wheel: {sorted(outliers)}"
     print(f"The wheel: {wheels[0]} seems valid.")
 
+    candidates = [info for info in f.filelist if info.filename.endswith('compute.pyi')]

Review Comment:
   Replaced with TODO.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749620476


##########
python/setup.py:
##########
@@ -121,8 +121,28 @@ def build_extensions(self):
 
     def run(self):
         self._run_cmake()
+        self._update_stubs()
         _build_ext.run(self)
 
+    def _update_stubs(self):
+        """Update stub docstrings and copy to build directory."""
+        stubs_dir = pjoin(setup_dir, 'pyarrow-stubs')
+        if not os.path.exists(stubs_dir):
+            return
+
+        build_cmd = self.get_finalized_command('build')
+        build_lib = os.path.abspath(build_cmd.build_lib)
+
+        # Import here to avoid hard dependency on the dev script
+        sys.path.insert(0, pjoin(setup_dir, '..', 'dev'))
+        try:
+            from update_stub_docstrings import update_stubs_for_build
+            update_stubs_for_build(stubs_dir, build_lib)
+        except ImportError:
+            print("-- Skipping stubs (update_stub_docstrings.py not found)")

Review Comment:
   Indeed, removing.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749609044


##########
ci/scripts/python_wheel_validate_contents.py:
##########
@@ -34,7 +34,7 @@ def validate_wheel(path):
     ]
     assert not outliers, f"Unexpected contents in wheel: {sorted(outliers)}"
     print(f"The wheel: {wheels[0]} seems valid.")
-
+    # TODO(GH-32609): Validate some docstrings were generated and added.

Review Comment:
   Will do.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3847924979

   @raulcd could you do a final review?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2642761216


##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+
+if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then
+  # Install library stubs
+  pip install pandas-stubs scipy-stubs sphinx types-cffi types-psutil types-requests types-python-dateutil

Review Comment:
   If I remove sphinx I get the following on the final PR:
   ```
   pyarrow/vendored/docscrape.py:622: error: Cannot find implementation or library stub for module named "sphinx.ext.autodoc"  [import-not-found]
   pyarrow/vendored/docscrape.py:622: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
   ```
   
   So sphinx is not needed for functioning of pyarrow and it's probably better to then inline ignore this error (once we enable typechecking). Will remove sphinx here.



##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+
+if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then
+  # Install library stubs
+  pip install pandas-stubs scipy-stubs sphinx types-cffi types-psutil types-requests types-python-dateutil

Review Comment:
   ```suggestion
     pip install pandas-stubs scipy-stubs types-cffi types-psutil types-requests types-python-dateutil
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3792836974

   Docs failure is from the [Pandas issue](https://github.com/apache/arrow/issues/48970).


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3797492681

   Thanks. Can we merge this? Do we need more reviews before we merge this?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3799396961

   Revision: 6bc241a45195e2ac18cb0716f0f73abce280028d
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-c06469d4d8](https://github.com/ursacomputing/crossbow/branches/all?query=actions-c06469d4d8)
   
   |Task|Status|
   |----|------|
   |wheel-macos-monterey-cp314-cp314-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-macos-monterey-cp314-cp314-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865604/job/61469490986)|
   |wheel-macos-monterey-cp314-cp314-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-macos-monterey-cp314-cp314-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865083/job/61469489335)|
   |wheel-macos-monterey-cp314-cp314t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-macos-monterey-cp314-cp314t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865078/job/61469489326)|
   |wheel-macos-monterey-cp314-cp314t-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-macos-monterey-cp314-cp314t-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865292/job/61469489918)|
   |wheel-manylinux-2-28-cp314-cp314-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-manylinux-2-28-cp314-cp314-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865042/job/61469489546)|
   |wheel-manylinux-2-28-cp314-cp314-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-manylinux-2-28-cp314-cp314-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865605/job/61469490934)|
   |wheel-manylinux-2-28-cp314-cp314t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-manylinux-2-28-cp314-cp314t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865456/job/61469490395)|
   |wheel-manylinux-2-28-cp314-cp314t-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-manylinux-2-28-cp314-cp314t-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865625/job/61469491050)|
   |wheel-musllinux-1-2-cp314-cp314-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-musllinux-1-2-cp314-cp314-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865578/job/61469490884)|
   |wheel-musllinux-1-2-cp314-cp314-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-musllinux-1-2-cp314-cp314-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865332/job/61469490316)|
   |wheel-musllinux-1-2-cp314-cp314t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-musllinux-1-2-cp314-cp314t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865213/job/61469489645)|
   |wheel-musllinux-1-2-cp314-cp314t-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-musllinux-1-2-cp314-cp314t-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865628/job/61469491215)|
   |wheel-windows-cp314-cp314-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-windows-cp314-cp314-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865257/job/61469489792)|
   |wheel-windows-cp314-cp314t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-c06469d4d8-github-wheel-windows-cp314-cp314t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21357865781/job/61469491483)|


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2722102395


##########
.github/workflows/python.yml:
##########
@@ -239,6 +239,11 @@ jobs:
       - name: Test
         shell: bash
         run: ci/scripts/python_test.sh $(pwd) $(pwd)/build
+      - name: Test annotations
+        shell: bash
+        env:
+          PYARROW_TEST_ANNOTATIONS: "ON"
+        run: ci/scripts/python_test_type_annotations.sh $(pwd)/python

Review Comment:
   Oh wait, we need compiled pyarrow to run type annotation checks against and that is not practical for pre-commit.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3751089577

   Revision: 491ff2c4f2236135674d3cbe953614fdb806c5de
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-b6331706da](https://github.com/ursacomputing/crossbow/branches/all?query=actions-b6331706da)
   
   |Task|Status|
   |----|------|
   |wheel-manylinux-2-28-cp311-cp311-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-b6331706da-github-wheel-manylinux-2-28-cp311-cp311-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21005963502/job/60388257145)|


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3799384172

   @github-actions crossbow submit wheel-*314*


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3801992432

   Revision: de7883d05ea0958ef56230c314c2a7f54a8391d8
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-fbb5798826](https://github.com/ursacomputing/crossbow/branches/all?query=actions-fbb5798826)
   
   |Task|Status|
   |----|------|
   |wheel-macos-monterey-cp310-cp310-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp310-cp310-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809482/job/61531547633)|
   |wheel-macos-monterey-cp310-cp310-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp310-cp310-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808639/job/61531544577)|
   |wheel-macos-monterey-cp311-cp311-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp311-cp311-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375807717/job/61531542016)|
   |wheel-macos-monterey-cp311-cp311-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp311-cp311-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810713/job/61531551754)|
   |wheel-macos-monterey-cp312-cp312-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp312-cp312-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810395/job/61531550454)|
   |wheel-macos-monterey-cp312-cp312-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp312-cp312-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810731/job/61531551622)|
   |wheel-macos-monterey-cp313-cp313-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp313-cp313-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809047/job/61531545889)|
   |wheel-macos-monterey-cp313-cp313-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp313-cp313-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809271/job/61531546657)|
   |wheel-macos-monterey-cp313-cp313t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp313-cp313t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808163/job/61531543346)|
   |wheel-macos-monterey-cp313-cp313t-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp313-cp313t-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810300/job/61531550257)|
   |wheel-macos-monterey-cp314-cp314-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp314-cp314-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808331/job/61531543810)|
   |wheel-macos-monterey-cp314-cp314-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp314-cp314-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809470/job/61531547538)|
   |wheel-macos-monterey-cp314-cp314t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp314-cp314t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809457/job/61531547625)|
   |wheel-macos-monterey-cp314-cp314t-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-macos-monterey-cp314-cp314t-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810032/job/61531549246)|
   |wheel-manylinux-2-28-cp310-cp310-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp310-cp310-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809614/job/61531548887)|
   |wheel-manylinux-2-28-cp310-cp310-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp310-cp310-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809637/job/61531549407)|
   |wheel-manylinux-2-28-cp311-cp311-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp311-cp311-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810561/job/61531550850)|
   |wheel-manylinux-2-28-cp311-cp311-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp311-cp311-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809651/job/61531548090)|
   |wheel-manylinux-2-28-cp312-cp312-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp312-cp312-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810430/job/61531550628)|
   |wheel-manylinux-2-28-cp312-cp312-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp312-cp312-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810019/job/61531549368)|
   |wheel-manylinux-2-28-cp313-cp313-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp313-cp313-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809956/job/61531549129)|
   |wheel-manylinux-2-28-cp313-cp313-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp313-cp313-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809699/job/61531548174)|
   |wheel-manylinux-2-28-cp313-cp313t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp313-cp313t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375807653/job/61531542013)|
   |wheel-manylinux-2-28-cp313-cp313t-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp313-cp313t-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810525/job/61531550855)|
   |wheel-manylinux-2-28-cp314-cp314-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp314-cp314-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375807920/job/61531542702)|
   |wheel-manylinux-2-28-cp314-cp314-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp314-cp314-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375807894/job/61531542422)|
   |wheel-manylinux-2-28-cp314-cp314t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp314-cp314t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808928/job/61531545491)|
   |wheel-manylinux-2-28-cp314-cp314t-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-manylinux-2-28-cp314-cp314t-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810264/job/61531549915)|
   |wheel-musllinux-1-2-cp310-cp310-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp310-cp310-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808913/job/61531545440)|
   |wheel-musllinux-1-2-cp310-cp310-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp310-cp310-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810666/job/61531551511)|
   |wheel-musllinux-1-2-cp311-cp311-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp311-cp311-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375807744/job/61531542136)|
   |wheel-musllinux-1-2-cp311-cp311-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp311-cp311-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809313/job/61531546984)|
   |wheel-musllinux-1-2-cp312-cp312-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp312-cp312-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809690/job/61531548159)|
   |wheel-musllinux-1-2-cp312-cp312-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp312-cp312-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375807929/job/61531542578)|
   |wheel-musllinux-1-2-cp313-cp313-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp313-cp313-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375807949/job/61531542657)|
   |wheel-musllinux-1-2-cp313-cp313-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp313-cp313-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808481/job/61531544155)|
   |wheel-musllinux-1-2-cp313-cp313t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp313-cp313t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808826/job/61531545306)|
   |wheel-musllinux-1-2-cp313-cp313t-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp313-cp313t-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809270/job/61531546621)|
   |wheel-musllinux-1-2-cp314-cp314-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp314-cp314-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808176/job/61531543367)|
   |wheel-musllinux-1-2-cp314-cp314-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp314-cp314-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809247/job/61531546590)|
   |wheel-musllinux-1-2-cp314-cp314t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp314-cp314t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375807677/job/61531541964)|
   |wheel-musllinux-1-2-cp314-cp314t-arm64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-musllinux-1-2-cp314-cp314t-arm64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809603/job/61531547891)|
   |wheel-windows-cp310-cp310-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-windows-cp310-cp310-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808476/job/61531545111)|
   |wheel-windows-cp311-cp311-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-windows-cp311-cp311-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808632/job/61531544511)|
   |wheel-windows-cp312-cp312-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-windows-cp312-cp312-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808677/job/61531544789)|
   |wheel-windows-cp313-cp313-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-windows-cp313-cp313-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375809117/job/61531546204)|
   |wheel-windows-cp313-cp313t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-windows-cp313-cp313t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808318/job/61531543843)|
   |wheel-windows-cp314-cp314-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-windows-cp314-cp314-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375808027/job/61531542923)|
   |wheel-windows-cp314-cp314t-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-fbb5798826-github-wheel-windows-cp314-cp314t-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21375810199/job/61531549853)|


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "dangotbanned (via GitHub)" <gi...@apache.org>.
dangotbanned commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2737088499


##########
python/pyproject.toml:
##########
@@ -84,15 +86,51 @@ zip-safe=false
 include-package-data=true
 
 [tool.setuptools.packages.find]
-include = ["pyarrow"]
+include = ["pyarrow", "pyarrow.*"]
 namespaces = false
 
 [tool.setuptools.package-data]
-pyarrow = ["*.pxd", "*.pyx", "includes/*.pxd"]
+pyarrow = ["*.pxd", "*.pyi", "*.pyx", "includes/*.pxd", "py.typed"]
 
 [tool.setuptools_scm]
 root = '..'
 version_file = 'pyarrow/_generated_version.py'
 version_scheme = 'guess-next-dev'
 git_describe_command = 'git describe --dirty --tags --long --match "apache-arrow-[0-9]*.*"'
 fallback_version = '24.0.0a0'
+
+# TODO: Enable type checking once stubs are merged
+[tool.mypy]
+files = ["pyarrow-stubs"]
+mypy_path = "$MYPY_CONFIG_FILE_DIR/pyarrow-stubs"
+exclude = [
+    "^pyarrow/",
+    "^benchmarks/",
+    "^examples/",
+    "^scripts/",
+]
+
+# TODO: Enable type checking once stubs are merged
+[tool.pyright]
+pythonPlatform = "All"
+pythonVersion = "3.10"

Review Comment:
   I think this came from a suggestion I made on the other PR.
   
   The idea is that setting `pythonVersion` to your minimum target will mean that you get a warning if you use typing features not available in all supported versions.
   
   For example, [PEP 695](https://peps.python.org/pep-0695/) syntax will be fine once support for `3.10`, `3.11` is dropped and then this is updated to `pythonVersion = "3.12"`



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2689908680


##########
ci/scripts/python_test_type_annotations.bat:
##########
@@ -0,0 +1,38 @@
+@rem Licensed to the Apache Software Foundation (ASF) under one
+@rem or more contributor license agreements.  See the NOTICE file
+@rem distributed with this work for additional information
+@rem regarding copyright ownership.  The ASF licenses this file
+@rem to you under the Apache License, Version 2.0 (the
+@rem "License"); you may not use this file except in compliance
+@rem with the License.  You may obtain a copy of the License at
+@rem
+@rem   http://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing,
+@rem software distributed under the License is distributed on an
+@rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@rem KIND, either express or implied.  See the License for the
+@rem specific language governing permissions and limitations
+@rem under the License.
+
+@echo on
+
+set PYARROW_DIR=%1
+
+echo Annotation testing on Windows ...
+
+@REM Install library stubs
+%PYTHON_CMD% -m pip install pandas-stubs scipy-stubs sphinx types-cffi types-psutil types-requests types-python-dateutil || exit /B 1
+
+@REM Install other dependencies for type checking

Review Comment:
   Fspec contains its own type annotations and it's nice we have these when checking our filesystem integrations.



##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+

Review Comment:
   Good point, adding.



##########
docs/source/developers/python/development.rst:
##########
@@ -42,7 +42,7 @@ Unit Testing
 ============
 
 We are using `pytest <https://docs.pytest.org/en/latest/>`_ to develop our unit
-test suite. After `building the project <build_pyarrow>`_ you can run its unit tests
+test suite. After `building the project <building.html>`_ you can run its unit tests

Review Comment:
   Huh, I have forgotten what this was about and I think you're right. Reverting.



##########
ci/scripts/python_wheel_validate_contents.py:
##########
@@ -35,6 +35,11 @@ def validate_wheel(path):
     assert not outliers, f"Unexpected contents in wheel: {sorted(outliers)}"
     print(f"The wheel: {wheels[0]} seems valid.")
 
+    candidates = [info for info in f.filelist if info.filename.endswith('compute.pyi')]

Review Comment:
   Yes, that's true. Accepting suggestion.



##########
ci/scripts/python_wheel_xlinux_build.sh:
##########
@@ -167,6 +167,11 @@ export ARROW_HOME=/tmp/arrow-dist
 export CMAKE_PREFIX_PATH=/tmp/arrow-dist
 
 pushd /arrow/python
+# We first populate stub docstrings and then build the wheel
+python setup.py build_ext --inplace
+python -m pip install griffe libcst
+python ../dev/update_stub_docstrings.py pyarrow-stubs

Review Comment:
   Yes, removing.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749607263


##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+
+if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then

Review Comment:
   Removing here.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749653812


##########
python/pyproject.toml:
##########
@@ -18,6 +18,8 @@
 [build-system]
 requires = [
     "cython >= 3.1",
+    # Needed for build-time stub docstring extraction
+    "libcst>=1.8.6",

Review Comment:
   That is probably best done in another PR?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3686093556

   Thanks for review @AlenkaF ! I think we probably want @raulcd to look at this too before merging?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2725343303


##########
ci/scripts/python_test_type_annotations.sh:
##########


Review Comment:
   Done.
   Do any of these scripts actually build pyarrow that we could test annotations against?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3750736236

   @github-actions crossbow submit wheel-manylinux-2-28-cp311-cp311-amd64


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3750979507

   wheel-manylinux-2-28-cp311-cp311-amd64


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3852566803

   I rebased on main to fix the docs CI issues.
   I'd like to continue on the annotation PRs next week so I'll merge Sunday evening.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2753972873


##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+
+if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then

Review Comment:
   I agree with @pitrou my previous comment was that the check is necessary if it gets integrated on the `python_test.sh` script otherwise, if we use a different script as we are currently doing, we should remove it.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "pitrou (via GitHub)" <gi...@apache.org>.
pitrou commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2736825288


##########
ci/scripts/python_wheel_macos_build.sh:
##########
@@ -177,6 +177,8 @@ export CMAKE_PREFIX_PATH=${build_dir}/install
 export SETUPTOOLS_SCM_PRETEND_VERSION=${PYARROW_VERSION}
 
 pushd ${source_dir}/python
+# Install libcst for build-time stub docstring extraction
+python -m pip install libcst

Review Comment:
   Should we add this to `requirements-wheel-build.txt`? What do you think @raulcd ?



##########
dev/update_stub_docstrings.py:
##########
@@ -0,0 +1,233 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Extract docstrings from pyarrow runtime and insert them into stub files.
+
+Usage (from python/ directory with pyarrow built):
+    python ../dev/update_stub_docstrings.py pyarrow-stubs
+"""
+
+import argparse
+import importlib
+import inspect
+import shutil
+import sys
+from pathlib import Path
+from textwrap import indent
+
+import libcst
+from libcst import matchers as m
+
+
+def _resolve_object(module, path):
+    """Resolve an object by dotted path from a module."""
+    if not path:
+        return module, None, module.__name__
+
+    parts = path.split(".")
+    parent = None
+    obj = module
+
+    for part in parts:
+        parent = obj
+        try:
+            obj = getattr(obj, part)
+        except AttributeError:
+            try:
+                obj = vars(parent).get(part)
+                if obj is not None:
+                    continue
+            except TypeError:
+                pass
+            return None, None, None
+
+    return obj, parent, getattr(obj, "__name__", parts[-1])
+
+
+def _get_docstring(name, module, indentation):
+    """Extract and format a docstring for insertion into a stub file."""
+    obj, parent, obj_name = _resolve_object(module, name)
+    if obj is None:
+        print(f"{name} not found in {module.__name__}")
+        return None
+
+    docstring = inspect.getdoc(obj)
+    if not docstring:
+        return None
+
+    # Remove signature prefix
+    parent_name = getattr(parent, "__name__", None) if parent else None
+    if docstring.startswith(obj_name) or (
+        parent_name and docstring.startswith(f"{parent_name}.{obj_name}")
+    ):
+        docstring = "\n".join(docstring.splitlines()[2:])
+
+    # Skip empty docstrings
+    if not docstring.strip():
+        return None
+
+    prefix = "    " * indentation
+    return '"""\n' + indent(docstring + '\n"""', prefix)
+
+
+class DocstringInserter(libcst.CSTTransformer):
+    """CST transformer that inserts docstrings into stub file nodes."""
+
+    def __init__(self, module, namespace):
+        self.module = module
+        self.base_namespace = namespace
+        self.stack = []
+        self.indentation = 0
+
+    def _full_name(self):
+        name = ".".join(self.stack)
+        return f"{self.base_namespace}.{name}" if self.base_namespace else name
+
+    def leave_Module(self, original_node, updated_node):
+        new_body = []
+        clone_matcher = m.SimpleStatementLine(
+            body=[m.Assign(value=m.Call(func=m.Name(value="_clone_signature"))),
+                  m.ZeroOrMore()]
+        )
+        for stmt in updated_node.body:
+            new_body.append(stmt)
+            if m.matches(stmt, clone_matcher):
+                name = stmt.body[0].targets[0].target.value
+                if self.base_namespace:
+                    name = f"{self.base_namespace}.{name}"
+                docstring = _get_docstring(name, self.module, 0)
+                if docstring:
+                    new_body.append(libcst.SimpleStatementLine(
+                        body=[libcst.Expr(value=libcst.SimpleString(docstring))]))
+        return updated_node.with_changes(body=new_body)
+
+    def visit_ClassDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_ClassDef(self, original_node, updated_node):
+        name = self._full_name()
+        docstring = _get_docstring(name, self.module, self.indentation)
+
+        if docstring:
+            ellipsis_class = m.ClassDef(body=m.IndentedBlock(body=[
+                m.SimpleStatementLine(body=[
+                    m.Expr(m.Ellipsis()), m.ZeroOrMore()]), m.ZeroOrMore()]))
+            func_class = m.ClassDef(body=m.IndentedBlock(
+                body=[m.FunctionDef(), m.ZeroOrMore()]))
+
+            if m.matches(updated_node, ellipsis_class):
+                updated_node = updated_node.deep_replace(
+                    updated_node.body.body[0].body[0].value,
+                    libcst.SimpleString(value=docstring))
+            elif m.matches(updated_node, func_class):
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=updated_node.body.with_changes(
+                        body=[docstring_stmt] + list(updated_node.body.body)))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+    def visit_FunctionDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_FunctionDef(self, original_node, updated_node):
+        name = self._full_name()
+        ellipsis_func = m.FunctionDef(
+            body=m.SimpleStatementSuite(body=[m.Expr(m.Ellipsis())]))
+
+        if m.matches(original_node, ellipsis_func):
+            docstring = _get_docstring(name, self.module, self.indentation)
+            if docstring:
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=libcst.IndentedBlock(body=[docstring_stmt]))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+
+LIB_MODULES = {"array", "builder", "compat", "config", "device", "error", "io",
+               "_ipc", "memory", "pandas_shim", "scalar", "table", "tensor", "_types"}
+
+
+def add_docstrings_to_stubs(stubs_dir):
+    """Update all stub files in stubs_dir with docstrings from pyarrow runtime."""
+    stubs_dir = Path(stubs_dir)
+    print(f"Updating stub docstrings in: {stubs_dir}")
+
+    pyarrow = importlib.import_module("pyarrow")
+
+    for stub_file in stubs_dir.rglob('*.pyi'):
+        if stub_file.name == "_stubs_typing.pyi":
+            continue
+
+        module_name = stub_file.stem
+        if module_name in LIB_MODULES:
+            namespace = "lib"
+        elif stub_file.parent.name in ("parquet", "interchange"):
+            namespace = f"{stub_file.parent.name}.{module_name}"
+        elif module_name == "__init__":
+            namespace = ""
+        else:
+            namespace = module_name
+
+        print(f"  {stub_file.name} -> {namespace or '(root)'}")
+        tree = libcst.parse_module(stub_file.read_text())
+        modified = tree.visit(DocstringInserter(pyarrow, namespace))
+        stub_file.write_text(modified.code)
+
+
+def copy_stubs(src_dir, dest_dir):
+    """Copy .pyi files from src_dir to dest_dir."""
+    src_dir, dest_dir = Path(src_dir), Path(dest_dir)
+    if not src_dir.exists():
+        return
+
+    print(f"Copying stubs: {src_dir} -> {dest_dir}")
+    for src in src_dir.rglob('*.pyi'):
+        dest = dest_dir / src.relative_to(src_dir)
+        dest.parent.mkdir(parents=True, exist_ok=True)
+        shutil.copy2(src, dest)
+
+
+def update_stubs_for_build(stubs_dir, build_lib):
+    """Entry point for setup.py: update docstrings and copy stubs to build dir."""
+    stubs_dir, build_lib = Path(stubs_dir), Path(build_lib)
+
+    sys.path.insert(0, str(build_lib))
+    try:
+        add_docstrings_to_stubs(stubs_dir)
+        copy_stubs(stubs_dir / "pyarrow", build_lib / "pyarrow")
+    finally:
+        sys.path.pop(0)
+
+
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument("stubs_dir", type=Path, help="Path to pyarrow-stubs folder")
+    args = parser.parse_args()
+
+    sys.path.insert(0, ".")

Review Comment:
   Can you add an absolute path instead so that this script doesn't depend on the current directory?



##########
ci/scripts/python_wheel_validate_contents.py:
##########
@@ -34,7 +34,7 @@ def validate_wheel(path):
     ]
     assert not outliers, f"Unexpected contents in wheel: {sorted(outliers)}"
     print(f"The wheel: {wheels[0]} seems valid.")
-
+    # TODO(GH-32609): Validate some docstrings were generated and added.

Review Comment:
   Is the type checking is split into several PRs, perhaps create sub-issues for clarify as well?



##########
python/pyproject.toml:
##########
@@ -18,6 +18,8 @@
 [build-system]
 requires = [
     "cython >= 3.1",
+    # Needed for build-time stub docstring extraction
+    "libcst>=1.8.6",

Review Comment:
   At some point we'll want to deduplicate `pyproject.toml` and the various `requirements` files? @raulcd 



##########
python/setup.py:
##########
@@ -121,8 +121,28 @@ def build_extensions(self):
 
     def run(self):
         self._run_cmake()
+        self._update_stubs()
         _build_ext.run(self)
 
+    def _update_stubs(self):
+        """Update stub docstrings and copy to build directory."""
+        stubs_dir = pjoin(setup_dir, 'pyarrow-stubs')
+        if not os.path.exists(stubs_dir):
+            return
+
+        build_cmd = self.get_finalized_command('build')
+        build_lib = os.path.abspath(build_cmd.build_lib)
+
+        # Import here to avoid hard dependency on the dev script
+        sys.path.insert(0, pjoin(setup_dir, '..', 'dev'))
+        try:
+            from update_stub_docstrings import update_stubs_for_build
+            update_stubs_for_build(stubs_dir, build_lib)
+        except ImportError:
+            print("-- Skipping stubs (update_stub_docstrings.py not found)")

Review Comment:
   Why would it not be found? It's in the repo, right?



##########
dev/update_stub_docstrings.py:
##########
@@ -0,0 +1,233 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Extract docstrings from pyarrow runtime and insert them into stub files.
+
+Usage (from python/ directory with pyarrow built):
+    python ../dev/update_stub_docstrings.py pyarrow-stubs
+"""
+
+import argparse
+import importlib
+import inspect
+import shutil
+import sys
+from pathlib import Path
+from textwrap import indent
+
+import libcst
+from libcst import matchers as m
+
+
+def _resolve_object(module, path):
+    """Resolve an object by dotted path from a module."""
+    if not path:
+        return module, None, module.__name__
+
+    parts = path.split(".")
+    parent = None
+    obj = module
+
+    for part in parts:
+        parent = obj
+        try:
+            obj = getattr(obj, part)
+        except AttributeError:
+            try:
+                obj = vars(parent).get(part)
+                if obj is not None:
+                    continue
+            except TypeError:
+                pass
+            return None, None, None
+
+    return obj, parent, getattr(obj, "__name__", parts[-1])
+
+
+def _get_docstring(name, module, indentation):
+    """Extract and format a docstring for insertion into a stub file."""
+    obj, parent, obj_name = _resolve_object(module, name)
+    if obj is None:
+        print(f"{name} not found in {module.__name__}")
+        return None
+
+    docstring = inspect.getdoc(obj)
+    if not docstring:
+        return None
+
+    # Remove signature prefix
+    parent_name = getattr(parent, "__name__", None) if parent else None
+    if docstring.startswith(obj_name) or (
+        parent_name and docstring.startswith(f"{parent_name}.{obj_name}")
+    ):
+        docstring = "\n".join(docstring.splitlines()[2:])
+
+    # Skip empty docstrings
+    if not docstring.strip():
+        return None
+
+    prefix = "    " * indentation
+    return '"""\n' + indent(docstring + '\n"""', prefix)
+
+
+class DocstringInserter(libcst.CSTTransformer):
+    """CST transformer that inserts docstrings into stub file nodes."""
+
+    def __init__(self, module, namespace):
+        self.module = module
+        self.base_namespace = namespace
+        self.stack = []
+        self.indentation = 0
+
+    def _full_name(self):
+        name = ".".join(self.stack)
+        return f"{self.base_namespace}.{name}" if self.base_namespace else name
+
+    def leave_Module(self, original_node, updated_node):
+        new_body = []
+        clone_matcher = m.SimpleStatementLine(
+            body=[m.Assign(value=m.Call(func=m.Name(value="_clone_signature"))),
+                  m.ZeroOrMore()]
+        )
+        for stmt in updated_node.body:
+            new_body.append(stmt)
+            if m.matches(stmt, clone_matcher):
+                name = stmt.body[0].targets[0].target.value
+                if self.base_namespace:
+                    name = f"{self.base_namespace}.{name}"
+                docstring = _get_docstring(name, self.module, 0)
+                if docstring:
+                    new_body.append(libcst.SimpleStatementLine(
+                        body=[libcst.Expr(value=libcst.SimpleString(docstring))]))
+        return updated_node.with_changes(body=new_body)
+
+    def visit_ClassDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_ClassDef(self, original_node, updated_node):
+        name = self._full_name()
+        docstring = _get_docstring(name, self.module, self.indentation)
+
+        if docstring:
+            ellipsis_class = m.ClassDef(body=m.IndentedBlock(body=[
+                m.SimpleStatementLine(body=[
+                    m.Expr(m.Ellipsis()), m.ZeroOrMore()]), m.ZeroOrMore()]))
+            func_class = m.ClassDef(body=m.IndentedBlock(
+                body=[m.FunctionDef(), m.ZeroOrMore()]))
+
+            if m.matches(updated_node, ellipsis_class):
+                updated_node = updated_node.deep_replace(
+                    updated_node.body.body[0].body[0].value,
+                    libcst.SimpleString(value=docstring))
+            elif m.matches(updated_node, func_class):
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=updated_node.body.with_changes(
+                        body=[docstring_stmt] + list(updated_node.body.body)))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+    def visit_FunctionDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_FunctionDef(self, original_node, updated_node):
+        name = self._full_name()
+        ellipsis_func = m.FunctionDef(
+            body=m.SimpleStatementSuite(body=[m.Expr(m.Ellipsis())]))
+
+        if m.matches(original_node, ellipsis_func):
+            docstring = _get_docstring(name, self.module, self.indentation)
+            if docstring:
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=libcst.IndentedBlock(body=[docstring_stmt]))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+
+LIB_MODULES = {"array", "builder", "compat", "config", "device", "error", "io",
+               "_ipc", "memory", "pandas_shim", "scalar", "table", "tensor", "_types"}
+
+
+def add_docstrings_to_stubs(stubs_dir):
+    """Update all stub files in stubs_dir with docstrings from pyarrow runtime."""
+    stubs_dir = Path(stubs_dir)
+    print(f"Updating stub docstrings in: {stubs_dir}")
+
+    pyarrow = importlib.import_module("pyarrow")
+
+    for stub_file in stubs_dir.rglob('*.pyi'):
+        if stub_file.name == "_stubs_typing.pyi":
+            continue
+
+        module_name = stub_file.stem
+        if module_name in LIB_MODULES:
+            namespace = "lib"
+        elif stub_file.parent.name in ("parquet", "interchange"):
+            namespace = f"{stub_file.parent.name}.{module_name}"
+        elif module_name == "__init__":
+            namespace = ""
+        else:
+            namespace = module_name
+
+        print(f"  {stub_file.name} -> {namespace or '(root)'}")
+        tree = libcst.parse_module(stub_file.read_text())
+        modified = tree.visit(DocstringInserter(pyarrow, namespace))
+        stub_file.write_text(modified.code)
+
+
+def copy_stubs(src_dir, dest_dir):
+    """Copy .pyi files from src_dir to dest_dir."""
+    src_dir, dest_dir = Path(src_dir), Path(dest_dir)
+    if not src_dir.exists():
+        return
+
+    print(f"Copying stubs: {src_dir} -> {dest_dir}")
+    for src in src_dir.rglob('*.pyi'):
+        dest = dest_dir / src.relative_to(src_dir)
+        dest.parent.mkdir(parents=True, exist_ok=True)
+        shutil.copy2(src, dest)
+
+
+def update_stubs_for_build(stubs_dir, build_lib):
+    """Entry point for setup.py: update docstrings and copy stubs to build dir."""
+    stubs_dir, build_lib = Path(stubs_dir), Path(build_lib)
+
+    sys.path.insert(0, str(build_lib))
+    try:
+        add_docstrings_to_stubs(stubs_dir)
+        copy_stubs(stubs_dir / "pyarrow", build_lib / "pyarrow")

Review Comment:
   It would seem more logical to copy in `setup.py`. @raulcd What do you think?



##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+
+if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then

Review Comment:
   Why this? Presumably one should only call this script if they want to actually check annotations?



##########
dev/update_stub_docstrings.py:
##########
@@ -0,0 +1,233 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Extract docstrings from pyarrow runtime and insert them into stub files.
+
+Usage (from python/ directory with pyarrow built):
+    python ../dev/update_stub_docstrings.py pyarrow-stubs
+"""
+
+import argparse
+import importlib
+import inspect
+import shutil
+import sys
+from pathlib import Path
+from textwrap import indent
+
+import libcst
+from libcst import matchers as m
+
+
+def _resolve_object(module, path):
+    """Resolve an object by dotted path from a module."""
+    if not path:
+        return module, None, module.__name__
+
+    parts = path.split(".")
+    parent = None
+    obj = module
+
+    for part in parts:
+        parent = obj
+        try:
+            obj = getattr(obj, part)
+        except AttributeError:
+            try:
+                obj = vars(parent).get(part)
+                if obj is not None:
+                    continue
+            except TypeError:
+                pass
+            return None, None, None
+
+    return obj, parent, getattr(obj, "__name__", parts[-1])
+
+
+def _get_docstring(name, module, indentation):
+    """Extract and format a docstring for insertion into a stub file."""
+    obj, parent, obj_name = _resolve_object(module, name)
+    if obj is None:
+        print(f"{name} not found in {module.__name__}")
+        return None
+
+    docstring = inspect.getdoc(obj)
+    if not docstring:
+        return None
+
+    # Remove signature prefix
+    parent_name = getattr(parent, "__name__", None) if parent else None
+    if docstring.startswith(obj_name) or (
+        parent_name and docstring.startswith(f"{parent_name}.{obj_name}")
+    ):
+        docstring = "\n".join(docstring.splitlines()[2:])
+
+    # Skip empty docstrings
+    if not docstring.strip():
+        return None
+
+    prefix = "    " * indentation
+    return '"""\n' + indent(docstring + '\n"""', prefix)
+
+
+class DocstringInserter(libcst.CSTTransformer):
+    """CST transformer that inserts docstrings into stub file nodes."""
+
+    def __init__(self, module, namespace):
+        self.module = module
+        self.base_namespace = namespace
+        self.stack = []
+        self.indentation = 0
+
+    def _full_name(self):
+        name = ".".join(self.stack)
+        return f"{self.base_namespace}.{name}" if self.base_namespace else name
+
+    def leave_Module(self, original_node, updated_node):
+        new_body = []
+        clone_matcher = m.SimpleStatementLine(
+            body=[m.Assign(value=m.Call(func=m.Name(value="_clone_signature"))),
+                  m.ZeroOrMore()]
+        )
+        for stmt in updated_node.body:
+            new_body.append(stmt)
+            if m.matches(stmt, clone_matcher):
+                name = stmt.body[0].targets[0].target.value
+                if self.base_namespace:
+                    name = f"{self.base_namespace}.{name}"
+                docstring = _get_docstring(name, self.module, 0)
+                if docstring:
+                    new_body.append(libcst.SimpleStatementLine(
+                        body=[libcst.Expr(value=libcst.SimpleString(docstring))]))
+        return updated_node.with_changes(body=new_body)
+
+    def visit_ClassDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_ClassDef(self, original_node, updated_node):
+        name = self._full_name()
+        docstring = _get_docstring(name, self.module, self.indentation)
+
+        if docstring:
+            ellipsis_class = m.ClassDef(body=m.IndentedBlock(body=[
+                m.SimpleStatementLine(body=[
+                    m.Expr(m.Ellipsis()), m.ZeroOrMore()]), m.ZeroOrMore()]))
+            func_class = m.ClassDef(body=m.IndentedBlock(
+                body=[m.FunctionDef(), m.ZeroOrMore()]))
+
+            if m.matches(updated_node, ellipsis_class):
+                updated_node = updated_node.deep_replace(
+                    updated_node.body.body[0].body[0].value,
+                    libcst.SimpleString(value=docstring))
+            elif m.matches(updated_node, func_class):
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=updated_node.body.with_changes(
+                        body=[docstring_stmt] + list(updated_node.body.body)))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+    def visit_FunctionDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_FunctionDef(self, original_node, updated_node):
+        name = self._full_name()
+        ellipsis_func = m.FunctionDef(
+            body=m.SimpleStatementSuite(body=[m.Expr(m.Ellipsis())]))
+
+        if m.matches(original_node, ellipsis_func):
+            docstring = _get_docstring(name, self.module, self.indentation)
+            if docstring:
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=libcst.IndentedBlock(body=[docstring_stmt]))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+
+LIB_MODULES = {"array", "builder", "compat", "config", "device", "error", "io",
+               "_ipc", "memory", "pandas_shim", "scalar", "table", "tensor", "_types"}
+
+
+def add_docstrings_to_stubs(stubs_dir):
+    """Update all stub files in stubs_dir with docstrings from pyarrow runtime."""
+    stubs_dir = Path(stubs_dir)
+    print(f"Updating stub docstrings in: {stubs_dir}")
+
+    pyarrow = importlib.import_module("pyarrow")
+
+    for stub_file in stubs_dir.rglob('*.pyi'):
+        if stub_file.name == "_stubs_typing.pyi":
+            continue
+
+        module_name = stub_file.stem
+        if module_name in LIB_MODULES:
+            namespace = "lib"
+        elif stub_file.parent.name in ("parquet", "interchange"):
+            namespace = f"{stub_file.parent.name}.{module_name}"
+        elif module_name == "__init__":
+            namespace = ""
+        else:
+            namespace = module_name
+
+        print(f"  {stub_file.name} -> {namespace or '(root)'}")
+        tree = libcst.parse_module(stub_file.read_text())
+        modified = tree.visit(DocstringInserter(pyarrow, namespace))
+        stub_file.write_text(modified.code)
+
+
+def copy_stubs(src_dir, dest_dir):
+    """Copy .pyi files from src_dir to dest_dir."""
+    src_dir, dest_dir = Path(src_dir), Path(dest_dir)
+    if not src_dir.exists():
+        return
+
+    print(f"Copying stubs: {src_dir} -> {dest_dir}")
+    for src in src_dir.rglob('*.pyi'):
+        dest = dest_dir / src.relative_to(src_dir)
+        dest.parent.mkdir(parents=True, exist_ok=True)
+        shutil.copy2(src, dest)
+
+
+def update_stubs_for_build(stubs_dir, build_lib):
+    """Entry point for setup.py: update docstrings and copy stubs to build dir."""
+    stubs_dir, build_lib = Path(stubs_dir), Path(build_lib)
+
+    sys.path.insert(0, str(build_lib))

Review Comment:
   Why all the `sys.path` hackery? Is it required for something specific? Please at least comment on this (but it would be better to avoid this).



##########
dev/update_stub_docstrings.py:
##########


Review Comment:
   This is Python-specific so we probably want to put somewhere inside the `python/` directory? Perhaps in `python/scripts`?



##########
python/setup.py:
##########
@@ -121,8 +121,28 @@ def build_extensions(self):
 
     def run(self):
         self._run_cmake()
+        self._update_stubs()
         _build_ext.run(self)
 
+    def _update_stubs(self):
+        """Update stub docstrings and copy to build directory."""
+        stubs_dir = pjoin(setup_dir, 'pyarrow-stubs')
+        if not os.path.exists(stubs_dir):
+            return
+
+        build_cmd = self.get_finalized_command('build')
+        build_lib = os.path.abspath(build_cmd.build_lib)
+
+        # Import here to avoid hard dependency on the dev script
+        sys.path.insert(0, pjoin(setup_dir, '..', 'dev'))
+        try:
+            from update_stub_docstrings import update_stubs_for_build

Review Comment:
   Hmm, is `update_stub_docstrings` supposed to be called as a script or as a Python module?



##########
python/pyproject.toml:
##########
@@ -84,15 +86,51 @@ zip-safe=false
 include-package-data=true
 
 [tool.setuptools.packages.find]
-include = ["pyarrow"]
+include = ["pyarrow", "pyarrow.*"]
 namespaces = false
 
 [tool.setuptools.package-data]
-pyarrow = ["*.pxd", "*.pyx", "includes/*.pxd"]
+pyarrow = ["*.pxd", "*.pyi", "*.pyx", "includes/*.pxd", "py.typed"]
 
 [tool.setuptools_scm]
 root = '..'
 version_file = 'pyarrow/_generated_version.py'
 version_scheme = 'guess-next-dev'
 git_describe_command = 'git describe --dirty --tags --long --match "apache-arrow-[0-9]*.*"'
 fallback_version = '24.0.0a0'
+
+# TODO: Enable type checking once stubs are merged
+[tool.mypy]
+files = ["pyarrow-stubs"]
+mypy_path = "$MYPY_CONFIG_FILE_DIR/pyarrow-stubs"
+exclude = [
+    "^pyarrow/",
+    "^benchmarks/",
+    "^examples/",
+    "^scripts/",
+]
+
+# TODO: Enable type checking once stubs are merged
+[tool.pyright]
+pythonPlatform = "All"
+pythonVersion = "3.10"

Review Comment:
   Do we actually have to set a Python version here? If so, should we set a more recent one e.g. 3.14?



##########
python/pyproject.toml:
##########
@@ -84,15 +86,51 @@ zip-safe=false
 include-package-data=true
 
 [tool.setuptools.packages.find]
-include = ["pyarrow"]
+include = ["pyarrow", "pyarrow.*"]
 namespaces = false
 
 [tool.setuptools.package-data]
-pyarrow = ["*.pxd", "*.pyx", "includes/*.pxd"]
+pyarrow = ["*.pxd", "*.pyi", "*.pyx", "includes/*.pxd", "py.typed"]
 
 [tool.setuptools_scm]
 root = '..'
 version_file = 'pyarrow/_generated_version.py'
 version_scheme = 'guess-next-dev'
 git_describe_command = 'git describe --dirty --tags --long --match "apache-arrow-[0-9]*.*"'
 fallback_version = '24.0.0a0'
+
+# TODO: Enable type checking once stubs are merged
+[tool.mypy]
+files = ["pyarrow-stubs"]
+mypy_path = "$MYPY_CONFIG_FILE_DIR/pyarrow-stubs"
+exclude = [
+    "^pyarrow/",

Review Comment:
   This exclusion means we're not checking anything currently, right?



##########
python/setup.py:
##########
@@ -121,8 +121,28 @@ def build_extensions(self):
 
     def run(self):
         self._run_cmake()
+        self._update_stubs()
         _build_ext.run(self)
 
+    def _update_stubs(self):
+        """Update stub docstrings and copy to build directory."""
+        stubs_dir = pjoin(setup_dir, 'pyarrow-stubs')
+        if not os.path.exists(stubs_dir):
+            return
+
+        build_cmd = self.get_finalized_command('build')
+        build_lib = os.path.abspath(build_cmd.build_lib)
+
+        # Import here to avoid hard dependency on the dev script

Review Comment:
   What does this mean?



##########
python/pyproject.toml:
##########
@@ -84,15 +86,51 @@ zip-safe=false
 include-package-data=true
 
 [tool.setuptools.packages.find]
-include = ["pyarrow"]
+include = ["pyarrow", "pyarrow.*"]

Review Comment:
   Ah, setuptools doesn't find packages recursively otherwise? I'm a bit surprised, I think we already have some of them such as `pyarrow.parquet`.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3750211130

   @github-actions crossbow submit wheel-manylinux-2-28-cp311-cp311-amd64


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok merged PR #48618:
URL: https://github.com/apache/arrow/pull/48618


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3748904507

   Thanks for review @raulcd ! I've responded to your points.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2690926958


##########
ci/scripts/python_wheel_macos_build.sh:
##########
@@ -175,6 +175,11 @@ export CMAKE_PREFIX_PATH=${build_dir}/install
 export SETUPTOOLS_SCM_PRETEND_VERSION=${PYARROW_VERSION}
 
 pushd ${source_dir}/python
+# We first populate stub docstrings and then build the wheel
+python setup.py build_ext --inplace
+python -m pip install griffe libcst
+python ../dev/update_stub_docstrings.py pyarrow-stubs

Review Comment:
   Same as https://github.com/apache/arrow/pull/48618#discussion_r2690922776. It's a noop and we don't have to introduce python logic in stub PRs if we do here.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2725025386


##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+
+if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then
+  if [ -n "${ARROW_PYTHON_VENV:-}" ]; then
+    . "${ARROW_PYTHON_VENV}/bin/activate"
+  fi
+
+  # Install library stubs. Note some libraries contain their own type hints so they need to be installed.
+  pip install fsspec pandas-stubs scipy-stubs types-cffi types-psutil types-requests types-python-dateutil
+
+  # Install type checkers
+  pip install mypy pyright ty
+
+  # Run type checkers
+  pushd ${pyarrow_dir}
+  mypy
+  pyright
+  ty check;

Review Comment:
   ```suggestion
     ty check
   ```



##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,42 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+
+if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then
+  if [ -n "${ARROW_PYTHON_VENV:-}" ]; then
+    . "${ARROW_PYTHON_VENV}/bin/activate"
+  fi
+
+  # Install library stubs. Note some libraries contain their own type hints so they need to be installed.
+  pip install fsspec pandas-stubs scipy-stubs types-cffi types-psutil types-requests types-python-dateutil
+
+  # Install type checkers
+  pip install mypy pyright ty
+
+  # Run type checkers
+  pushd ${pyarrow_dir}
+  mypy
+  pyright
+  ty check;
+  popd
+else
+  echo "Skipping type annotation tests";

Review Comment:
   ```suggestion
     echo "Skipping type annotation tests"
   ```



##########
ci/scripts/python_test_type_annotations.sh:
##########


Review Comment:
   Could you enable lint for this file?
   
   ```diff
   diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
   index c4c4f04188..fb46b2eda0 100644
   --- a/.pre-commit-config.yaml
   +++ b/.pre-commit-config.yaml
   @@ -337,6 +337,7 @@ repos:
              ?^ci/scripts/python_sdist_build\.sh$|
              ?^ci/scripts/python_sdist_test\.sh$|
              ?^ci/scripts/python_wheel_unix_test\.sh$|
   +          ?^ci/scripts/python_test_type_annotations\.sh$|
              ?^ci/scripts/r_build\.sh$|
              ?^ci/scripts/r_revdepcheck\.sh$|
              ?^ci/scripts/release_test\.sh$|
   @@ -379,6 +380,7 @@ repos:
            # TODO: Remove this when we fix all lint failures
            files: >-
              (
   +          ?^ci/scripts/python_test_type_annotations\.sh$|
              ?^dev/release/05-binary-upload\.sh$|
              ?^dev/release/binary-recover\.sh$|
              ?^dev/release/post-03-binary\.sh$|
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2728849569


##########
ci/scripts/python_wheel_macos_build.sh:
##########
@@ -177,6 +177,11 @@ export CMAKE_PREFIX_PATH=${build_dir}/install
 export SETUPTOOLS_SCM_PRETEND_VERSION=${PYARROW_VERSION}
 
 pushd ${source_dir}/python
+# We first populate stub docstrings and then build the wheel
+python setup.py build_ext --inplace

Review Comment:
   I tried refactoring to [single build](https://github.com/apache/arrow/pull/48618/changes/ec1c497bdcd389471ad0fb113c66bfc3878b4b39) and am testing it now. I had some help from claude :robot:.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3770094872

   @raulcd I think this is ready for another review whenever you have time.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3804628685

   @pitrou could you please take a look at proposed changes here? I suppose especially `setup.py`. This PR was split out from the bigger type annotations PR and deals only with helper scripts and CI setup.
   There is also the next PR rebased on top of this one that actually starts adding annotations https://github.com/apache/arrow/pull/48622.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "AlenkaF (via GitHub)" <gi...@apache.org>.
AlenkaF commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2642367800


##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+
+if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then
+  # Install library stubs
+  pip install pandas-stubs scipy-stubs sphinx types-cffi types-psutil types-requests types-python-dateutil

Review Comment:
   I think I understand why pandas stubs (and some others) are needed for testing. But am not sure about scipy and sphinx, for example. Could you help me understand? Thanks!
   
   (in any case, stubs are probably not "expensive" dependencies?)



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2642707406


##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+
+if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then
+  # Install library stubs
+  pip install pandas-stubs scipy-stubs sphinx types-cffi types-psutil types-requests types-python-dateutil

Review Comment:
   These are mostly stubs for libraries we're touching from our codebase. Stub should be fairly light and python only. I believe sphinx is inline annotated, but I'm not sure how urgent it is for us to check against it. I'll check and perhaps remove it here.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r3371909583


##########
python/pyarrow/py.typed:
##########


Review Comment:
   Agreed that this is not ideal  @robsdedude. Unfortunately progress on annotations was slow. I'll try to get more coverage merged by next release and look into `__getatrr__` as a temporary measure. Work continues at https://github.com/apache/arrow/pull/48622, reviews welcome :)



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "robsdedude (via GitHub)" <gi...@apache.org>.
robsdedude commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r3372050641


##########
python/pyarrow/py.typed:
##########


Review Comment:
   For reference (created this before you comment for better visibility): https://github.com/apache/arrow/issues/50123



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "robsdedude (via GitHub)" <gi...@apache.org>.
robsdedude commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r3371590167


##########
python/pyarrow/py.typed:
##########


Review Comment:
   I think adding a `py.typed` marker to the package before all public APIs are typed (even just with a whole bunch of `Any`s) wasn't ideal. Downstream users will now see a bunch of typing errors because type checkers now assume that pyarrow provides type hints that can be relied upon.
   
   In my case, I'm seeing `mypy` complain about `Module has no attribute "count"  [attr-defined]` where the module in question is `pyarrow.compute`.
   
   Please consider either removing the marker until type hints are ready or to make sure all public APIs exist (at least as `def xyz(*args: Any, **kwargs: Any) -> Any` stubs). Or apply the same `__getatrr__` placeholder to all modules, not just the top-level module.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2689914702


##########
compose.yaml:
##########
@@ -1001,14 +1003,16 @@ services:
       ARROW_S3: "OFF"
       ARROW_SUBSTRAIT: "OFF"
       ARROW_WITH_OPENTELEMETRY: "OFF"
+      PYARROW_TEST_ANNOTATIONS: "ON"

Review Comment:
   @raulcd do you think we actually want to be able to toggle these? I'm thinking we don't really need them



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3801911667

   ```
   Unable to match any tasks for `wheel-314`
   The Archery job run can be found at: https://github.com/apache/arrow/actions/runs/21375118976
   ```


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3751248906

   @github-actions crossbow submit wheel-manylinux-2-28-cp311-cp311-amd64


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3801963693

   ```
   Unable to match any tasks for `wheel`
   The Archery job run can be found at: https://github.com/apache/arrow/actions/runs/21375591417
   ```


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3801978692

   @github-actions crossbow submit wheel-*


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749607814


##########
ci/scripts/python_wheel_macos_build.sh:
##########
@@ -177,6 +177,8 @@ export CMAKE_PREFIX_PATH=${build_dir}/install
 export SETUPTOOLS_SCM_PRETEND_VERSION=${PYARROW_VERSION}
 
 pushd ${source_dir}/python
+# Install libcst for build-time stub docstring extraction
+python -m pip install libcst

Review Comment:
   Done, see if it makes sense.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749614034


##########
python/scripts/update_stub_docstrings.py:
##########
@@ -0,0 +1,233 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Extract docstrings from pyarrow runtime and insert them into stub files.
+
+Usage (from python/ directory with pyarrow built):
+    python ../dev/update_stub_docstrings.py pyarrow-stubs
+"""
+
+import argparse
+import importlib
+import inspect
+import shutil
+import sys
+from pathlib import Path
+from textwrap import indent
+
+import libcst
+from libcst import matchers as m
+
+
+def _resolve_object(module, path):
+    """Resolve an object by dotted path from a module."""
+    if not path:
+        return module, None, module.__name__
+
+    parts = path.split(".")
+    parent = None
+    obj = module
+
+    for part in parts:
+        parent = obj
+        try:
+            obj = getattr(obj, part)
+        except AttributeError:
+            try:
+                obj = vars(parent).get(part)
+                if obj is not None:
+                    continue
+            except TypeError:
+                pass
+            return None, None, None
+
+    return obj, parent, getattr(obj, "__name__", parts[-1])
+
+
+def _get_docstring(name, module, indentation):
+    """Extract and format a docstring for insertion into a stub file."""
+    obj, parent, obj_name = _resolve_object(module, name)
+    if obj is None:
+        print(f"{name} not found in {module.__name__}")
+        return None
+
+    docstring = inspect.getdoc(obj)
+    if not docstring:
+        return None
+
+    # Remove signature prefix
+    parent_name = getattr(parent, "__name__", None) if parent else None
+    if docstring.startswith(obj_name) or (
+        parent_name and docstring.startswith(f"{parent_name}.{obj_name}")
+    ):
+        docstring = "\n".join(docstring.splitlines()[2:])
+
+    # Skip empty docstrings
+    if not docstring.strip():
+        return None
+
+    prefix = "    " * indentation
+    return '"""\n' + indent(docstring + '\n"""', prefix)
+
+
+class DocstringInserter(libcst.CSTTransformer):
+    """CST transformer that inserts docstrings into stub file nodes."""
+
+    def __init__(self, module, namespace):
+        self.module = module
+        self.base_namespace = namespace
+        self.stack = []
+        self.indentation = 0
+
+    def _full_name(self):
+        name = ".".join(self.stack)
+        return f"{self.base_namespace}.{name}" if self.base_namespace else name
+
+    def leave_Module(self, original_node, updated_node):
+        new_body = []
+        clone_matcher = m.SimpleStatementLine(
+            body=[m.Assign(value=m.Call(func=m.Name(value="_clone_signature"))),
+                  m.ZeroOrMore()]
+        )
+        for stmt in updated_node.body:
+            new_body.append(stmt)
+            if m.matches(stmt, clone_matcher):
+                name = stmt.body[0].targets[0].target.value
+                if self.base_namespace:
+                    name = f"{self.base_namespace}.{name}"
+                docstring = _get_docstring(name, self.module, 0)
+                if docstring:
+                    new_body.append(libcst.SimpleStatementLine(
+                        body=[libcst.Expr(value=libcst.SimpleString(docstring))]))
+        return updated_node.with_changes(body=new_body)
+
+    def visit_ClassDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_ClassDef(self, original_node, updated_node):
+        name = self._full_name()
+        docstring = _get_docstring(name, self.module, self.indentation)
+
+        if docstring:
+            ellipsis_class = m.ClassDef(body=m.IndentedBlock(body=[
+                m.SimpleStatementLine(body=[
+                    m.Expr(m.Ellipsis()), m.ZeroOrMore()]), m.ZeroOrMore()]))
+            func_class = m.ClassDef(body=m.IndentedBlock(
+                body=[m.FunctionDef(), m.ZeroOrMore()]))
+
+            if m.matches(updated_node, ellipsis_class):
+                updated_node = updated_node.deep_replace(
+                    updated_node.body.body[0].body[0].value,
+                    libcst.SimpleString(value=docstring))
+            elif m.matches(updated_node, func_class):
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=updated_node.body.with_changes(
+                        body=[docstring_stmt] + list(updated_node.body.body)))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+    def visit_FunctionDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_FunctionDef(self, original_node, updated_node):
+        name = self._full_name()
+        ellipsis_func = m.FunctionDef(
+            body=m.SimpleStatementSuite(body=[m.Expr(m.Ellipsis())]))
+
+        if m.matches(original_node, ellipsis_func):
+            docstring = _get_docstring(name, self.module, self.indentation)
+            if docstring:
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=libcst.IndentedBlock(body=[docstring_stmt]))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+
+LIB_MODULES = {"array", "builder", "compat", "config", "device", "error", "io",
+               "_ipc", "memory", "pandas_shim", "scalar", "table", "tensor", "_types"}
+
+
+def add_docstrings_to_stubs(stubs_dir):
+    """Update all stub files in stubs_dir with docstrings from pyarrow runtime."""
+    stubs_dir = Path(stubs_dir)
+    print(f"Updating stub docstrings in: {stubs_dir}")
+
+    pyarrow = importlib.import_module("pyarrow")
+
+    for stub_file in stubs_dir.rglob('*.pyi'):
+        if stub_file.name == "_stubs_typing.pyi":
+            continue
+
+        module_name = stub_file.stem
+        if module_name in LIB_MODULES:
+            namespace = "lib"
+        elif stub_file.parent.name in ("parquet", "interchange"):
+            namespace = f"{stub_file.parent.name}.{module_name}"
+        elif module_name == "__init__":
+            namespace = ""
+        else:
+            namespace = module_name
+
+        print(f"  {stub_file.name} -> {namespace or '(root)'}")
+        tree = libcst.parse_module(stub_file.read_text())
+        modified = tree.visit(DocstringInserter(pyarrow, namespace))
+        stub_file.write_text(modified.code)
+
+
+def copy_stubs(src_dir, dest_dir):
+    """Copy .pyi files from src_dir to dest_dir."""
+    src_dir, dest_dir = Path(src_dir), Path(dest_dir)
+    if not src_dir.exists():
+        return
+
+    print(f"Copying stubs: {src_dir} -> {dest_dir}")
+    for src in src_dir.rglob('*.pyi'):
+        dest = dest_dir / src.relative_to(src_dir)
+        dest.parent.mkdir(parents=True, exist_ok=True)
+        shutil.copy2(src, dest)
+
+
+def update_stubs_for_build(stubs_dir, build_lib):
+    """Entry point for setup.py: update docstrings and copy stubs to build dir."""
+    stubs_dir, build_lib = Path(stubs_dir), Path(build_lib)
+
+    sys.path.insert(0, str(build_lib))

Review Comment:
   We require to know where stubs are so we can populate their docstrings.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749621944


##########
dev/update_stub_docstrings.py:
##########
@@ -0,0 +1,233 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Extract docstrings from pyarrow runtime and insert them into stub files.
+
+Usage (from python/ directory with pyarrow built):
+    python ../dev/update_stub_docstrings.py pyarrow-stubs
+"""
+
+import argparse
+import importlib
+import inspect
+import shutil
+import sys
+from pathlib import Path
+from textwrap import indent
+
+import libcst
+from libcst import matchers as m
+
+
+def _resolve_object(module, path):
+    """Resolve an object by dotted path from a module."""
+    if not path:
+        return module, None, module.__name__
+
+    parts = path.split(".")
+    parent = None
+    obj = module
+
+    for part in parts:
+        parent = obj
+        try:
+            obj = getattr(obj, part)
+        except AttributeError:
+            try:
+                obj = vars(parent).get(part)
+                if obj is not None:
+                    continue
+            except TypeError:
+                pass
+            return None, None, None
+
+    return obj, parent, getattr(obj, "__name__", parts[-1])
+
+
+def _get_docstring(name, module, indentation):
+    """Extract and format a docstring for insertion into a stub file."""
+    obj, parent, obj_name = _resolve_object(module, name)
+    if obj is None:
+        print(f"{name} not found in {module.__name__}")
+        return None
+
+    docstring = inspect.getdoc(obj)
+    if not docstring:
+        return None
+
+    # Remove signature prefix
+    parent_name = getattr(parent, "__name__", None) if parent else None
+    if docstring.startswith(obj_name) or (
+        parent_name and docstring.startswith(f"{parent_name}.{obj_name}")
+    ):
+        docstring = "\n".join(docstring.splitlines()[2:])
+
+    # Skip empty docstrings
+    if not docstring.strip():
+        return None
+
+    prefix = "    " * indentation
+    return '"""\n' + indent(docstring + '\n"""', prefix)
+
+
+class DocstringInserter(libcst.CSTTransformer):
+    """CST transformer that inserts docstrings into stub file nodes."""
+
+    def __init__(self, module, namespace):
+        self.module = module
+        self.base_namespace = namespace
+        self.stack = []
+        self.indentation = 0
+
+    def _full_name(self):
+        name = ".".join(self.stack)
+        return f"{self.base_namespace}.{name}" if self.base_namespace else name
+
+    def leave_Module(self, original_node, updated_node):
+        new_body = []
+        clone_matcher = m.SimpleStatementLine(
+            body=[m.Assign(value=m.Call(func=m.Name(value="_clone_signature"))),
+                  m.ZeroOrMore()]
+        )
+        for stmt in updated_node.body:
+            new_body.append(stmt)
+            if m.matches(stmt, clone_matcher):
+                name = stmt.body[0].targets[0].target.value
+                if self.base_namespace:
+                    name = f"{self.base_namespace}.{name}"
+                docstring = _get_docstring(name, self.module, 0)
+                if docstring:
+                    new_body.append(libcst.SimpleStatementLine(
+                        body=[libcst.Expr(value=libcst.SimpleString(docstring))]))
+        return updated_node.with_changes(body=new_body)
+
+    def visit_ClassDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_ClassDef(self, original_node, updated_node):
+        name = self._full_name()
+        docstring = _get_docstring(name, self.module, self.indentation)
+
+        if docstring:
+            ellipsis_class = m.ClassDef(body=m.IndentedBlock(body=[
+                m.SimpleStatementLine(body=[
+                    m.Expr(m.Ellipsis()), m.ZeroOrMore()]), m.ZeroOrMore()]))
+            func_class = m.ClassDef(body=m.IndentedBlock(
+                body=[m.FunctionDef(), m.ZeroOrMore()]))
+
+            if m.matches(updated_node, ellipsis_class):
+                updated_node = updated_node.deep_replace(
+                    updated_node.body.body[0].body[0].value,
+                    libcst.SimpleString(value=docstring))
+            elif m.matches(updated_node, func_class):
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=updated_node.body.with_changes(
+                        body=[docstring_stmt] + list(updated_node.body.body)))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+    def visit_FunctionDef(self, node):
+        self.stack.append(node.name.value)
+        self.indentation += 1
+
+    def leave_FunctionDef(self, original_node, updated_node):
+        name = self._full_name()
+        ellipsis_func = m.FunctionDef(
+            body=m.SimpleStatementSuite(body=[m.Expr(m.Ellipsis())]))
+
+        if m.matches(original_node, ellipsis_func):
+            docstring = _get_docstring(name, self.module, self.indentation)
+            if docstring:
+                docstring_stmt = libcst.SimpleStatementLine(
+                    body=[libcst.Expr(value=libcst.SimpleString(value=docstring))])
+                updated_node = updated_node.with_changes(
+                    body=libcst.IndentedBlock(body=[docstring_stmt]))
+
+        self.stack.pop()
+        self.indentation -= 1
+        return updated_node
+
+
+LIB_MODULES = {"array", "builder", "compat", "config", "device", "error", "io",
+               "_ipc", "memory", "pandas_shim", "scalar", "table", "tensor", "_types"}
+
+
+def add_docstrings_to_stubs(stubs_dir):
+    """Update all stub files in stubs_dir with docstrings from pyarrow runtime."""
+    stubs_dir = Path(stubs_dir)
+    print(f"Updating stub docstrings in: {stubs_dir}")
+
+    pyarrow = importlib.import_module("pyarrow")
+
+    for stub_file in stubs_dir.rglob('*.pyi'):
+        if stub_file.name == "_stubs_typing.pyi":
+            continue
+
+        module_name = stub_file.stem
+        if module_name in LIB_MODULES:
+            namespace = "lib"
+        elif stub_file.parent.name in ("parquet", "interchange"):
+            namespace = f"{stub_file.parent.name}.{module_name}"
+        elif module_name == "__init__":
+            namespace = ""
+        else:
+            namespace = module_name
+
+        print(f"  {stub_file.name} -> {namespace or '(root)'}")
+        tree = libcst.parse_module(stub_file.read_text())
+        modified = tree.visit(DocstringInserter(pyarrow, namespace))
+        stub_file.write_text(modified.code)
+
+
+def copy_stubs(src_dir, dest_dir):
+    """Copy .pyi files from src_dir to dest_dir."""
+    src_dir, dest_dir = Path(src_dir), Path(dest_dir)
+    if not src_dir.exists():
+        return
+
+    print(f"Copying stubs: {src_dir} -> {dest_dir}")
+    for src in src_dir.rglob('*.pyi'):
+        dest = dest_dir / src.relative_to(src_dir)
+        dest.parent.mkdir(parents=True, exist_ok=True)
+        shutil.copy2(src, dest)
+
+
+def update_stubs_for_build(stubs_dir, build_lib):
+    """Entry point for setup.py: update docstrings and copy stubs to build dir."""
+    stubs_dir, build_lib = Path(stubs_dir), Path(build_lib)
+
+    sys.path.insert(0, str(build_lib))
+    try:
+        add_docstrings_to_stubs(stubs_dir)
+        copy_stubs(stubs_dir / "pyarrow", build_lib / "pyarrow")

Review Comment:
   Moved to `setup.py`



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749618805


##########
python/setup.py:
##########
@@ -121,8 +121,28 @@ def build_extensions(self):
 
     def run(self):
         self._run_cmake()
+        self._update_stubs()
         _build_ext.run(self)
 
+    def _update_stubs(self):
+        """Update stub docstrings and copy to build directory."""
+        stubs_dir = pjoin(setup_dir, 'pyarrow-stubs')
+        if not os.path.exists(stubs_dir):
+            return
+
+        build_cmd = self.get_finalized_command('build')
+        build_lib = os.path.abspath(build_cmd.build_lib)
+
+        # Import here to avoid hard dependency on the dev script
+        sys.path.insert(0, pjoin(setup_dir, '..', 'dev'))
+        try:
+            from update_stub_docstrings import update_stubs_for_build

Review Comment:
   I was thinking module for setup.py and script for development time.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3828701274

   Thanks for the review @pitrou. I addressed your comments and rebases. Pease do another pass.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3873359653

   Thanks for reviews all! Moving on to https://github.com/apache/arrow/pull/48622.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2723040559


##########
.github/workflows/python.yml:
##########
@@ -239,6 +239,11 @@ jobs:
       - name: Test
         shell: bash
         run: ci/scripts/python_test.sh $(pwd) $(pwd)/build
+      - name: Test annotations
+        shell: bash
+        env:
+          PYARROW_TEST_ANNOTATIONS: "ON"
+        run: ci/scripts/python_test_type_annotations.sh $(pwd)/python

Review Comment:
   Oh...



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2725343303


##########
ci/scripts/python_test_type_annotations.sh:
##########


Review Comment:
   Done.
   Do any of these scripts actually build pyarrow? In that case we could actually run this check here.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2690922776


##########
ci/scripts/python_wheel_windows_build.bat:
##########
@@ -135,6 +135,10 @@ pushd C:\arrow\python
 @REM Build wheel
 %PYTHON_CMD% setup.py bdist_wheel || exit /B 1
 
+@REM We first populate stub docstrings and then build the wheel
+%PYTHON_CMD% setup.py build_ext --inplace
+%PYTHON_CMD% -m pip install griffe libcst

Review Comment:
   I added running `dev\update_stub_docstrings.py`, so I suppose it's a noop now and we can keep it to make sure it doesn't fail before introducing actual stubs? This will keep CI logic out of stub PRs.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3770094886

   Revision: 5ce90113b935e733f07bf74eb3ed366ac255cfae
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-46e8b6d779](https://github.com/ursacomputing/crossbow/branches/all?query=actions-46e8b6d779)
   
   |Task|Status|
   |----|------|
   |wheel-manylinux-2-28-cp311-cp311-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-46e8b6d779-github-wheel-manylinux-2-28-cp311-cp311-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21151190344/job/60827383688)|


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2725334374


##########
ci/scripts/python_test_type_annotations.sh:
##########


Review Comment:
   I'll give it a try! I'm afraid runtime annotations might not be seen at this point and in such case we can disable this in a later PR.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2720801461


##########
.github/workflows/python.yml:
##########
@@ -239,6 +239,11 @@ jobs:
       - name: Test
         shell: bash
         run: ci/scripts/python_test.sh $(pwd) $(pwd)/build
+      - name: Test annotations
+        shell: bash
+        env:
+          PYARROW_TEST_ANNOTATIONS: "ON"
+        run: ci/scripts/python_test_type_annotations.sh $(pwd)/python

Review Comment:
   That's a nice idea! So instead of a new workflow step you are proposing we move these checks into pre-commit script, correct? I'll change to pre-commit approach.
   
   One thing I wonder about - are there users that run all these checks locally and would not like the new extra jobs?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2721128912


##########
python/pyarrow-stubs/pyarrow/__init__.pyi:
##########
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Type stubs for PyArrow.
+
+This is a placeholder stub file.
+Complete type annotations will be added in subsequent PRs.
+"""
+
+from typing import Any
+
+def __getattr__(name: str) -> Any: ...

Review Comment:
   Oh, interesting I didn't consider this one! Yes this is meant as a temporary and we would want it out before the release. I'll make a note and issue, thanks for pointing it out!



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3801943705

   @github-actions crossbow submit wheel-314


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3799121173

   @kou thanks for the review! I think we can merge. Perhaps @raulcd wants to do a final sign-off?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2727444219


##########
ci/scripts/python_wheel_macos_build.sh:
##########
@@ -177,6 +177,11 @@ export CMAKE_PREFIX_PATH=${build_dir}/install
 export SETUPTOOLS_SCM_PRETEND_VERSION=${PYARROW_VERSION}
 
 pushd ${source_dir}/python
+# We first populate stub docstrings and then build the wheel
+python setup.py build_ext --inplace

Review Comment:
   Won't this build pyarrow twice one?
   `python setup.py build_ext --inplace`
   and one for
   `python setup.py bdist_wheel`
   
   I'll take a look at that but, if that's the case, we probably want to check whether there are alternatives to not build twice.
   
   I am running wheels at the moment to validate them.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749654653


##########
python/pyproject.toml:
##########
@@ -84,15 +86,51 @@ zip-safe=false
 include-package-data=true
 
 [tool.setuptools.packages.find]
-include = ["pyarrow"]
+include = ["pyarrow", "pyarrow.*"]

Review Comment:
   I forget why this was needed, reverting to see if tests fail or pass.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749676539


##########
ci/scripts/python_wheel_validate_contents.py:
##########
@@ -34,7 +34,7 @@ def validate_wheel(path):
     ]
     assert not outliers, f"Unexpected contents in wheel: {sorted(outliers)}"
     print(f"The wheel: {wheels[0]} seems valid.")
-
+    # TODO(GH-32609): Validate some docstrings were generated and added.

Review Comment:
   I created two issues (for this PR and one following it) and linked them into the original issue https://github.com/apache/arrow/issues/32609 



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2687800226


##########
ci/scripts/python_wheel_xlinux_build.sh:
##########
@@ -167,6 +167,11 @@ export ARROW_HOME=/tmp/arrow-dist
 export CMAKE_PREFIX_PATH=/tmp/arrow-dist
 
 pushd /arrow/python
+# We first populate stub docstrings and then build the wheel
+python setup.py build_ext --inplace
+python -m pip install griffe libcst
+python ../dev/update_stub_docstrings.py pyarrow-stubs

Review Comment:
   this will fail, right? this file isn't present on the current PR so our wheels will start failing to build if we merge as is? I'll run archery just to validate



##########
docs/source/developers/python/development.rst:
##########
@@ -42,7 +42,7 @@ Unit Testing
 ============
 
 We are using `pytest <https://docs.pytest.org/en/latest/>`_ to develop our unit
-test suite. After `building the project <build_pyarrow>`_ you can run its unit tests
+test suite. After `building the project <building.html>`_ you can run its unit tests

Review Comment:
   shouldn't `build_pyarrow` be an alias for the `buildint.rst` file?
   https://github.com/apache/arrow/blob/d54a2051cf9020a0fdf50836420c38ad14787abb/docs/source/developers/python/building.rst#L20



##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+

Review Comment:
   Can we add the virtualenv activation in case of `ARROW_PYTHON_VENV` present? This is a pattern we use on lots of our sh scripts.
   ```
   if [ -n "${ARROW_PYTHON_VENV:-}" ]; then
     . "${ARROW_PYTHON_VENV}/bin/activate"
   fi
   ```



##########
ci/scripts/python_test_type_annotations.bat:
##########
@@ -0,0 +1,38 @@
+@rem Licensed to the Apache Software Foundation (ASF) under one
+@rem or more contributor license agreements.  See the NOTICE file
+@rem distributed with this work for additional information
+@rem regarding copyright ownership.  The ASF licenses this file
+@rem to you under the Apache License, Version 2.0 (the
+@rem "License"); you may not use this file except in compliance
+@rem with the License.  You may obtain a copy of the License at
+@rem
+@rem   http://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing,
+@rem software distributed under the License is distributed on an
+@rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@rem KIND, either express or implied.  See the License for the
+@rem specific language governing permissions and limitations
+@rem under the License.
+
+@echo on
+
+set PYARROW_DIR=%1
+
+echo Annotation testing on Windows ...
+
+@REM Install library stubs
+%PYTHON_CMD% -m pip install pandas-stubs scipy-stubs sphinx types-cffi types-psutil types-requests types-python-dateutil || exit /B 1
+
+@REM Install other dependencies for type checking

Review Comment:
   Can we add a note on why `fsspec` is necessary? Is this a requirement for other dependencies?



##########
ci/scripts/python_wheel_validate_contents.py:
##########
@@ -35,6 +35,11 @@ def validate_wheel(path):
     assert not outliers, f"Unexpected contents in wheel: {sorted(outliers)}"
     print(f"The wheel: {wheels[0]} seems valid.")
 
+    candidates = [info for info in f.filelist if info.filename.endswith('compute.pyi')]

Review Comment:
   Won't this fail also? I don't think we are able to generate those, see the other comment about the missing `dev/update_stub_docstrings.py`
   ```suggestion
       # Validate at least one typing stub has been generated.
       candidates = [info for info in f.filelist if info.filename.endswith('compute.pyi')]
   ```



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3751261888

   Revision: ba07ac8806944d521918a2a4e10928cc6078b451
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-6c5a9f1e7e](https://github.com/ursacomputing/crossbow/branches/all?query=actions-6c5a9f1e7e)
   
   |Task|Status|
   |----|------|
   |wheel-manylinux-2-28-cp311-cp311-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-6c5a9f1e7e-github-wheel-manylinux-2-28-cp311-cp311-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21007224769/job/60392612446)|


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3746081436

   @github-actions crossbow submit wheel-manylinux-2-28-cp311-cp311-amd64


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotions [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3746095575

   Revision: 28fba3a025db0c6c5b9eb1543476f56642245a3f
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-8a459250fe](https://github.com/ursacomputing/crossbow/branches/all?query=actions-8a459250fe)
   
   |Task|Status|
   |----|------|
   |wheel-manylinux-2-28-cp311-cp311-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-8a459250fe-github-wheel-manylinux-2-28-cp311-cp311-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/20969788066/job/60269834650)|


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2690948119


##########
ci/scripts/python_test_type_annotations.bat:
##########
@@ -0,0 +1,38 @@
+@rem Licensed to the Apache Software Foundation (ASF) under one
+@rem or more contributor license agreements.  See the NOTICE file
+@rem distributed with this work for additional information
+@rem regarding copyright ownership.  The ASF licenses this file
+@rem to you under the Apache License, Version 2.0 (the
+@rem "License"); you may not use this file except in compliance
+@rem with the License.  You may obtain a copy of the License at
+@rem
+@rem   http://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing,
+@rem software distributed under the License is distributed on an
+@rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@rem KIND, either express or implied.  See the License for the
+@rem specific language governing permissions and limitations
+@rem under the License.
+
+@echo on
+
+set PYARROW_DIR=%1
+
+echo Annotation testing on Windows ...
+
+@REM Install library stubs
+%PYTHON_CMD% -m pip install pandas-stubs scipy-stubs sphinx types-cffi types-psutil types-requests types-python-dateutil || exit /B 1
+
+@REM Install other dependencies for type checking

Review Comment:
   Added some comments along these lines.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2690930016


##########
compose.yaml:
##########
@@ -1001,14 +1003,16 @@ services:
       ARROW_S3: "OFF"
       ARROW_SUBSTRAIT: "OFF"
       ARROW_WITH_OPENTELEMETRY: "OFF"
+      PYARROW_TEST_ANNOTATIONS: "ON"

Review Comment:
   Ok, agreed with your reasoning. I also introduced `PYARROW_TEST_ANNOTATIONS` to the windows script.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3750221636

   Revision: ee725601ae50a6a6efb55d737649aacc62d0db78
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-cd0acc6696](https://github.com/ursacomputing/crossbow/branches/all?query=actions-cd0acc6696)
   
   |Task|Status|
   |----|------|
   |wheel-manylinux-2-28-cp311-cp311-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-cd0acc6696-github-wheel-manylinux-2-28-cp311-cp311-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21000405776/job/60368521064)|


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3750363862

   Revision: 19b54bc1f4c16ccc10723ba45805a71f9f1718d8
   
   Submitted crossbow builds: [ursacomputing/crossbow @ actions-f406282276](https://github.com/ursacomputing/crossbow/branches/all?query=actions-f406282276)
   
   |Task|Status|
   |----|------|
   |wheel-manylinux-2-28-cp311-cp311-amd64|[![GitHub Actions](https://github.com/ursacomputing/crossbow/actions/workflows/crossbow.yml/badge.svg?branch=actions-f406282276-github-wheel-manylinux-2-28-cp311-cp311-amd64)](https://github.com/ursacomputing/crossbow/actions/runs/21001361990/job/60371939741)|


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3750350823

   @github-actions crossbow submit wheel-manylinux-2-28-cp311-cp311-amd64


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2729059884


##########
ci/scripts/python_wheel_macos_build.sh:
##########
@@ -177,6 +177,11 @@ export CMAKE_PREFIX_PATH=${build_dir}/install
 export SETUPTOOLS_SCM_PRETEND_VERSION=${PYARROW_VERSION}
 
 pushd ${source_dir}/python
+# We first populate stub docstrings and then build the wheel
+python setup.py build_ext --inplace

Review Comment:
   https://github.com/apache/arrow/actions/runs/21370491404/job/61513502965?pr=48618#step:6:8605 here's an example check.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3801959897

   @github-actions crossbow submit wheel


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2719408779


##########
.github/workflows/python.yml:
##########
@@ -239,6 +239,11 @@ jobs:
       - name: Test
         shell: bash
         run: ci/scripts/python_test.sh $(pwd) $(pwd)/build
+      - name: Test annotations
+        shell: bash
+        env:
+          PYARROW_TEST_ANNOTATIONS: "ON"
+        run: ci/scripts/python_test_type_annotations.sh $(pwd)/python

Review Comment:
   I don't object this approach but it may be better that we use pre-commit for type checking. (I think that type checking is one of lint checks.)



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3784507511

   @kou could you take a quick look at this?


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3811001019

   Ping @pitrou 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on PR #48618:
URL: https://github.com/apache/arrow/pull/48618#issuecomment-3770090090

   @github-actions crossbow submit wheel-manylinux-2-28-cp311-cp311-amd64


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749626968


##########
python/pyproject.toml:
##########
@@ -84,15 +86,51 @@ zip-safe=false
 include-package-data=true
 
 [tool.setuptools.packages.find]
-include = ["pyarrow"]
+include = ["pyarrow", "pyarrow.*"]
 namespaces = false
 
 [tool.setuptools.package-data]
-pyarrow = ["*.pxd", "*.pyx", "includes/*.pxd"]
+pyarrow = ["*.pxd", "*.pyi", "*.pyx", "includes/*.pxd", "py.typed"]
 
 [tool.setuptools_scm]
 root = '..'
 version_file = 'pyarrow/_generated_version.py'
 version_scheme = 'guess-next-dev'
 git_describe_command = 'git describe --dirty --tags --long --match "apache-arrow-[0-9]*.*"'
 fallback_version = '24.0.0a0'
+
+# TODO: Enable type checking once stubs are merged
+[tool.mypy]
+files = ["pyarrow-stubs"]
+mypy_path = "$MYPY_CONFIG_FILE_DIR/pyarrow-stubs"
+exclude = [
+    "^pyarrow/",
+    "^benchmarks/",
+    "^examples/",
+    "^scripts/",
+]
+
+# TODO: Enable type checking once stubs are merged
+[tool.pyright]
+pythonPlatform = "All"
+pythonVersion = "3.10"

Review Comment:
   Maybe we best keep it in then?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-32609: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2749616811


##########
python/pyproject.toml:
##########
@@ -84,15 +86,51 @@ zip-safe=false
 include-package-data=true
 
 [tool.setuptools.packages.find]
-include = ["pyarrow"]
+include = ["pyarrow", "pyarrow.*"]
 namespaces = false
 
 [tool.setuptools.package-data]
-pyarrow = ["*.pxd", "*.pyx", "includes/*.pxd"]
+pyarrow = ["*.pxd", "*.pyi", "*.pyx", "includes/*.pxd", "py.typed"]
 
 [tool.setuptools_scm]
 root = '..'
 version_file = 'pyarrow/_generated_version.py'
 version_scheme = 'guess-next-dev'
 git_describe_command = 'git describe --dirty --tags --long --match "apache-arrow-[0-9]*.*"'
 fallback_version = '24.0.0a0'
+
+# TODO: Enable type checking once stubs are merged
+[tool.mypy]
+files = ["pyarrow-stubs"]
+mypy_path = "$MYPY_CONFIG_FILE_DIR/pyarrow-stubs"
+exclude = [
+    "^pyarrow/",

Review Comment:
   Yes, if we don't we get type check failurea (IIRC).



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations [arrow]

Posted by "rok (via GitHub)" <gi...@apache.org>.
rok commented on code in PR #48618:
URL: https://github.com/apache/arrow/pull/48618#discussion_r2750215273


##########
ci/scripts/python_test_type_annotations.sh:
##########
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+set -ex
+pyarrow_dir=${1}
+
+if [ "${PYARROW_TEST_ANNOTATIONS}" == "ON" ]; then

Review Comment:
   Actually let's get @raulcd's opinion in light of our previous discussion: https://github.com/apache/arrow/pull/48618#discussion_r2690100864 



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org