Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`generate_dataset()` ignores `unique=True` for coherent presets (email, name, city, ...)

Chiusa
#441 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #447 di @rich-iannone — integrata

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
69/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
data

Direzione di ricerca

Start with _generate_single_country() and _generate_column_with_row_context() in pointblank/generate/generators.py, then compare their handling of field.unique with generate_column() and _generate_unique_values(). Reproduce the duplicates using the issue’s script and presets. Done means coherent presets either produce the requested number of unique values or raise a clear error when that cannot be achieved.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

string_field(preset=..., unique=True) returns duplicate values, without any error or warning, when the preset belongs to one of the coherent groups (person, address, business, credit card). Presets outside those groups (e.g. url, uuid4) are unique as expected.

Reproducer

import pointblank as pb

for preset in ["email", "name", "city", "user_name", "url", "uuid4"]:
    schema = pb.Schema(x=pb.string_field(preset=preset, unique=True))
    df = pb.generate_dataset(schema, n=2000, seed=42, country="US")
    print(f"{preset:10} distinct={df['x'].n_unique()} / 2000")

Output:

email      distinct=1998 / 2000
name       distinct=1946 / 2000
city       distinct=156 / 2000
user_name  distinct=1994 / 2000
url        distinct=2000 / 2000
uuid4      distinct=2000 / 2000

For city the constraint cannot be satisfied at all with the available values, but no error is raised. On the regular path, _generate_unique_values() would raise "Unable to generate 2000 unique values ...".

Cause

In pointblank/generate/generators.py, _generate_single_country() sends every column whose preset is in coherent_presets to _generate_column_with_row_context() (line 666 on main at 4510729):

if needs_coherence and preset in coherent_presets:
    data[col_name] = _generate_column_with_row_context(field, config, shared_locale_gen)
else:
    data[col_name] = generate_column(field, config)

generate_column() checks field.unique and uses _generate_unique_values(), but _generate_column_with_row_context() (line 533) generates one value per row and never looks at field.unique.

Expected behavior

Either the values are unique, or an error is raised when uniqueness cannot be guaranteed, as on the regular path. Since coherent values are built per row from a shared person/location context, a full fix may need retries at the row-context level; raising a clear error (or at least a warning) when unique=True is combined with a coherent preset would already avoid silently returning invalid data.

Environment

  • pointblank 1.0.1 (also reproduced on 0.25.0)
  • polars 1.38.1
  • Python 3.12.7
  • Linux

Found while using pointblank as the generation engine of fauxdata.

Lingua principale
Python
Stelle
493
Fork
34
Merge medio
13h 39m
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di posit-dev/pointblank

Tutte le issue di posit-dev/pointblank

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.