Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[train] update config dataclass repr to check against None #40851

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion python/ray/air/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,20 @@ def _repr_dataclass(obj, *, default_values: Optional[Dict[str, Any]] = None) ->

non_default_values = {} # Maps field name to value.

def equals(value, default_value):
# We need to special case None because of a bug in pyarrow:
# https://github.com/apache/arrow/issues/38535
if value is None and default_value is None:
return True
if value is None or default_value is None:
return False
return value == default_value

for field in fields(obj):
value = getattr(obj, field.name)
default_value = default_values.get(field.name, field.default)
is_required = isinstance(field.default, _MISSING_TYPE)
if is_required or value != default_value:
if is_required or not equals(value, default_value):
non_default_values[field.name] = value

string = f"{obj.__class__.__name__}("
Expand Down
8 changes: 8 additions & 0 deletions python/ray/air/tests/test_configs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

import pyarrow.fs

from ray.train import (
ScalingConfig,
FailureConfig,
Expand Down Expand Up @@ -30,6 +32,12 @@ def test_repr(config):
assert len(representation) < MAX_REPR_LENGTH


def test_storage_filesystem_repr():
config = RunConfig(storage_filesystem=pyarrow.fs.S3FileSystem())
representation = repr(config)
assert len(representation) < MAX_REPR_LENGTH


def test_failure_config_init():
FailureConfig(fail_fast=True)
FailureConfig(fail_fast=False)
Expand Down
Loading