Skip to content

[core][data] Fix code bugs found during the docstring backfill - #67602

Open
dstrodtman wants to merge 7 commits into
masterfrom
doc-1899-annotation-bug-fixes
Open

dstrodtman wants to merge 7 commits into
masterfrom
doc-1899-annotation-bug-fixes

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Why are these changes needed?

Docstring cleanup PRs carry the docstring-only label, which lets them skip the heavy library test suites. A guard enforces that label, so those PRs can't fix a code bug they uncover, even a one-line type annotation. This PR collects those code fixes so they get normal CI and a code review. It stays in draft and gains a commit for each bug found as the docstring work continues.

Fixes so far:

  • python/ray/dashboard/modules/job/job_log_storage_client.py: JobLogStorageClient.get_log_file_path is annotated -> Tuple[str, str], but it returns the single path that os.path.join builds. The annotation is now -> str, and the unused Tuple import is gone. Found while fixing its docstring in [core] Hand-fix the ten D212 docstrings the auto-fix would mis-render #67601.
  • python/ray/_private/state.py: GlobalState.get_actor_info is annotated -> Optional[str], but GlobalStateAccessor.get_actor_info returns the serialized ActorTableData as bytes, and the caller in actor_table parses it with ActorTableData.FromString. The annotation is now -> Optional[bytes]. @pseudo-rnd-thoughts found this in [Docs][Core] Specify if the node id needs to be a hex or byte value  #67592, which leaves it out to stay docstring-only.
  • python/ray/data/preprocessors/torch.py: TorchVisionPreprocessor.preferred_batch_format overrides a @classmethod on Preprocessor but drops the decorator, unlike the other preprocessor overrides. Calling it on the class, as in TorchVisionPreprocessor.preferred_batch_format(), raises TypeError for the missing cls argument. Ray calls it only through an instance today, which works either way. The method is now a @classmethod. Found while adding its docstring for the Ray Data docstring backfill.
  • python/ray/data/_internal/object_extensions/arrow.py: ArrowPythonObjectArray.from_objects takes no self but has no @staticmethod, so it works only when called on the class, which is how every caller uses it today. It's now a @staticmethod.
  • python/ray/data/_internal/object_extensions/arrow.py and python/ray/data/_internal/tensor_extensions/arrow.py: ArrowPythonObjectScalar.as_py and ArrowTensorScalar.as_py take an untyped **kwargs as their only argument, and pydoclint rejects any docstring with an Args: or Returns: section on that signature. **kwargs is now annotated Any.
  • python/ray/data/_internal/tensor_extensions/pandas.py: TensorArray.isna is annotated -> "TensorArray", but every branch returns a boolean NumPy array. The annotation is now -> np.ndarray.

The from_objects and as_py fixes unblock their docstrings, so this PR also adds those three docstrings, plus the ArrowTensorScalar class docstring, which sits directly above the as_py signature. The docstring-only Ray Data backfill in #67605, which merged, left all four out.

Testing

  • The pre-commit suite on the changed files, including ruff, black, and pydoclint: passed.
  • The annotation fixes have no runtime effect.
  • The @classmethod and @staticmethod fixes change only calls that raised before: a class-level call to preferred_batch_format and an instance-level call to from_objects. Existing calls return the same values. A standalone Python check confirmed the @classmethod behavior. I didn't run the Ray Data tests locally, so premerge covers them.
  • pydoclint passes on the three new docstrings with no baseline changes.

AI assistance (Claude Code) was used to prepare this PR.

🤖 Generated with Claude Code

JobLogStorageClient.get_log_file_path returns a single path from
os.path.join, not a tuple. GlobalState.get_actor_info returns the
serialized ActorTableData bytes from the GCS accessor, which its caller
parses with ActorTableData.FromString, not a str.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman dstrodtman added the core Issues that should be addressed in Ray Core label Oct 30, 2026
The override drops the @classmethod that Preprocessor.preferred_batch_format
and the other preprocessor overrides carry, so calling it on the class
raises TypeError for the missing cls argument. Calls through an instance,
the only path Ray uses today, are unaffected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
…extensions

ArrowPythonObjectArray.from_objects takes no self but lacks @staticmethod,
so it works only when called on the class. Add the decorator.

ArrowPythonObjectScalar.as_py and ArrowTensorScalar.as_py take an untyped
**kwargs as their only argument, which pydoclint rejects in any docstring
that has an Args or Returns section. Annotate it as Any.

TensorArray.isna is annotated to return a TensorArray, but it returns a
boolean NumPy array. Annotate it as np.ndarray.

Add the docstrings these fixes unblock, which the docstring-only Ray Data
backfill leaves out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman dstrodtman added the data Ray Data-related issues label Oct 30, 2026
@dstrodtman dstrodtman changed the title [core] Fix type annotations that contradict the code [core][data] Fix code bugs found during the docstring backfill Oct 30, 2026
It sits directly above the as_py signature this PR fixes, so it lands here
rather than in the docstring-only Ray Data backfill, which would otherwise
conflict with this PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
dstrodtman added a commit that referenced this pull request Oct 30, 2026
…cessors (#67603)

## Summary

Adds the missing docstrings on the public
`ray.data.preprocessor.Preprocessor` and `ray.data.preprocessors`
surface: 88 symbols in 13 files. Most are the configuration properties
on each built-in preprocessor, such as `columns`, `output_columns`, and
`bins`. Each property docstring restates the constructor's existing
`Args:` entry. The `get_input_columns` and `get_output_columns`
overrides, `Preprocessor.fit_status`, `Chain.fit_status`,
`Preprocessor.has_stats`, and `OneHotEncoder.safe_get` now get
docstrings with `Returns:` sections, written from what the code returns.

## Before

These properties and methods had no docstring, so the API reference
showed only their names and signatures.

## After

They have docstrings. Overrides that now carry their own docstring, such
as `LabelEncoder.get_input_columns`, appear in their class's method
table, because the `class.rst` autosummary template lists only methods
whose own `__doc__` is set.

Behavior is unchanged. The diff touches only docstrings, which the guard
below confirms.

## Subsystems

API (preprocessors). Docstrings only.

## For reviewers

The descriptions of what a method returns, such as `fit_status`,
`has_stats`, `safe_get`, and the base `get_input_columns` and
`get_output_columns`, are the parts worth a technical read. The property
docstrings paraphrase each class's `Args:` section.

While writing these, I found that
`TorchVisionPreprocessor.preferred_batch_format` is missing the
`@classmethod` that the base method and the other overrides carry.
That's a code change, so it's in #67602 instead of here, and the two PRs
touch adjacent lines.

## Duplicate check

No open PR documents these symbols. I searched open PRs for
`preprocessor docstring` and `preprocessors`. #60533 changes
`OneHotEncoder` and `MultiHotEncoder` code in `encoder.py` but doesn't
touch these docstrings.

## Testing

- `python ci/ray_ci/doc/check_docstring_only.py --base "$(git merge-base
upstream/master HEAD)"`: `docstring-only guard: 13 file(s), docstrings
only.`
- The full pre-commit suite on the changed files, including ruff, black,
pydoclint, and the docstyle hook: passed.
- The commit carries an `@rtd-build` line, so the Read the Docs preview
renders the new docstrings.

AI assistance (Claude Code) was used to prepare this PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
dstrodtman added a commit that referenced this pull request Oct 30, 2026
…API (#67605)

## Summary

Adds the missing docstrings, `Args:` entries, and `Returns:` sections on
public Ray Data symbols in `aggregate`, `dataset`, `iterator`,
`catalog`, `datasource`, `datatype`, and the public classes under
`_internal`: the Databricks and LeRobot datasources and the object and
tensor extensions. Each describes existing behavior, written from the
code. It follows #67603, which covers the preprocessors.

## Before

These symbols had no docstring, or their docstring had no section for
some parameters or for the return value. `ApproximateQuantile` and
`ApproximateTopK` kept their whole docstring on `__init__`, and the
class reference page doesn't render that, so [their
pages](https://docs.ray.io/en/master/data/api/doc/ray.data.aggregate.ApproximateQuantile.html)
show no description.

## After

The symbols are documented. The `ApproximateQuantile` and
`ApproximateTopK` docstrings move, unchanged, from `__init__` to the
class, so their pages show the description, examples, and arguments, and
`__init__` drops out of their method tables.

Where a base class lacked the docstring an override would inherit, this
PR documents the base instead of each override: `Datasource.get_name`,
`Datasource.estimate_inmemory_data_size`, `AggregateFn.output_field`,
and `Catalog.resolve`.

Behavior is unchanged. The diff touches only docstrings, which the guard
below confirms.

## Subsystems

API, IO, shuffle and aggregation, block and data format. Docstrings
only.

## For reviewers

These docstrings state behavior that looks unintended, so they're the
ones worth a close read:

- `PythonObjectArray.to_numpy` ignores `dtype`.
- `ArrowPythonObjectArray.to_numpy` ignores `zero_copy_only` and
`writable`.
- `Dataset.__init__` now documents its arguments and keeps the note that
the constructor isn't part of the public API.

Three methods can't be documented without a signature change, so their
code fixes and docstrings are in #67602:
`ArrowPythonObjectScalar.as_py`, `ArrowTensorScalar.as_py`, and
`ArrowPythonObjectArray.from_objects`. The `ArrowTensorScalar` class
docstring sits directly above one of those signatures, so it's in #67602
too. #67602 also corrects the return annotation of `TensorArray.isna`,
which this PR documents as returning a boolean NumPy array.

## Duplicate check

No open PR documents these symbols. Open PRs #67600, #66927, #67238, and
#67237 change other parts of `dataset.py`, and none of them edit the
docstrings changed here.

## Testing

- `python ci/ray_ci/doc/check_docstring_only.py --base "$(git merge-base
upstream/master HEAD)"`: `docstring-only guard: 15 file(s), docstrings
only.`
- The full pre-commit suite on the changed files, including ruff, black,
pydoclint, and the docstyle hook: passed.
- The commit carries an `@rtd-build` line, so the Read the Docs preview
renders the changed docstrings.

AI assistance (Claude Code) was used to prepare this PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@dstrodtman dstrodtman added the skip-gpu-tests Skips GPU tests for PRs that trigger them due to overly broad rules. label Nov 3, 2026
@dstrodtman
dstrodtman marked this pull request as ready for review November 3, 2026 18:51
@dstrodtman
dstrodtman requested review from a team as code owners November 3, 2026 18:51
@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Nov 3, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors type annotations, adds docstrings, and applies missing decorators across several modules, including updating get_actor_info to return bytes and get_log_file_path to return a string. The review feedback correctly suggests updating the return type of ArrowTensorScalar.as_py to Optional[np.ndarray] and updating its docstring to reflect that it can return None when the scalar is null.

Comment on lines +817 to +825
def as_py(self, **kwargs: Any) -> np.ndarray:
"""Convert this scalar to a NumPy array.

Args:
**kwargs: Unused.

Returns:
The tensor as a NumPy array.
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since self.__array__() can return None when the scalar is null (as handled in fixed_shape_extension_scalar_to_ndarray), the return type annotation should be Optional[np.ndarray] instead of np.ndarray. Additionally, the docstring's Returns section should be updated to document this behavior.

Suggested change
def as_py(self, **kwargs: Any) -> np.ndarray:
"""Convert this scalar to a NumPy array.
Args:
**kwargs: Unused.
Returns:
The tensor as a NumPy array.
"""
def as_py(self, **kwargs: Any) -> Optional[np.ndarray]:
"""Convert this scalar to a NumPy array.
Args:
**kwargs: Unused.
Returns:
The tensor as a NumPy array, or ``None`` if the scalar is null.
"""

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
dstrodtman added a commit that referenced this pull request Nov 4, 2026
…#67601)

## Why are these changes needed?

This follows #67540, which merged on 2026-11-02 and applied ruff's
`D212` and `D200` auto-fixes to `python/ray/` outside the library trees.
That PR left ten `D212` violations in place because the auto-fix would
change what they render as. Each has a first line indented less than the
lines below it, and `inspect.cleandoc` ignores the first line when it
computes the common indent, so joining that line to the opening quotes
dedents the rest. This PR fixes them by hand so a later config PR can
turn on `D212`.

Each docstring now has a summary on the opening quotes, with the
material below it re-indented as a block or section. Every summary comes
from the existing text or from the code:

- `metrics_reporter.py` `report_instances` and `report_resources`,
`scheduler.py` `_sort_gang_resource_requests`,
`job_log_storage_client.py` `get_log_file_path`, and the
`util/dask/scheduler_utils.py` module docstring get a summary line. The
existing content stays below it.
- `dag/dag_node.py` `DAGNode.__init__` gets a summary and a capitalized
`Args:` section. The entries drop the types already in the signature,
and the `ex:` lines become "For example, ``...``".

Three docstrings changed beyond layout, because the existing text didn't
match the code. These need a close read:

- `instance_manager/config.py` `get_docker_config`: the old text listed
a "node specific docker image" as the first choice for head nodes. In
`ray-schema.json`, a node type's `docker` block allows only
`worker_image`, `pull_before_run`, and `worker_run_options`, so the
head-node order is `head_image`, then `image`. The worker-node order now
names the node type's `docker.worker_image` explicitly.
- `instance_manager/config.py` `FileConfigReader` and
`KubeRayConfigReader` `get_cached_autoscaling_config`: these overrides
had only a `Returns:` block and no summary. They now have no docstring
and inherit the abstract `IConfigReader.get_cached_autoscaling_config`
docstring.
- `aws/utils.py` `LazyDefaultDict.__missing__`: the pseudo-code was
copied from `collections.defaultdict` and described a factory that takes
no argument and a `KeyError` for a `None` factory. This override calls
`default_factory(key)`, so the docstring now says that.

One thing outside this PR's scope:
`JobLogStorageClient.get_log_file_path` is annotated `-> Tuple[str,
str]`, but it returns a single `str`. Fixing the annotation is a code
change, so it's in #67602 instead.

## Testing

- `uvx [email protected] check --select D212 --config
'lint.pydocstyle.convention="google"'` on the seven changed files: all
checks passed.
- `python ci/ray_ci/doc/check_docstring_only.py --base
doc-1903-core-docstring-autofix`: `docstring-only guard: 7 file(s),
docstrings only.`
- The full pre-commit suite on the changed files, including ruff, black,
pydoclint, and the docstyle hook: passed.

AI assistance (Claude Code) was used to prepare this PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
…on-bug-fixes

Signed-off-by: Douglas Strodtman <[email protected]>

# Conflicts:
#	python/ray/_private/state.py
#	python/ray/dashboard/modules/job/job_log_storage_client.py

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues that should be addressed in Ray Core data Ray Data-related issues go add ONLY when ready to merge, run all tests skip-gpu-tests Skips GPU tests for PRs that trigger them due to overly broad rules.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant