Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Closed
#441 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

A pull request for this has already been merged.

  • #447 by @rich-iannone — merged

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
69/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
data

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
493
Forks
34
Avg merge
13h 39m
Merged PRs (30d)
16

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from posit-dev/pointblank

All issues in posit-dev/pointblank

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.