Reference¶
Import as from rand_engine import DataGenerator.
Generate pandas DataFrames, dict streams or files from a RandSpec.
stream_dict converts normalized microbatches to pandas records. Text columns of get_df
are string[pyarrow] with pd.NA nulls; a transformer's output keeps the dtype it returns; stream_dict records hold Python None for nulls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
random_spec
|
dict or callable
|
RandSpec mapping each column to |
required |
seed
|
int
|
Seed of this generator's own random state; the same spec, seed and size give the same output. |
None
|
Raises:
| Type | Description |
|---|---|
SpecValidationError
|
If the evaluated spec is invalid. |
Examples:
>>> from rand_engine import DataGenerator
>>> spec = {
... "user_id": {"method": "int_zfilled", "kwargs": {"length": 8}},
... "age": {"method": "integers", "kwargs": {"min": 18, "max": 80}},
... }
>>> df = DataGenerator(spec, seed=42).size(100).get_df()
>>> list(df.columns)
['user_id', 'age']
>>> bool(df["age"].between(18, 80).all())
True
Source code in rand_engine/main/data_generator.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 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 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 163 164 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 198 199 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 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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
write
property
¶
Return the batch file writer of this generator.
Chain format, mode, option or options, then call save(path):
it generates size rows and writes them to path (one file, or numFiles
parts). Nothing is written until save runs.
Returns:
| Type | Description |
|---|---|
FileBatchWriter
|
Writer whose |
Examples:
>>> import os, tempfile
>>> from rand_engine import DataGenerator
>>> spec = {"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}}}
>>> out = tempfile.mkdtemp()
>>> DataGenerator(spec, seed=42).size(10).write.format("csv").save(os.path.join(out, "ages.csv"))
>>> os.path.isfile(os.path.join(out, "ages.csv"))
True
writeStream
property
¶
Return the stream file writer of this generator.
Chain format, trigger(frequency) and option("timeout", seconds) (default
20), then call start(path): each pass writes one microbatch of size rows to
path/part-<uuid>.<ext>, sleeps frequency seconds, and repeats until
timeout seconds have passed. start blocks for that duration.
Returns:
| Type | Description |
|---|---|
FileStreamWriter
|
Writer whose |
Examples:
>>> import os, tempfile
>>> from rand_engine import DataGenerator
>>> spec = {"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}}}
>>> out = tempfile.mkdtemp()
>>> target = os.path.join(out, "ages")
>>> stream = DataGenerator(spec, seed=42).size(10).writeStream
>>> stream.format("json").trigger(frequency=0.1).option("timeout", 0.3).start(target)
>>> bool(os.listdir(target))
True
get_df()
¶
Return one DataFrame of size rows generated from the spec.
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Raises:
| Type | Description |
|---|---|
RandEngineError
|
If |
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> df = DataGenerator(RandSpecs.customers(), seed=42).size(10).get_df()
>>> len(df)
10
Source code in rand_engine/main/data_generator.py
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 | |
size(size)
¶
Set the rows per batch and return this generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int or callable
|
Rows per |
required |
Returns:
| Type | Description |
|---|---|
DataGenerator
|
This generator, for chaining. |
Examples:
>>> from rand_engine import DataGenerator
>>> spec = {"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}}}
>>> DataGenerator(spec, seed=42).size(lambda: 5).get_df().shape
(5, 1)
Source code in rand_engine/main/data_generator.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
stream_dict(min_throughput=1, max_throughput=10)
¶
Yield the rows of an endless stream as dicts, one microbatch of size rows at a time.
Each record gains a timestamp_created key (epoch seconds, 3 decimals); text columns,
dates included, are str and nulls are None. After each record the generator sleeps
1 / uniform(min_throughput, max_throughput) seconds.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_throughput
|
int
|
Lower bound of the uniform draw that sets the sleep after each record. |
1
|
max_throughput
|
int
|
Upper bound of the uniform draw that sets the sleep after each record. |
10
|
Yields:
| Type | Description |
|---|---|
dict
|
One row of the spec's columns plus |
Raises:
| Type | Description |
|---|---|
RandEngineError
|
On the first |
Examples:
>>> from itertools import islice
>>> from rand_engine import DataGenerator
>>> spec = {"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}}}
>>> stream = DataGenerator(spec, seed=42).size(5).stream_dict(min_throughput=500, max_throughput=1000)
>>> sorted(next(stream))
['age', 'timestamp_created']
Source code in rand_engine/main/data_generator.py
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 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
transformers(transformers)
¶
Set the functions that transform each generated batch, in order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transformers
|
list of callable
|
Functions |
required |
Returns:
| Type | Description |
|---|---|
DataGenerator
|
This generator, for chaining. |
Raises:
| Type | Description |
|---|---|
RandEngineError
|
When a batch is generated, if a transformer changes its row count. |
Examples:
>>> from rand_engine import DataGenerator
>>> spec = {"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}}}
>>> gen = DataGenerator(spec, seed=42).transformers([lambda df: df.assign(double=df["age"] * 2)]).size(10)
>>> list(gen.get_df().columns)
['age', 'double']
Source code in rand_engine/main/data_generator.py
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 | |
wrapped_df_generator(size, offset=0)
¶
Return a zero-argument callable that generates one batch of size rows.
The callable runs generation, embedded transformers, global transformers and modifiers, in that order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Rows in the batch. |
required |
offset
|
int
|
Row index of the batch's first row, so streamed and multi-part rows continue one index. |
0
|
Returns:
| Type | Description |
|---|---|
callable
|
|
Raises:
| Type | Description |
|---|---|
RandEngineError
|
When called, if a global transformer changes the row count. |
Examples:
>>> from rand_engine import DataGenerator
>>> spec = {"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}}}
>>> batch = DataGenerator(spec, seed=42).wrapped_df_generator(size=4)
>>> batch().shape
(4, 1)
Source code in rand_engine/main/data_generator.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
Import as from rand_engine import SparkGenerator.
Generate a PySpark DataFrame from a RandSpec.
Ordinary columns use native Spark expressions. Stateless pk and fk columns use
the shared key authority; an explicit seed applies to those key columns only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spark
|
SparkSession
|
Session that builds the DataFrame. |
required |
F
|
module
|
The |
required |
metadata
|
dict
|
RandSpec mapping each column to |
required |
Raises:
| Type | Description |
|---|---|
SpecValidationError
|
If |
Examples:
>>> from pyspark.sql import SparkSession, functions as F
>>> from rand_engine import SparkGenerator
>>> spark = SparkSession.builder.getOrCreate()
>>> spec = {"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}}}
>>> SparkGenerator(spark, F, spec).size(100).get_df().count()
100
Source code in rand_engine/main/spark_generator.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 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 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 163 164 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 198 199 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 | |
get_df()
¶
Build the Spark DataFrame of size rows generated from the metadata.
Returns:
| Type | Description |
|---|---|
DataFrame
|
One column per metadata key; the technical |
Raises:
| Type | Description |
|---|---|
RandEngineError
|
If |
Examples:
>>> from pyspark.sql import SparkSession, functions as F
>>> from rand_engine import SparkGenerator
>>> spark = SparkSession.builder.getOrCreate()
>>> spec = {"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}}}
>>> SparkGenerator(spark, F, spec).size(100).get_df().count()
100
Source code in rand_engine/main/spark_generator.py
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 179 180 181 182 183 184 185 186 187 | |
map_methods()
¶
Return the RandSpec method names mapped to their Spark generator functions.
Returns:
| Type | Description |
|---|---|
dict
|
Method name to its Spark or stateless key generator function. |
Examples:
>>> from pyspark.sql import SparkSession, functions as F
>>> from rand_engine import SparkGenerator
>>> spark = SparkSession.builder.getOrCreate()
>>> spec = {"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}}}
>>> "integers" in SparkGenerator(spark, F, spec).map_methods()
True
Source code in rand_engine/main/spark_generator.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
size(size)
¶
Set the number of rows of the DataFrame and return this generator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
int
|
Rows built by |
required |
Returns:
| Type | Description |
|---|---|
SparkGenerator
|
This generator, for chaining. |
Examples:
>>> from pyspark.sql import SparkSession, functions as F
>>> from rand_engine import SparkGenerator
>>> spark = SparkSession.builder.getOrCreate()
>>> spec = {"age": {"method": "integers", "kwargs": {"min": 18, "max": 80}}}
>>> gen = SparkGenerator(spark, F, spec).size(100)
Source code in rand_engine/main/spark_generator.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
Import as from rand_engine import RandSpecs.
Cross-compatible specification examples for DataGenerator and SparkGenerator.
All specs use the unified API with date_format parameter.
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> df = DataGenerator(RandSpecs.customers(), seed=42).size(100).get_df()
>>> list(df.columns)
['customer_id', 'age', 'city', 'total_spent', 'is_premium', 'registration_date']
>>> len(df)
100
Source code in rand_engine/examples/common_rand_specs.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 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 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 163 164 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 198 199 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 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 327 328 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 410 411 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 453 454 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 488 489 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 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
customers()
classmethod
¶
Return the customer profiles RandSpec (6 Fields).
Returns:
| Type | Description |
|---|---|
dict
|
RandSpec mapping each of the 6 fields to its method and kwargs. |
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> list(DataGenerator(RandSpecs.customers(), seed=1).size(5).get_df().columns)
['customer_id', 'age', 'city', 'total_spent', 'is_premium', 'registration_date']
Source code in rand_engine/examples/common_rand_specs.py
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 | |
devices()
classmethod
¶
Return the device inventory RandSpec (7 Fields).
Returns:
| Type | Description |
|---|---|
dict
|
RandSpec mapping each of the 7 fields to its method and kwargs. |
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> list(DataGenerator(RandSpecs.devices(), seed=1).size(5).get_df().columns)
['device_id', 'serial_number', 'firmware_version', 'uptime_hours', 'status', 'is_critical', 'last_seen']
Source code in rand_engine/examples/common_rand_specs.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 | |
employees()
classmethod
¶
Return the employee records RandSpec (8 Fields).
Returns:
| Type | Description |
|---|---|
dict
|
RandSpec mapping each of the 8 fields to its method and kwargs. |
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> list(DataGenerator(RandSpecs.employees(), seed=1).size(5).get_df().columns)
['employee_id', 'department', 'position', 'salary', 'hire_date', 'age', 'is_remote', 'performance_score']
Source code in rand_engine/examples/common_rand_specs.py
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 410 411 412 413 | |
events()
classmethod
¶
Return the system event logs RandSpec (6 Fields).
Returns:
| Type | Description |
|---|---|
dict
|
RandSpec mapping each of the 6 fields to its method and kwargs. |
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> list(DataGenerator(RandSpecs.events(), seed=1).size(5).get_df().columns)
['event_id', 'event_type', 'timestamp', 'duration_ms', 'is_error', 'severity']
Source code in rand_engine/examples/common_rand_specs.py
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | |
faker_pool(provider, locale='en_US', pool_size=100, seed=None)
classmethod
¶
Build one materialized distincts spec with a local Faker instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str
|
Faker provider method, such as |
required |
locale
|
str
|
Faker locale; an unsupported locale raises RandEngineError. |
"en_US"
|
pool_size
|
int
|
Number of values to materialize; a positive integer. |
100
|
seed
|
int
|
Seed of the Faker instance; the same seed gives the same pool. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
A |
Raises:
| Type | Description |
|---|---|
RandEngineError
|
If |
Examples:
>>> from rand_engine import RandSpecs
>>> spec = RandSpecs.faker_pool("city", pool_size=5, seed=1)
>>> spec["method"]
'distincts'
>>> len(spec["kwargs"]["distincts"])
5
Source code in rand_engine/examples/common_rand_specs.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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 90 91 92 93 94 95 96 97 98 99 100 101 | |
from_schema(schema, overrides=None)
classmethod
¶
Build a validated RandSpec from Arrow field metadata only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
Arrow schema; each field's type picks a default generation recipe. |
required |
overrides
|
dict
|
Per-field overrides keyed by field name. A |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
RandSpec with one entry per schema field, validated before return. |
Raises:
| Type | Description |
|---|---|
SpecValidationError
|
If |
Examples:
>>> import pyarrow as pa
>>> from rand_engine import DataGenerator, RandSpecs
>>> schema = pa.schema([("id", pa.int32()), ("active", pa.bool_())])
>>> spec = RandSpecs.from_schema(schema, {"id": {"kwargs": {"max": 9}}})
>>> {name: column["method"] for name, column in spec.items()}
{'id': 'integers', 'active': 'booleans'}
>>> DataGenerator(spec, seed=1).size(5).get_df().shape
(5, 2)
Source code in rand_engine/examples/common_rand_specs.py
103 104 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 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 163 164 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 | |
orders()
classmethod
¶
Return the e-commerce orders RandSpec (6 Fields).
Returns:
| Type | Description |
|---|---|
dict
|
RandSpec mapping each of the 6 fields to its method and kwargs. |
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> list(DataGenerator(RandSpecs.orders(), seed=1).size(5).get_df().columns)
['order_id', 'customer_id', 'amount', 'order_timestamp', 'status', 'payment_method']
Source code in rand_engine/examples/common_rand_specs.py
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 336 337 338 339 340 341 342 | |
products()
classmethod
¶
Return the product catalog RandSpec (7 Fields).
Returns:
| Type | Description |
|---|---|
dict
|
RandSpec mapping each of the 7 fields to its method and kwargs. |
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> list(DataGenerator(RandSpecs.products(), seed=1).size(5).get_df().columns)
['product_id', 'sku', 'name', 'price', 'stock_quantity', 'category', 'is_active']
Source code in rand_engine/examples/common_rand_specs.py
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 | |
sales()
classmethod
¶
Return the sales records RandSpec (8 Fields).
Returns:
| Type | Description |
|---|---|
dict
|
RandSpec mapping each of the 8 fields to its method and kwargs. |
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> list(DataGenerator(RandSpecs.sales(), seed=1).size(5).get_df().columns)
['transaction_id', 'sale_id', 'product_id', 'amount', 'quantity', 'sales_rep', 'sale_date', 'is_wholesale']
Source code in rand_engine/examples/common_rand_specs.py
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 | |
sensors()
classmethod
¶
Return the IoT sensor readings RandSpec (7 Fields).
Returns:
| Type | Description |
|---|---|
dict
|
RandSpec mapping each of the 7 fields to its method and kwargs. |
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> list(DataGenerator(RandSpecs.sensors(), seed=1).size(5).get_df().columns)
['sensor_id', 'device_name', 'temperature', 'humidity', 'battery_level', 'timestamp', 'is_online']
Source code in rand_engine/examples/common_rand_specs.py
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 | |
transactions()
classmethod
¶
Return the financial transactions RandSpec (7 Fields).
Returns:
| Type | Description |
|---|---|
dict
|
RandSpec mapping each of the 7 fields to its method and kwargs. |
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> list(DataGenerator(RandSpecs.transactions(), seed=1).size(5).get_df().columns)
['transaction_id', 'account_id', 'amount', 'transaction_type', 'timestamp', 'is_approved', 'fee']
Source code in rand_engine/examples/common_rand_specs.py
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 | |
users()
classmethod
¶
Return the application users RandSpec (7 Fields).
Returns:
| Type | Description |
|---|---|
dict
|
RandSpec mapping each of the 7 fields to its method and kwargs. |
Examples:
>>> from rand_engine import DataGenerator, RandSpecs
>>> list(DataGenerator(RandSpecs.users(), seed=1).size(5).get_df().columns)
['user_id', 'username', 'signup_date', 'login_count', 'subscription_plan', 'is_active', 'engagement_score']
Source code in rand_engine/examples/common_rand_specs.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |