-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[Data] Move env_float, env_integer, and env_bool to ray._common #60642
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
base: master
Are you sure you want to change the base?
[Data] Move env_float, env_integer, and env_bool to ray._common #60642
Conversation
Signed-off-by: DeborahOlaboye <deboraholaboye@gmail.com>
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.
Code Review
This pull request refactors the env_integer, env_float, and env_bool utility functions by moving them from ray._private.ray_constants to ray._common.utils. The changes across the codebase correctly update the import paths to reflect this move.
My review focuses on the implementation of the moved functions. I've identified a correctness issue in env_integer where it fails to handle negative integer values from environment variables. I've also suggested a minor improvement to env_bool for better readability and to avoid redundant lookups. The implementation of env_float looks good.
| def env_integer(key, default): | ||
| if key in os.environ: | ||
| value = os.environ[key] | ||
| if value.isdigit(): | ||
| return int(os.environ[key]) | ||
|
|
||
| logger.debug( | ||
| f"Found {key} in environment, but value must " | ||
| f"be an integer. Got: {value}. Returning " | ||
| f"provided default {default}." | ||
| ) | ||
| return default | ||
| return default |
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.
The use of value.isdigit() to check if an environment variable is an integer is not robust as it doesn't handle negative numbers (e.g., "-1".isdigit() is False). This will cause the function to incorrectly fall back to the default value for negative integers. It's better to use a try-except ValueError block for conversion, which is more robust and consistent with the implementation of env_float.
| def env_integer(key, default): | |
| if key in os.environ: | |
| value = os.environ[key] | |
| if value.isdigit(): | |
| return int(os.environ[key]) | |
| logger.debug( | |
| f"Found {key} in environment, but value must " | |
| f"be an integer. Got: {value}. Returning " | |
| f"provided default {default}." | |
| ) | |
| return default | |
| return default | |
| def env_integer(key, default): | |
| if key in os.environ: | |
| value = os.environ[key] | |
| try: | |
| return int(value) | |
| except ValueError: | |
| logger.debug( | |
| f"Found {key} in environment, but value must " | |
| f"be an integer. Got: {value}. Returning " | |
| f"provided default {default}." | |
| ) | |
| return default | |
| return default |
| def env_bool(key, default): | ||
| if key in os.environ: | ||
| return ( | ||
| True | ||
| if os.environ[key].lower() == "true" or os.environ[key] == "1" | ||
| else False | ||
| ) | ||
| return default |
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.
The current implementation accesses os.environ[key] multiple times within the conditional logic. This can be slightly improved for efficiency and readability by storing the value in a local variable before performing comparisons.
def env_bool(key, default):
if key in os.environ:
val = os.environ[key].lower()
return val == "true" or val == "1"
return defaultThere 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.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
| ResourceRequestPriority, | ||
| ) | ||
| from ray.autoscaler._private.constants import env_integer | ||
| from ray._common.utils import env_integer |
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.
Wrong env_integer implementation imported, losing inf support
Medium Severity
The import of env_integer changed from ray.autoscaler._private.constants to ray._common.utils, but these have different implementations. The autoscaler version supports "inf" (returning sys.maxsize), accepts negative numbers via direct int() conversion, and raises ValueError on invalid input. The common utils version uses isdigit() which rejects negative numbers and "inf", silently falling back to the default. If users previously set RAY_DATA_AUTOSCALING_COORDINATOR_REQUEST_GET_TIMEOUT_S=inf for example, this would now silently use the default value instead.


Description
Move
env_integer,env_float, andenv_boolutility functions fromray._private.ray_constantstoray._common.utils. Update all Ray Data imports to use the new location.Related issues
Fixes #60516