Skip to content

fix(core): write use_polars_sort to Ray DatasetContext#355

Merged
danielgafni merged 7 commits into
danielgafni:masterfrom
geoHeil:fix/ray-data-use-polars-sort
Apr 21, 2026
Merged

fix(core): write use_polars_sort to Ray DatasetContext#355
danielgafni merged 7 commits into
danielgafni:masterfrom
geoHeil:fix/ray-data-use-polars-sort

Conversation

@geoHeil

@geoHeil geoHeil commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #354

Changelog

RayDataExecutionOptions.use_polars has been deprecated in favor of RayDataExecutionOptions.use_polars_sort

geoHeil and others added 2 commits April 20, 2026 17:34
…afni#354)

Ray 2.55 deprecated `DatasetContext.use_polars` in favor of
`use_polars_sort`. Writing the old attribute on every
`RayDataExecutionOptions.apply()` / `apply_remote()` emitted a
DeprecationWarning on every materialization.

Add `use_polars_sort` as the canonical field and keep `use_polars`
as a deprecated alias that forwards its value and warns once at
construction, preserving the existing API. `apply()` now writes
`ctx.use_polars_sort` only.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Ray <2.50 does not expose `DatasetContext.use_polars_sort`, so writing
it would silently create an unread attribute and drop the user's setting.
Probe for the new attribute and fall back to `use_polars` on older Ray.
Since `pyproject.toml` pins `ray>=2.7.0`, we need to support both.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread src/dagster_ray/configs.py Outdated
Comment on lines +96 to +101
warnings.warn(
"`use_polars` is deprecated; use `use_polars_sort` instead. "
"The value has been forwarded to `use_polars_sort`.",
DeprecationWarning,
stacklevel=2,
)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Use deprecated on the old field instead


Edit: just noticed you already did it, why duplicate the warning in this case?

Comment thread src/dagster_ray/configs.py Outdated
Comment on lines +120 to +125
# Ray >=2.50 renamed `use_polars` to `use_polars_sort`; set the new name when
# available to avoid Ray's own DeprecationWarning, and fall back on older Ray.
if hasattr(ctx, "use_polars_sort"):
ctx.use_polars_sort = self.use_polars_sort
else:
ctx.use_polars = self.use_polars_sort

@danielgafni danielgafni Apr 20, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this has to be an explicit Ray version check, that's cleaner to read

It also has to check the legacy self.use_polars variant

@danielgafni

Copy link
Copy Markdown
Owner

also, let's add a validator to ensure that the two attributes are not set to contradicting values (True/False and False/True)

…ng values

Use packaging.Version to decide between `use_polars` and `use_polars_sort`
on Ray's DatasetContext, and raise when callers set the deprecated and new
fields to different values instead of silently forwarding.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread src/dagster_ray/configs.py Outdated
Comment on lines +122 to +123
# `use_polars_sort`; read the effective value (the legacy field wins when
# both are set only because the validator has already unified them).

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

can you explain this comment? I am seeing the opposite in the validator: use_polars can easily be unset

in general the new parameter should be preferred - even tho we did explicitly forbid conflicts

@geoHeil geoHeil Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — the comment was wrong. Fixed in 5dc380d: dropped the confusing comment

Comment thread docs/changelog.md Outdated
Comment on lines +9 to +18
## Unreleased

### :bug: Bug Fixes

- avoid Ray 2.55 `DatasetContext.use_polars` DeprecationWarning on every `RayDataExecutionOptions.apply()` by writing to `use_polars_sort` ([#354](https://github.com/danielgafni/dagster-ray/issues/354))

### :hammer_and_wrench: Other Improvements

- add `RayDataExecutionOptions.use_polars_sort`; keep `use_polars` as a deprecated alias that forwards its value and emits a `DeprecationWarning`

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

do not edit the changelog, it's auto-generated by git-cliff from conventional commits history.

You can add a ## Changelog section to the PR description for a more verbose changeling entry.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted in 5dc380d — the ## Unreleased block is removed. I'll add a ## Changelog section to the PR description instead.

Comment thread src/dagster_ray/configs.py Outdated
)
use_polars: bool | None = Field(
default=None,
description="Deprecated. Use `use_polars_sort` instead. Ray 2.55 renamed the underlying `DatasetContext` attribute to `use_polars_sort`.",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

No need to change the description, we have the deprecated parameter for the deprecation message

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 5dc380d — removed the custom description; relying on the deprecated parameter alone.

Comment thread src/dagster_ray/configs.py Outdated
use_polars: bool | None = Field(
default=None,
description="Deprecated. Use `use_polars_sort` instead. Ray 2.55 renamed the underlying `DatasetContext` attribute to `use_polars_sort`.",
deprecated="`use_polars` is deprecated; use `use_polars_sort` instead.",

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

please add "is deprecated and will be removed in dagster-ray 0.5.0"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in 5dc380d: ``use_polarsis deprecated and will be removed in dagster-ray 0.5.0; useuse_polars_sort` instead.`

geoHeil and others added 2 commits April 21, 2026 05:30
- revert changelog edit (auto-generated by git-cliff from commit history)
- drop duplicate `description` on deprecated `use_polars` field; pydantic `deprecated=` message is the single source of truth
- expand deprecation message to state removal in dagster-ray 0.5.0
- simplify `apply()` to read `self.use_polars_sort` directly — the validator already unifies the legacy field into it

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@danielgafni danielgafni left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It's mostly ok now but I believe there will be a bug if use_polars is set to False: param merging logic doesn't correctly handle this case because it always also checks whether use_polars_sort is set to None (which can't happen due to it being non-optional bool).

It's really surprising how this wasn't caught by one of these May tests added...

Please fix param merging logic and it should be good to go.

Comment thread src/dagster_ray/configs.py Outdated
f"({legacy!r} vs {new!r}). `use_polars` is deprecated; set only "
"`use_polars_sort`."
)
if legacy is not None and new is None:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This line is dead code because new can never be None

@geoHeil geoHeil Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Refactored in a735002 to use explicit "use_polars" in data / "use_polars_sort" in data key-presence checks, which removes the ambiguity you called out.

Replace ambiguous `data.get(...) is None` checks with explicit `"key" in data`
checks. In `mode="before"` the validator receives the raw input dict, so `None`
was overloaded to mean both "key missing" and "value is None"; key-presence is
unambiguous and easier to verify at a glance.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@geoHeil

geoHeil commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

Pushed a735002 reworking the validator to use key-presence checks instead of is None checks, per #355 (review).

The retry in RayClusterClient.wait_until_ready only caught
urllib3.exceptions.ProtocolError, so transient apiserver
unavailability that surfaced as MaxRetryError (wrapping
NewConnectionError with "Connection refused") aborted the wait
instead of retrying.

Seen in CI when minikube briefly drops its apiserver mid-test:

    Failed to wait for RayCluster ray/dg-dev-... readiness
    ...
    urllib3.exceptions.NewConnectionError: Failed to establish a
    new connection: [Errno 111] Connection refused

Catch both ProtocolError and MaxRetryError so the existing
30 x 2s retry budget covers apiserver blips as well as mid-
response network drops.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@geoHeil
geoHeil marked this pull request as ready for review April 21, 2026 06:37
@geoHeil

geoHeil commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

@danielgafni can you re-run the timeout/failing minicube test?

@danielgafni
danielgafni merged commit bf8b895 into danielgafni:master Apr 21, 2026
31 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants