date_field()function

Create a date column specification.

USAGE

date_field(
    min_date=None,
    max_date=None,
    nullable=False,
    null_probability=0.0,
    unique=False,
    generator=None,
)

Parameters

min_date : str | date | None = None

Minimum date (inclusive). Can be ISO string or date object.

max_date : str | date | None = None

Maximum date (inclusive). Can be ISO string or date object.

nullable : bool = False

Whether the column can contain null values. Default is False.

null_probability : float = 0.0

Probability of generating null when nullable=True. Default is 0.0.

unique : bool = False

Whether all values must be unique. Default is False.

generator : Callable[[], Any] | None = None

Custom callable that generates values. Overrides other settings.

Returns

DateField

A date field specification.

Examples


Define a schema with date fields and generate test data:

import pointblank as pb
from datetime import date

# Define a schema with date field specifications
schema = pb.Schema(
    birth_date=pb.date_field(
        min_date=date(1960, 1, 1),
        max_date=date(2005, 12, 31)
    ),
    hire_date=pb.date_field(
        min_date=date(2020, 1, 1),
        max_date=date(2024, 12, 31)
    ),
)

# Generate 100 rows of test data
pb.preview(pb.generate_dataset(schema, n=100, seed=23))
PolarsRows100Columns2
birth_date
Date
hire_date
Date
1 1986-01-03 2024-05-15
2 1967-06-30 2021-08-16
3 1961-07-13 2024-08-26
4 1987-07-09 2020-06-20
5 1998-01-06 2020-02-04
96 1969-04-14 2023-01-29
97 1975-03-23 2021-03-23
98 1981-05-29 2021-06-13
99 1982-09-14 2020-11-02
100 1968-12-21 2020-08-07

Date values are uniformly distributed within the specified range.