Faker¶
For anyone who needs realistic names, emails or cities at volume. It teaches RandSpecs.faker_pool: Faker draws a small pool once, and NumPy samples it into many rows.
Prerequisite and run¶
Install the extra first:
pip install "rand-engine[faker]"
rand-engine get-started faker
python faker-example.py
The command writes faker-example.py to the current directory. --out DIR writes it to DIR
instead, created when missing. An existing file is never overwritten. Running it prints the first
rows of a 10,000-row DataFrame and the distinct-name count from the configured pool.
# Databricks notebook source
# Faker: small realistic value pools drawn once, then sampled at NumPy speed into many rows. Needs the faker extra; install it through the [Getting started](https://marcoaureliomenezes.github.io/rand_engine/getting-started/) guide.
# COMMAND ----------
from rand_engine import DataGenerator, RandSpecs
# COMMAND ----------
# Build the pools. Faker runs once per pool value, not per row; seed fixes each pool.
# name uses the pt_BR locale; the others use the default en_US.
spec = {
"user_id": {"method": "pk", "kwargs": {"start": 1}},
"name": RandSpecs.faker_pool("name", locale="pt_BR", pool_size=200, seed=0),
"email": RandSpecs.faker_pool("email", pool_size=200, seed=1),
"city": RandSpecs.faker_pool("city", pool_size=50, seed=2),
"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}},
}
# COMMAND ----------
# Sample 10 000 rows into df from the pools and the native columns, then look at them.
df = DataGenerator(spec, seed=7).size(10_000).get_df()
print(df.head())
print("distinct names:", df["name"].nunique(), "from a pool of", len(spec["name"]["kwargs"]["distincts"]))
What it shows¶
- Install: the
fakerextra is required; use the command above or the Getting started guide. - Pools:
nameuses thept_BRlocale, andemailandcityuse the default locale. Each pool has a size and a seed. - Sample: 10 000 rows drawn from the pools and the native columns, then the head, and the number of distinct names against the pool size.