Dummy Data Generation¶
Synthetic dataset generation utilities.
Main API¶
csvw_eo.make_dummy_from_metadata
¶
CSVW-EO Dummy Dataset Generator.
This module generates a synthetic dummy dataset from CSVW-EO metadata. It is intended for testing pipelines and validating metadata structures.
The generator supports: - categorical partitions - numeric partitions - datetime ranges - nullable proportions - column groups (joint partitions)
The resulting dataset respects the structural information contained in CSVW-EO metadata but does not guarantee semantic correctness.
apply_nulls_dataframe(df: pd.DataFrame, columns_meta: list[dict[str, Any]], rng: np.random.Generator) -> pd.DataFrame
¶
Apply missing values (nulls) to a dataframe according to metadata.
Each column is assigned null values based on its configured null proportion and datatype-specific null handling strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input dataframe to modify. |
required |
columns_meta
|
list[dict[str, Any]]
|
Metadata describing each column, including null proportions and datatype information. |
required |
rng
|
Generator
|
NumPy random number generator used for stochastic null injection. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Dataframe with null values applied according to metadata rules. |
Source code in csvw-eo-library/src/csvw_eo/make_dummy_from_metadata.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
apply_nulls_serie(series: pd.Series, nullable_prop: float, datatype: DataTypes, rng: np.random.Generator) -> pd.Series
¶
Inject null values into a column according to metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
Series
|
Column values. |
required |
nullable_prop
|
float
|
Proportion of null values. |
required |
datatype
|
DataTypes
|
Column datatype. |
required |
rng
|
Generator
|
Random number generator. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Column with nulls applied. |
Source code in csvw-eo-library/src/csvw_eo/make_dummy_from_metadata.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
build_generation_order(depends_map: dict[str, list[dict[str, Any]]]) -> list[str]
¶
Compute a deterministic column generation order based on dependencies.
This function attempts to order columns such that each column appears after all the columns it depends on (i.e., a topological ordering).
The input is a mapping of column names to a list of dependency
specifications. Each dependency dict may contain a DEPENDS_ON key
indicating another column that must be generated first.
Behavior
- A dependency graph is built where each column maps to the set of columns it depends on.
- Self-dependencies are ignored.
- Columns are iteratively selected:
- Prefer columns whose dependencies are already resolved.
- Among those, selection is deterministic (alphabetical order).
- If no such column exists (e.g., due to cycles or missing dependencies), a fallback strategy is used:
- Select the column with the fewest dependencies.
- Break ties alphabetically.
This ensures the function always returns a complete, deterministic order, even when the dependency graph is not a valid DAG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depends_map
|
dict[str, list[dict[str, Any]]]
|
Mapping of column name to a list of dependency definitions.
Each dependency dict may include a |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of column names in generation order. Dependencies will appear before dependents whenever possible. |
Notes
- Cycles are not explicitly detected or reported. Instead, they are handled via the fallback strategy.
- Missing dependency references (i.e., dependencies not present as keys
in
depends_map) are treated as unresolved and may influence ordering. - The output is stable and deterministic for a given input.
Source code in csvw-eo-library/src/csvw_eo/make_dummy_from_metadata.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
column_group_partitions(df: pd.DataFrame, columns_group_meta: list[dict[str, Any]]) -> pd.DataFrame
¶
Filter a dataframe to keep only rows belonging to allowed column-group partitions.
The function builds a global boolean mask by combining per-column-group partition or key constraints, depending on metadata configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input dataframe to filter. |
required |
columns_group_meta
|
list[dict[str, Any]]
|
Metadata describing column groups and their partitioning rules. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered dataframe containing only rows that satisfy all group constraints. |
Source code in csvw-eo-library/src/csvw_eo/make_dummy_from_metadata.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
main() -> None
¶
Command-line interface for dummy dataset generation.
Source code in csvw-eo-library/src/csvw_eo/make_dummy_from_metadata.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
make_dummy_from_metadata(metadata: dict[str, Any], nb_rows: int = 100, seed: int = 0) -> pd.DataFrame
¶
Generate a dummy dataset from CSVW-EO metadata, respecting exhaustive column group partitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict
|
CSVW-EO metadata structure. |
required |
nb_rows
|
int
|
Number of rows to generate. |
100
|
seed
|
int
|
Random seed. |
0
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Generated dataset |
Source code in csvw-eo-library/src/csvw_eo/make_dummy_from_metadata.py
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | |
Series Generation Utilities¶
csvw_eo.generate_series
¶
CSVW-EO Dummy Dataset Generator.
This module generates a synthetic dummy dataset from CSVW-EO metadata. It is intended for testing pipelines and validating metadata structures.
The generator supports: - categorical partitions - numeric partitions - datetime ranges - nullable proportions - column groups (joint partitions)
The resulting dataset respects the structural information contained in CSVW-EO metadata but does not guarantee semantic correctness.
bigger_series(depend_serie: pd.Series, col_meta: dict[str, Any], nb_rows: int, rng: np.random.Generator) -> pd.Series
¶
Generate a series where each value is greater than the corresponding value.
in depend_serie, while respecting the original column bounds.
Works for numeric and datetime columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depend_serie
|
Series
|
The series this column depends on. |
required |
col_meta
|
dict
|
Metadata for the column, must contain bounds and datatype. |
required |
nb_rows
|
int
|
Number of rows to generate. |
required |
rng
|
Generator
|
Random number generator for offsets. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Generated series satisfying BIGGER dependency. |
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
fixed_series(depend_serie: pd.Series, col_meta: dict[str, Any], rng: np.random.Generator) -> pd.Series
¶
Generate a series where each unique entity in depend_serie has a fixed value.
(multi-row fixedPerEntity dependency).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depend_serie
|
Series
|
Entity identifier series. |
required |
col_meta
|
dict
|
Column metadata, must include DATATYPE. |
required |
rng
|
Generator
|
Random number generator for value generation. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Series satisfying FIXED dependency. |
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
generate_boolean_column(nb_rows: int, rng: np.random.Generator) -> pd.Series
¶
Generate a boolean column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nb_rows
|
int
|
Number of rows to generate. |
required |
rng
|
Generator
|
NumPy random number generator. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Series containing randomly generated boolean values. |
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
generate_column_series(col_meta: dict[str, Any], nb_rows: int, rng: np.random.Generator) -> pd.Series
¶
Generate a column series based on metadata and datatype.
Supports datetime, integer, floating-point, boolean, string, and duration datatypes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col_meta
|
dict[str, Any]
|
Column metadata describing datatype and constraints. |
required |
nb_rows
|
int
|
Number of rows to generate. |
required |
rng
|
Generator
|
NumPy random number generator. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Generated pandas Series with the appropriate datatype. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the datatype is unknown or unsupported. |
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
generate_dataframe(depends_map: dict[str, list[dict[str, Any]]], order: list[str], meta_map: dict[str, dict[str, Any]], nb_rows: int, rng: np.random.Generator) -> pd.DataFrame
¶
Generate a dummy dataframe based on column metadata and dependency rules.
Columns are generated in a specified order, optionally using dependency relationships between columns (e.g., mapping, fixed, or relational constraints).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depends_map
|
dict[str, list[dict[str, Any]]]
|
Mapping of column names to their dependency definitions. Each dependency may define how a column depends on another column. |
required |
order
|
list[str]
|
Ordered list of column names defining generation sequence. |
required |
meta_map
|
dict[str, dict[str, Any]]
|
Metadata for each column describing datatype, constraints, and generation rules. |
required |
nb_rows
|
int
|
Number of rows to generate. |
required |
rng
|
Generator
|
NumPy random number generator used for all stochastic operations. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Generated dataframe with dummy random values respecting metadata and dependency constraints. |
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
generate_datetime_column(col_meta: dict[str, Any], nb_rows: int, rng: np.random.Generator) -> pd.Series
¶
Generate a datetime column between minimum and maximum values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col_meta
|
dict[str, Any]
|
Column metadata containing datetime bounds. |
required |
nb_rows
|
int
|
Number of rows to generate. |
required |
rng
|
Generator
|
NumPy random number generator. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Series containing randomly generated datetime values. |
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
generate_double_column(col_meta: dict[str, Any], nb_rows: int, rng: np.random.Generator) -> pd.Series
¶
Generate a floating-point column between minimum and maximum values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col_meta
|
dict[str, Any]
|
Column metadata containing numeric bounds. |
required |
nb_rows
|
int
|
Number of rows to generate. |
required |
rng
|
Generator
|
NumPy random number generator. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Series containing randomly generated floating-point values. |
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
generate_duration_column(col_meta: dict[str, Any], nb_rows: int, rng: np.random.Generator) -> pd.Series
¶
Generate a duration column between minimum and maximum values.
Bounds are interpreted as seconds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col_meta
|
dict[str, Any]
|
Column metadata containing duration bounds. |
required |
nb_rows
|
int
|
Number of rows to generate. |
required |
rng
|
Generator
|
NumPy random number generator. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Series containing randomly generated durations. |
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
generate_integer_column(col_meta: dict[str, Any], nb_rows: int, rng: np.random.Generator) -> pd.Series
¶
Generate an integer column between minimum and maximum values.
The generated values respect the XSD integer subtype constraints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col_meta
|
dict[str, Any]
|
Column metadata containing integer bounds and datatype. |
required |
nb_rows
|
int
|
Number of rows to generate. |
required |
rng
|
Generator
|
NumPy random number generator. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Series containing randomly generated integer values. |
Notes
If zero is allowed by the bounds, at least one generated value is forced to be zero.
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
generate_string_column(col_meta: dict[str, Any], nb_rows: int, rng: np.random.Generator) -> pd.Series
¶
Generate a string column based on partition metadata.
The generated values are selected from public keys, public partitions, or randomly generated strings depending on the available metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col_meta
|
dict[str, Any]
|
Column metadata describing available partitions or keys. |
required |
nb_rows
|
int
|
Number of rows to generate. |
required |
rng
|
Generator
|
NumPy random number generator. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Series containing randomly generated string values. |
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
get_bounds(col_meta: dict[str, Any]) -> tuple[T, T]
¶
Get the lower and upper bounds from column metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
col_meta
|
dict[str, Any]
|
Column metadata containing minimum and maximum values. |
required |
Returns:
| Type | Description |
|---|---|
tuple[T, T]
|
Tuple containing the minimum and maximum bounds. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the minimum or maximum bound is missing from the metadata. |
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
mapping_series(depend_serie: pd.Series, value_map: dict[Any, Any], col_meta: dict[str, Any], rng: np.random.Generator) -> pd.Series
¶
Generate a series based on a valueMap dependency.
Each value in depend_serie is mapped according to col_meta[VALUE_MAP]. If multiple options exist, one is chosen randomly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
depend_serie
|
Series
|
Series to map from. |
required |
value_map
|
dict[Any, Any]
|
Mapping from origin column |
required |
col_meta
|
dict
|
Column metadata, must include VALUE_MAP and DATATYPE. |
required |
rng
|
Generator
|
Random number generator for choosing among multiple mapping values. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Generated series satisfying MAPPING dependency. |
Source code in csvw-eo-library/src/csvw_eo/generate_series.py
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |