The time_field() function defines the constraints and behavior for a time-of-day column when generating synthetic data with generate_dataset(). You can control the time range with min_time= and max_time=, enforce uniqueness with unique=True, and introduce null values with nullable=True and null_probability=.
Time values are generated uniformly (at second-level resolution) within the specified range. If no range is provided, the default range is 00:00:00 to 23:59:59. Both min_time= and max_time= accept datetime.time objects or ISO format time strings (e.g., "09:30:00").
Parameters
min_time:str | time | None=None
Minimum time (inclusive). Can be an ISO format string (e.g., "08:00:00") or a datetime.time object. Default is None (defaults to 00:00:00).
max_time:str | time | None=None
Maximum time (inclusive). Can be an ISO format string (e.g., "17:30:00") or a datetime.time object. Default is None (defaults to 23:59:59).
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. With second-level resolution within a time range, uniqueness is feasible for moderate dataset sizes.
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 value.
Returns
TimeField
A time field specification that can be passed to Schema().
Raises
:ValueError
If min_time is later than max_time, or if a time string cannot be parsed.
Examples
The min_time= and max_time= parameters accept datetime.time objects, making it easy to define business-hours ranges: