int_field()function

Create an integer column specification.

USAGE

int_field(
    min_val=None,
    max_val=None,
    allowed=None,
    nullable=False,
    null_probability=0.0,
    unique=False,
    generator=None,
    dtype='Int64',
)

Parameters

min_val : int | None = None

Minimum value (inclusive). Default is None (no minimum).

max_val : int | None = None

Maximum value (inclusive). Default is None (no maximum).

allowed : list[int] | None = None

List of allowed values (categorical constraint). When provided, values are sampled from this list.

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.

dtype : str = 'Int64'

Integer dtype. Default is "Int64". Options: "Int8", "Int16", "Int32", "Int64", "UInt8", "UInt16", "UInt32", "UInt64".

Returns

IntField

An integer field specification.

Examples


Define a schema with integer fields and generate test data:

import pointblank as pb

# Define a schema with integer field specifications
schema = pb.Schema(
    user_id=pb.int_field(min_val=1, unique=True),
    age=pb.int_field(min_val=0, max_val=120),
    rating=pb.int_field(allowed=[1, 2, 3, 4, 5]),
)

# Generate 100 rows of test data
pb.preview(pb.generate_dataset(schema, n=100, seed=23))
PolarsRows100Columns3
user_id
Int64
age
Int64
rating
Int64
1 7188536481533917197 118 3
2 2674009078779859984 99 1
3 7652102777077138151 37 1
4 157503859921753049 114 5
5 2829213282471975080 106 3
96 7027508096731143831 36 2
97 6055996548456656575 69 1
98 3822709996092631588 39 2
99 1522653102058131295 114 1
100 5690877051669225499 99 5

The generated data will have unique user IDs starting from 1, ages between 0-120, and ratings sampled from the allowed values.