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

pyfloat() - floats passed as min_value and max_value params TypeError: 'float' object cannot be interpreted as an integer #2039

Open
josidridolfo opened this issue May 2, 2024 · 0 comments

Comments

@josidridolfo
Copy link

josidridolfo commented May 2, 2024

  • Faker version: 25.0.1
  • OS: Mac OS Sonoma 14.4.1

Brief summary of the issue goes here.

faker.pyfloat()'s min_value and max_value no longer accepts floats; ints work. This is despite the documentation stating that floats are valid datatypes for the min_value and max_value params.

from faker import faker
faker = Faker()
eur_val = faker.pyfloat(left_digits=10,
                            right_digits=2,
                            positive=True,
                            min_value=0.01,
                            max_value=999999999.99,
                )

Expected behavior

output should be a float between 0.01 and 999999999.99

Actual behavior

output does not include floats below 1 or above the max value.

Relevant error:

  File "/usr/src/app/contracts/management/commands/populate_contracts.py", line 42, in handle
    "currency_value": faker.pyfloat(
                      ^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/faker/providers/python/__init__.py", line 133, in pyfloat
    left_number = self._safe_random_int(
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/faker/providers/python/__init__.py", line 172, in _safe_random_int
    return self.random_int(min_value, max_value - 1)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/faker/providers/__init__.py", line 316, in random_int
    return self.generator.random.randrange(min, max + 1, step)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/random.py", line 312, in randrange
    istop = _index(stop)
            ^^^^^^^^^^^^
TypeError: 'float' object cannot be interpreted as an integer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant