pyfloat() - floats passed as min_value and max_value params TypeError: 'float' object cannot be interpreted as an integer
- 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
I test the code and worked well as expected, on version 25.8.0, can you provide your faker version?
And in your code the f of faker should be capital.
from faker import Faker
The code I tested:
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,
)
print(eur_val)
#OUTPUT
#930165130.36
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.