-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
[AIR] Add __repr__
to AIR classes
#27006
Merged
richardliaw
merged 35 commits into
ray-project:master
from
bveeramani:bveeramani/air-repr2
Jul 27, 2022
Merged
Changes from 25 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
b51aa74
Add `__repr__` for checkpoints
bveeramani ca2e9a7
Add config `__repr__`s
bveeramani 50b1b04
Add preprocessor `__repr__`s
bveeramani bb36088
Add trainer `__repr__`
bveeramani 40468f6
Update `Preprocessor`s
bveeramani ad08a51
Fix stuff
bveeramani 448a67c
Add predictor `__repr__`s
bveeramani 829cf73
Appease lint
bveeramani 6e881c3
Update tensorflow_predictor.py
bveeramani 7c90cf2
Merge branch 'master' into bveeramani/air-repr2
bveeramani 32737da
Fix docstring example
bveeramani a7abc5a
Update preprocessor reprs
bveeramani 1632231
More preprocessor fix
bveeramani c509445
Update base_trainer.py
bveeramani 9c62b92
Update config.py
bveeramani 83b3e89
Update predictors
bveeramani 3cc7836
Remove example
bveeramani 819259d
Merge branch 'master' into bveeramani/air-repr2
bveeramani a327638
Resolve merge issues
bveeramani 6ee74e3
Add preprocessor repr tests
bveeramani 13efed3
Add checkpoint tests
bveeramani c7bdad0
Appease lint
bveeramani a54fdb6
Add some tests
bveeramani e3924b9
Add tests
bveeramani e0682ff
Remove whitespace
bveeramani 74e297d
Add tests to `BUILD`
bveeramani 125e116
Update python/ray/train/tests/test_batch_predictor.py
richardliaw 85b6966
Fix dataset tests
bveeramani 9f33bc7
Fix `DatasetPipeline`
bveeramani a304fc4
Format files
bveeramani 28d71f4
Merge branch 'master' into bveeramani/air-repr2
bveeramani 1cfb3b6
Revert dataset changes
bveeramani f6ed176
Update test_dataset_config.py
bveeramani 4091a42
Merge remote-tracking branch 'upstream/master' into bveeramani/air-repr2
bveeramani c05dc4b
Merge master into branch
richardliaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import pytest | ||
|
||
from ray.air.config import ( | ||
ScalingConfig, | ||
DatasetConfig, | ||
FailureConfig, | ||
CheckpointConfig, | ||
RunConfig, | ||
) | ||
from ray.air.constants import MAX_REPR_LENGTH | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"config", | ||
[ | ||
ScalingConfig(), | ||
ScalingConfig(use_gpu=True), | ||
DatasetConfig(), | ||
DatasetConfig(fit=True), | ||
FailureConfig(), | ||
FailureConfig(max_failures=2), | ||
CheckpointConfig(), | ||
CheckpointConfig(num_to_keep=1), | ||
RunConfig(), | ||
RunConfig(name="experiment"), | ||
RunConfig(failure_config=FailureConfig()), | ||
], | ||
) | ||
def test_repr(config): | ||
representation = repr(config) | ||
|
||
assert eval(representation) == config | ||
assert len(representation) < MAX_REPR_LENGTH | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
|
||
import pytest | ||
|
||
sys.exit(pytest.main(["-v", "-x", __file__])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,24 +56,24 @@ def __init__( | |
raise_if_missing: bool = False, | ||
): | ||
self.output_column_name = output_column_name | ||
self.included_columns = include | ||
self.excluded_columns = exclude or [] | ||
self.include = include | ||
self.exclude = exclude or [] | ||
self.dtype = dtype | ||
self.raise_if_missing = raise_if_missing | ||
|
||
def _validate(self, df: pd.DataFrame): | ||
total_columns = set(df) | ||
if self.excluded_columns and self.raise_if_missing: | ||
missing_columns = set(self.excluded_columns) - total_columns.intersection( | ||
set(self.excluded_columns) | ||
if self.exclude and self.raise_if_missing: | ||
missing_columns = set(self.exclude) - total_columns.intersection( | ||
set(self.exclude) | ||
) | ||
if missing_columns: | ||
raise ValueError( | ||
f"Missing columns specified in 'exclude': {missing_columns}" | ||
) | ||
if self.included_columns and self.raise_if_missing: | ||
missing_columns = set(self.included_columns) - total_columns.intersection( | ||
set(self.included_columns) | ||
if self.include and self.raise_if_missing: | ||
missing_columns = set(self.include) - total_columns.intersection( | ||
set(self.include) | ||
) | ||
if missing_columns: | ||
raise ValueError( | ||
|
@@ -84,10 +84,10 @@ def _transform_pandas(self, df: pd.DataFrame): | |
self._validate(df) | ||
|
||
included_columns = set(df) | ||
if self.included_columns: # subset of included columns | ||
included_columns = set(self.included_columns) | ||
if self.include: # subset of included columns | ||
included_columns = set(self.include) | ||
|
||
columns_to_concat = list(included_columns - set(self.excluded_columns)) | ||
columns_to_concat = list(included_columns - set(self.exclude)) | ||
concatenated = df[columns_to_concat].to_numpy(dtype=self.dtype) | ||
df = df.drop(columns=columns_to_concat) | ||
try: | ||
|
@@ -98,9 +98,18 @@ def _transform_pandas(self, df: pd.DataFrame): | |
return df | ||
|
||
def __repr__(self): | ||
return ( | ||
f"Concatenator(output_column_name={self.output_column_name}, " | ||
f"include={self.included_columns}, " | ||
f"exclude={self.excluded_columns}, " | ||
f"dtype={self.dtype})" | ||
) | ||
default_values = { | ||
"output_column_name": "concat_out", | ||
"include": None, | ||
"exclude": [], | ||
"dtype": None, | ||
"raise_if_missing": False, | ||
} | ||
|
||
non_default_arguments = [] | ||
for parameter, default_value in default_values.items(): | ||
value = getattr(self, parameter) | ||
if value != default_value: | ||
non_default_arguments.append(f"{parameter}={value}") | ||
|
||
return f"{self.__class__.__name__}({', '.join(non_default_arguments)})" | ||
Comment on lines
+101
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this so the representation isn't too long. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice