Skip to content

Commit 12e84d7

Browse files
CopilotVibhuJawa
andauthored
Fix RayStageSpecKeys enum membership check for Python < 3.12 compatibility (#1039)
* Initial plan * Fix RayStageSpecKeys enum membership check for Python < 3.12 compatibility Co-authored-by: VibhuJawa <[email protected]> * Add test for RayStageSpecKeys compatibility fix Co-authored-by: VibhuJawa <[email protected]> * Fix ruff linting issues in test file - remove trailing whitespace and add final newline Co-authored-by: VibhuJawa <[email protected]> * Address code review feedback - import RayStageSpecKeys instead of redefining it in test Co-authored-by: VibhuJawa <[email protected]> * Remove __main__ block from test file as requested in code review Co-authored-by: VibhuJawa <[email protected]> * Move RayStageSpecKeys compatibility test to proper location and clean up format Co-authored-by: VibhuJawa <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: VibhuJawa <[email protected]> Co-authored-by: Vibhu Jawa <[email protected]>
1 parent 419febc commit 12e84d7

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

nemo_curator/backends/experimental/ray_data/adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, stage: ProcessingStage):
4646

4747
# Go through all the keys in the ray_stage_spec and raise error if they are not in RayStageSpecKeys
4848
for key in self.stage.ray_stage_spec():
49-
if key not in RayStageSpecKeys:
49+
if key not in {e.value for e in RayStageSpecKeys}:
5050
msg = f"Invalid key {key} in ray_stage_spec for stage {self.stage}"
5151
raise ValueError(msg)
5252

tests/backends/experimental/test_utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from pytest import LogCaptureFixture
2121

2222
from nemo_curator.backends.base import NodeInfo, WorkerMetadata
23-
from nemo_curator.backends.experimental.utils import execute_setup_on_node
23+
from nemo_curator.backends.experimental.utils import RayStageSpecKeys, execute_setup_on_node
2424
from nemo_curator.stages.base import ProcessingStage
2525
from nemo_curator.stages.resources import Resources
2626

@@ -93,3 +93,26 @@ def setup_on_node(
9393
assert len(matching_logs) == len(ray.nodes()), (
9494
f"Expected {len(ray.nodes())} logs for setup on node for 2 stages, got {len(matching_logs)}: {matching_logs}"
9595
)
96+
97+
98+
class TestRayStageSpecKeys:
99+
"""Test class for RayStageSpecKeys enum compatibility."""
100+
101+
def test_enum_membership_compatibility(self):
102+
"""Test that the fixed pattern works across Python versions."""
103+
# Test data
104+
valid_keys = ["is_actor_stage", "is_fanout_stage", "is_lsh_stage"]
105+
invalid_keys = ["invalid_key", "another_bad_key"]
106+
107+
# Test the fixed pattern - this is what's now used in the adapter
108+
enum_values = {e.value for e in RayStageSpecKeys}
109+
110+
# Testing valid keys
111+
for key in valid_keys:
112+
result = key not in enum_values
113+
assert result is False, f"Valid key '{key}' should be found in enum values"
114+
115+
# Testing invalid keys
116+
for key in invalid_keys:
117+
result = key not in enum_values
118+
assert result is True, f"Invalid key '{key}' should not be found in enum values"

0 commit comments

Comments
 (0)