vecgen 0.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.5
2
+ Name: vecgen
3
+ Version: 0.3.0
4
+ Summary: Declarative, reproducible synthetic datasets with dependent columns, plus data corruption with a ground-truth report.
5
+ Project-URL: Homepage, https://github.com/pchaher03/vecgen
6
+ Project-URL: Repository, https://github.com/pchaher03/vecgen
7
+ Project-URL: Issues, https://github.com/pchaher03/vecgen/issues
8
+ Author: Pablo
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: data-quality,dataset,machine-learning,numpy,pandas,synthetic-data,testing
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Scientific/Engineering
24
+ Classifier: Topic :: Software Development :: Testing
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.9
27
+ Requires-Dist: numpy>=1.24.0
28
+ Requires-Dist: pandas>=2.0.0
29
+ Provides-Extra: dev
30
+ Requires-Dist: build>=1.2.0; extra == 'dev'
31
+ Requires-Dist: mypy>=1.11.0; extra == 'dev'
32
+ Requires-Dist: pandas-stubs>=2.0.0; extra == 'dev'
33
+ Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
34
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
35
+ Requires-Dist: ruff>=0.6.0; extra == 'dev'
36
+ Requires-Dist: twine>=5.0.0; extra == 'dev'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # vecgen
40
+
41
+ **Declarative, reproducible synthetic datasets with dependent columns, plus data corruption that comes with a ground-truth report.**
42
+
43
+ `vecgen` (short for **Vectorized Generator**) lets you describe a dataset as rules, distributions, and dependencies between columns, generate it deterministically with a seed, and then break it on purpose while recording exactly what was broken. You can also inject rule-driven values and edge cases into existing `pandas` DataFrames, Series, and `numpy` arrays.
44
+
45
+ All outputs are native `pandas` and `numpy` structures, making `vecgen` immediately compatible with **scikit-learn**, **PyTorch**, and **TensorFlow** without extra dependencies.
46
+
47
+ ## Key Features
48
+
49
+ * **Conditional & Dependent Columns:** Define a column differently per condition (`when="country == 'MX'"`), or make distribution parameters depend on other columns (`mean="age * 800"`). Columns are resolved in dependency order, so you can declare them in any order.
50
+ * **Corruption with a Ground-Truth Report:** `inject_nulls`, `inject_duplicates`, and `inject_outliers` can return a `CorruptionReport` listing every row, column, and value they changed. Use it to check that your pipeline or validation rules caught what they should have.
51
+ * **Serializable Builders:** Save a `DatasetBuilder` definition to JSON and reload it later. The same JSON plus the same seed gives the same dataset.
52
+ * **Pandas & NumPy Polymorphism:** Accepts `pd.DataFrame`, `pd.Series`, and 1D/2D `np.ndarray` inputs and returns the exact same type, shape, and preserved index/column metadata.
53
+ * **Flexible Rule Engine:** Define conditional logic using boolean masks, Python callables (`lambda df: ...`), or pandas query strings (`"age >= 18 and country == 'MX'"`).
54
+ * **ML-Ready Dataset Builder:** Generate synthetic DataFrames via `.build()` or export pure NumPy `(X, y)` feature/target arrays directly via `.build_numpy(target=...)`.
55
+ * **Vectorized & Deterministic:** Built purely on NumPy and pandas vectorized operations, non-destructive by default (`inplace=False`), and fully reproducible via `seed`.
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ pip install vecgen
61
+ ```
62
+
63
+ For local development:
64
+
65
+ ```bash
66
+ git clone https://github.com/pchaher03/vecgen.git
67
+ cd vecgen
68
+ pip install -e ".[dev]"
69
+ ```
70
+
71
+ ## Quickstart
72
+
73
+ ### 1. Generate a Dataset with Conditional and Dependent Columns
74
+
75
+ ```python
76
+ from vecgen import DatasetBuilder
77
+
78
+ builder = DatasetBuilder(rows=10_000, seed=42)
79
+
80
+ builder.add_distribution("age", dist="normal", mean=35, std=10, clip=(18, 90), dtype="int64")
81
+ builder.add_choice("country", choices=["MX", "US", "CA"], weights=[0.5, 0.3, 0.2])
82
+
83
+ # Parameters can be expressions of other columns
84
+ builder.add_distribution("income", dist="normal", mean="age * 800", std=6_000, clip=(0, None))
85
+
86
+ # Same column, different behavior per condition (first match wins; no `when` = fallback)
87
+ builder.add_distribution("spend", dist="lognormal", mean=4.0, sigma=0.5, when="country == 'MX'")
88
+ builder.add_distribution("spend", dist="normal", mean=150, std=40, when="country == 'US'")
89
+ builder.add_distribution("spend", dist="normal", mean=120, std=30)
90
+
91
+ # Rules can depend on any column; declaration order does not matter
92
+ builder.add_rule("is_eligible", rule="age >= 21 and country in ['MX', 'US']", value=1, default=0)
93
+
94
+ # Export as a pandas DataFrame
95
+ df = builder.build()
96
+
97
+ # Or export directly as NumPy (X, y) arrays for scikit-learn / PyTorch / TensorFlow
98
+ X, y = builder.build_numpy(target="is_eligible")
99
+ ```
100
+
101
+ Dependencies in string rules and expressions are detected automatically. If you use a callable, declare its inputs with `depends_on=["age"]`. Circular dependencies raise `CircularDependencyError`.
102
+
103
+ ### 2. Corrupt the Data and Get a Ground-Truth Report
104
+
105
+ ```python
106
+ import vecgen as vg
107
+
108
+ dirty, report = vg.inject_outliers(
109
+ df, cols=["spend"], rate=0.05, magnitude=5, seed=42, return_report=True
110
+ )
111
+
112
+ report.summary() # counts per corruption kind and column
113
+ report.to_frame() # row_position, index_label, column, kind, original_value, new_value
114
+
115
+ # Compare against whatever your pipeline flagged
116
+ flagged = my_outlier_detector(dirty) # boolean row mask or row positions
117
+ result = report.evaluate(flagged, kind="outlier")
118
+ print(result.recall, result.precision, result.missed)
119
+ ```
120
+
121
+ Reports can be combined with `+`, so you can inject nulls, duplicates, and outliers in sequence and keep a single manifest. Without `return_report=True` the injectors return just the corrupted data, so they still work inside `df.pipe(...)`.
122
+
123
+ ### 3. Save and Reload a Builder
124
+
125
+ ```python
126
+ builder.to_json("orders_v1.json")
127
+ same_builder = DatasetBuilder.from_json("orders_v1.json")
128
+ assert same_builder.build().equals(df)
129
+ ```
130
+
131
+ Only JSON-representable definitions can be exported: string rules, string expressions, and scalar parameters. Callables and boolean masks raise a `SchemaError` that names the offending column. Loaded rules are evaluated as pandas expressions, so treat JSON files from untrusted sources the way you would treat any config that contains code.
132
+
133
+ ### 4. Augment an Existing DataFrame or NumPy Array
134
+
135
+ ```python
136
+ import numpy as np
137
+ import pandas as pd
138
+ import vecgen as vg
139
+
140
+ df = pd.DataFrame({
141
+ "age": [17, 25, 68, 42],
142
+ "spend": [20.0, 150.0, 300.0, 85.0],
143
+ })
144
+
145
+ df = (
146
+ df.pipe(vg.set_values, col="tier", rule="spend >= 100", value="premium", default="standard")
147
+ .pipe(vg.set_values, col="discount", rule=lambda d: d["age"] >= 65, value=0.20, default=0.0)
148
+ .pipe(vg.inject_nulls, cols=["spend"], rate=0.25, seed=42)
149
+ )
150
+
151
+ # Pure 2D NumPy array (returns a copy of the same shape)
152
+ arr = np.array([[17, 20.0], [68, 300.0]])
153
+ arr_updated = vg.set_values(arr, col=1, rule=lambda x: x[:, 0] >= 65, value=0.0)
154
+ ```
155
+
156
+ ### 5. Use the Pandas `.gen` Accessor
157
+
158
+ ```python
159
+ import pandas as pd
160
+ import vecgen # Registers the .gen accessor on DataFrames and Series
161
+
162
+ df = pd.DataFrame({"score": [45, 82, 91, 60]})
163
+ df = df.gen.apply_rule(col="passed", rule=df["score"] >= 70, value=True, default=False)
164
+ ```
165
+
166
+ ## What vecgen is (and is not)
167
+
168
+ `vecgen` preserves the distributions, conditions, and dependencies that you declare. It does not learn them from real data and it does not make privacy guarantees. If you need statistical cloning of real datasets, look at tools such as SDV.
169
+
170
+ ## Project Documentation
171
+
172
+ * [Project Vision & Requirements (FR-1 – FR-11, NFR-1 – NFR-7)](docs/project_vision.md)
173
+ * [Repository & Architecture Structure](docs/project_structure.txt)
174
+
175
+ ## License
176
+
177
+ Distributed under the MIT License. See `LICENSE` for more information.
@@ -0,0 +1,18 @@
1
+ vecgen/__init__.py,sha256=QpclrntvB9UTDL9k6ZCnrBCp32O_mj2MGc93bvNMJWs,1000
2
+ vecgen/_compat.py,sha256=vhm73o8ebBhfgIfk2u2DGOBRiaeRAthpOHaRtKEUNRA,5822
3
+ vecgen/_graph.py,sha256=xVss8PWiTtc-p3-GlN_jNTPjKCDvkOendCjZLlmRMJQ,4038
4
+ vecgen/accessor.py,sha256=nj3i0lxi7OmtSH9JDRDRKOdfG7UR0AftBFeYO0vKKUU,6280
5
+ vecgen/builder.py,sha256=hovbN3NiKikVztgsSHFeMmRPK_U1fI1YtN6seaL0kCE,11811
6
+ vecgen/distributions.py,sha256=L3UUX_zU_wtGuHBNksmPzpcvxxUH82FdzMRU5OcS1Ec,6660
7
+ vecgen/engine.py,sha256=uLyFHx1JiNfmKmBnskgVeDpw5vzJRZA1_WSoiIXrq98,8469
8
+ vecgen/exceptions.py,sha256=eVReQ_ygiT236lHX5QDmb_wt0kUYfNQYqxZFQ7lqEMg,519
9
+ vecgen/noise.py,sha256=p_jKGDQUmOHnKyvxB8BQkFgwO8276LJ7eU_hd1LI950,15446
10
+ vecgen/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ vecgen/report.py,sha256=S661nWGjX4swGsCNW-XQDFuFmI5hv-5Tv9qW9GMu4cg,8305
12
+ vecgen/rules.py,sha256=bt2CZ2YKuOltGS3-BtAA9VCHkAkGUA7r-iD0hkxF8Io,4578
13
+ vecgen/serialization.py,sha256=ic7VHjvnCuuYv_omVP1ILtJpFxu_UhvEeNLMq5vXwvg,10858
14
+ vecgen/types.py,sha256=aV8uJm1OlLW54zGGQDLtUWHEoRhNO6efllE3k1sroes,1142
15
+ vecgen-0.3.0.dist-info/METADATA,sha256=IRNEb6lgX18OMlNj0tRjiH_sF9Ey5k0gOZg-2FPTzig,8137
16
+ vecgen-0.3.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
17
+ vecgen-0.3.0.dist-info/licenses/LICENSE,sha256=adee5ha_q7tG3Tq2HEiYaKrXJgkU9NfSEUHSp3Ja4Ic,1062
18
+ vecgen-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pablo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.