-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: pyfloat type error on none max value #1908
fix: pyfloat type error on none max value #1908
Conversation
if max_value is None: | ||
temp_max_value = 10 ** (left_digits + right_digits) | ||
if min_value is not None: | ||
temp_min_value = min_value * 10 ** right_digits | ||
if min_value is None: | ||
temp_min_value = -(10 ** (left_digits + right_digits)) | ||
if max_value is not None: | ||
if max_value < temp_min_value: | ||
temp_min_value = max_value - 1 | ||
temp_max_value = max_value * 10 ** right_digits |
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.
This section aims to infer boundaries in the case where we don't have max_value or min_value.
temp_min_value = min_value | ||
temp_max_value = max_value |
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.
Renamed to temp
rather than left
because it is now doing both the right and left parts.
opposite_signs = (temp_min_value * temp_max_value) < 0 | ||
if opposite_signs and left_digits_requested: | ||
positive_number = self._safe_random_int( | ||
10 ** (left_digits + right_digits - 1), | ||
temp_max_value, | ||
positive=True, | ||
) | ||
negative_number = self._safe_random_int( | ||
temp_min_value, | ||
-(10 ** (left_digits + right_digits - 1)), | ||
positive=False, | ||
) | ||
number = self.random_element((positive_number, negative_number)) |
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.
This part is so that we can generate a number which respects these two constraints:
- It must have a fixed amount of left digits
- It can be either positive or negative.
In this case we need to choose two numbers, one in the negative side, and one in the positive. We then choose randomly between the two.
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.
Thank you! <3
What does this change
Handle the combinations of specified digits and min and max values in a more advanced way for pyfloat.
What was wrong
There were a few issues that this PR aims to address:
needed_left_digits == sys.float_info.dig
because the range was then invalid-(10**sys.float_info.dig + 1)
as max value and10**sys.float_info.dig
as min_value can never succeed because of the following code at the end:How this fixes it
ValueError
is raised if max_value or min_value is out of boundsleft_number
which then caused issues in trying to figure out a "right number" which could then end up being lower/higher than the configured max/min value, an int is chosen randomly between min and max values which are scaled up to have the length of left + right digits so that afterwards a.
can be inserted in the right place.Fixes #1907