`generate_dataset()` ignores `unique=True` for coherent presets (email, name, city, ...)
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
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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from posit-dev/pointblank
-
Type: ★ Enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
posit-dev/pointblank#379 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
posit-dev/pointblank#395 ·
Maintainers usually reply within 1 day
-
Type: ★ Enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
posit-dev/pointblank#394 ·
Maintainers usually reply within 1 day
-
ibis.pyspark col_vals_in_set produces invalid SQLMay be free again @rich-iannone claimed this 295 days ago, and no pull request is open. OpenDifficulty: [2] Intermediate Effort: [3] High Priority: [3] High Type: ☹︎ Bug
posit-dev/pointblank#335 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
-
YAML value column selectorMay be free again @rich-iannone claimed this 313 days ago, and no pull request is open. OpenDifficulty: [2] Intermediate Effort: [3] High Priority: [3] High Type: ☹︎ Bug
posit-dev/pointblank#333 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
All issues in posit-dev/pointblank
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 1/5 Under an hour Newbie friendliness 62/100
-
Difficulty 1/5 Under an hour Newbie friendliness 70/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
topoteretes/cognee#5773 ·
Maintainers usually reply within 1 day
-
MiKTeX: a failed build reports no errors because texify --quiet switches the log to file:line: styleOpen
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
SublimeText/LaTeXTools#1718 ·