The float_field() function defines the constraints and behavior for a floating-point column when generating synthetic data with generate_dataset(). You can control the range of values with min_val= and max_val=, restrict values to a specific set with allowed=, enforce uniqueness with unique=True, and introduce null values with nullable=True and null_probability=. The dtype= parameter lets you choose between "Float32" and "Float64" precision.
When both min_val= and max_val= are provided, values are drawn from a uniform distribution across that range. If neither is specified, values are drawn uniformly from a large default range. If allowed= is provided, values are sampled from that specific list.
Parameters
min_val:float | None=None
Minimum value (inclusive). Default is None (no minimum).
max_val:float | None=None
Maximum value (inclusive). Default is None (no maximum).
allowed:list[float] | None=None
List of allowed values (categorical constraint). When provided, values are sampled from this list. Cannot be combined with min_val=/max_val=.
nullable:bool=False
Whether the column can contain null values. Default is False.
null_probability:float=0.0
Probability of generating a null value for each row when nullable=True. Must be between 0.0 and 1.0. Default is 0.0.
unique:bool=False
Whether all values must be unique. Default is False. When True, the generator will retry until it produces n distinct values.
generator:Callable[[], Any] | None=None
Custom callable that generates values. When provided, this overrides all other constraints. The callable should take no arguments and return a single float value.
dtype:str='Float64'
Float dtype. Default is "Float64". Options: "Float32", "Float64".
Returns
FloatField
A float field specification that can be passed to Schema().
Raises
:ValueError
If min_val is greater than max_val, if allowed is an empty list, if null_probability is not between 0.0 and 1.0, or if dtype is not a valid float type.
Examples
The min_val= and max_val= parameters define the generated value ranges: