Generate pylibcudf stubs with stubgen-pyx - #23628
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
f7f07d5 to
29f2241
Compare
29f2241 to
e748f52
Compare
|
Can you temporarily elide the insertion of docstrings into the stubs. That will make the diffs of the types, which is the important thing, much easier to read. |
| from rmm.pylibrmm.memory_resource import DeviceMemoryResource | ||
|
|
||
| __all__ = ["AvroReaderOptions", "AvroReaderOptionsBuilder", "read_avro"] | ||
| __all__ = ['read_avro', 'AvroReaderOptions', 'AvroReaderOptionsBuilder'] |
There was a problem hiding this comment.
The script should run ruff check/fmt on the pyis.
There was a problem hiding this comment.
Good idea, I'll add that.
| def build(self) -> AvroReaderOptions: | ||
| """Create a AvroReaderOptions object""" | ||
|
|
||
| def read_avro(options: AvroReaderOptions, stream: CudaStreamLike | None=None, mr: DeviceMemoryResource | None=None) -> TableWithMetadata: |
There was a problem hiding this comment.
nit: Usually type stubs don't advertise the default, but rather just show that there is a default by saying mr : SomeType | None = ....
There was a problem hiding this comment.
Good point, I'll see if we can modify the generator to do that. Opened jon-edward/stubgen-pyx#62
| TableWithMetadata, | ||
| ) | ||
| from pylibcudf.io.types import SinkInfo, SourceInfo, TableWithMetadata | ||
| from pylibcudf.libcudf.io.types import compression_type, quote_style |
There was a problem hiding this comment.
Need to do renaming of these into CamelCase
There was a problem hiding this comment.
Yeah, I haven't yet figured out how best to do that. I made this work locally by supporting an import remapping option for specific type names, which is a bit manual but might be our best option. I don't know how we can get this to work automagically without some input.
| stream: CudaStreamLike | None = None, | ||
| mr: DeviceMemoryResource | None = None, | ||
| ) -> Scalar: ... | ||
| def from_arrow(obj: ArrowLike, dtype: DataType | None=None, stream: CudaStreamLike | None=None, mr: DeviceMemoryResource | None=None) -> ArrowLike: |
| def _infer_list_depth_and_dtype(obj: list) -> tuple[int, type]: | ||
| """Infer the nesting depth and final scalar type.""" | ||
| def _flatten_nested_list(obj: list, depth: int) -> tuple[list, tuple[int, ...]]: | ||
| """Flatten a nested list and compute the shape""" | ||
| def _infer_shape(obj: list, depth: int) -> tuple[int, ...]: ... | ||
| def _flatten(obj: list, out: list, offset: int) -> int: ... | ||
| def _prepare_array_metadata(iface: dict) -> tuple[int, int, tuple[int, ...], tuple[int, ...] | None, DataType]: |
There was a problem hiding this comment.
Let's just cull all underscore names from the type stubs.
There was a problem hiding this comment.
| from pylibcudf.libcudf.types import interpolation as Interpolation | ||
| from pylibcudf.libcudf.types import mask_state as MaskState | ||
| from pylibcudf.libcudf.types import nan_equality as NanEquality | ||
| from pylibcudf.libcudf.types import nan_policy as NanPolicy | ||
| from pylibcudf.libcudf.types import null_aware as NullAware | ||
| from pylibcudf.libcudf.types import null_equality as NullEquality | ||
| from pylibcudf.libcudf.types import null_order as NullOrder | ||
| from pylibcudf.libcudf.types import null_policy as NullPolicy | ||
| from pylibcudf.libcudf.types import order as Order | ||
| from pylibcudf.libcudf.types import output_nullability as OutputNullability | ||
| from pylibcudf.libcudf.types import size_type | ||
| from pylibcudf.libcudf.types import sorted as Sorted | ||
| from pylibcudf.libcudf.types import type_id | ||
| from pylibcudf.libcudf.types import type_id as TypeId | ||
| from pylibcudf.libcudf.utilities.type_dispatcher import type_to_id |
There was a problem hiding this comment.
None of this will work since these modules don't exist.
There was a problem hiding this comment.
Same fundamental issue as #23628 (comment).
Probably not just temporarily, we should change stubgen-pyx to support eliding docstrings since there's no real reason to keep docstrings in the stubs if they're in the source. Opened jon-edward/stubgen-pyx#64 |
Summary
.pyifiles withstubgen-pyx==0.2.18Motivation
We have been improving
stubgen-pyxupstream, and this draft gives cudf developers a concrete diff for evaluating whether generated pylibcudf stubs are close enough to replace the handwritten files.Notes for reviewers
This is intentionally a draft/evaluation PR. The generated stubs are much more complete and source-derived than the handwritten versions, but there are still visible gaps worth reviewing:
CudaStreamLikeis lost in generated signatures, generally becomingobject | NoneValidation
python/pylibcudf/pylibcudf/**/*.pyifiles and regenerated them withpre-commit run stubgen-pyx-pylibcudf --all-filespre-commit run stubgen-pyx-pylibcudf --all-filesafter rebasing on latestupstream/main; it passed with no further changespre-commit run ruff --files ci/checks/generate_pylibcudf_stubs.py .pre-commit-config.yamlpre-commit run ruff-format --files ci/checks/generate_pylibcudf_stubs.py .pre-commit-config.yamlpre-commit run yamllint --files .pre-commit-config.yamlpre-commit run verify-copyright --files ...git diff --checkFull commit-time
mypywas also run while preparing this branch and currently fails on the generated stubs; that failure is part of the review signal for this draft.