API reference
Generator
The generator module provides generator functions for generating realistic data. These generators wrap around common data sources such as frequency tables and numeric distributions.
from_datetime_range(start_dt, end_dt, dt_format, unit, rng=None)
Generate data from a range of dates and times.
The start and end datetime must be provided either as a ISO 8601 datetime string or a NumPy datetime object.
The output format must include the same format codes as specified in the datetime
Python module for the
strftime
function.
The unit specifies the smallest unit of time that may change when generating random dates and times.
For example if D
is specified, generated dates will only differ in their days, months and years, leaving hours,
minutes and seconds unaffected.
The same applies for h
, m
and s
for hours, minutes and seconds respectively.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_dt
|
Union[str, datetime64]
|
datetime string or object for start of range |
required |
end_dt
|
Union[str, datetime64]
|
datetime string or object for end of range |
required |
dt_format
|
str
|
output format for generated datetimes |
required |
unit
|
DateTimeUnit
|
smallest unit of time that may change when generating random dates and times |
required |
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Generator
|
function returning list of random datetime strings within the specified range |
Source code in gecko/generator.py
from_frequency_table(data_source, value_column=0, freq_column=1, encoding='utf-8', delimiter=',', rng=None)
Generate data from a frequency table. The frequency table must be provided in CSV format and contain at least two columns: one containing values to generate and one containing their assigned absolute frequencies. Values generated by this function will have a distribution similar to the frequencies listed in the input file. If the value and frequency column are provided as strings, then it is automatically assumed that the CSV file has a header row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_source
|
Union[str, PathLike[str], DataFrame]
|
path to CSV file or data frame to use as frequency table |
required |
value_column
|
Union[str, int]
|
name or index of the value column |
0
|
freq_column
|
Union[str, int]
|
name or index of the frequency column |
1
|
encoding
|
str
|
character encoding of the CSV file |
'utf-8'
|
delimiter
|
str
|
column delimiter of the CSV file |
','
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Generator
|
function returning list with single series containing values generated from the input file |
Source code in gecko/generator.py
from_function(func, *args, **kwargs)
Generate data from an arbitrary function that returns a single value at a time.
Notes
This function should be used sparingly since it is not vectorized. Only use it for testing purposes or if performance is not important.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[_P, str]
|
function to invoke to generate data from |
required |
*args
|
object
|
positional arguments to pass to |
()
|
**kwargs
|
object
|
keyword arguments to pass to |
{}
|
Returns:
Type | Description |
---|---|
Generator
|
function returning list with strings generated from custom function |
Source code in gecko/generator.py
from_group(generator_lst, max_rounding_adjustment=0, rng=None)
Generate data from multiple generators. Unless explicitly specified, all generators will generate data with equal probability. Alternatively generators can be assigned fixed probabilities. The output of each generator is then shuffled. If all generators generate multiple series, then all series are shuffled the same. Due to rounding errors, it may occur that the computed amount of rows to generate for each generator does not exactly sum up to the desired amount of rows. To compensate, this generator allows the specification of a maximum amount of rows that may be added or removed to random generators to match the target amount of rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
generator_lst
|
Union[list[Generator], list[_WeightedGenerator]]
|
list of (weighted) generators |
required |
max_rounding_adjustment
|
int
|
maximum amount of rows to add or remove if the computed amount of total rows does not match the desired amount of rows |
0
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Generator
|
function returning list of random data generated using supplied generators |
Source code in gecko/generator.py
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 |
|
from_multicolumn_frequency_table(data_source, value_columns=0, freq_column=1, encoding='utf-8', delimiter=',', rng=None)
Generate data from a frequency table with multiple interdependent columns.. The frequency table must be provided in CSV format and contain at least two columns: one containing values to generate and one containing their assigned absolute frequencies. Values generated by this function will have a distribution similar to the frequencies listed in the input file. If the values and frequency column are provided as strings, then it is automatically assumed that the CSV file has a header row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_source
|
Union[str, PathLike[str], DataFrame]
|
path to CSV file or data frame to use as frequency table |
required |
value_columns
|
Union[int, str, list[int], list[str]]
|
names or indices of the value columns |
0
|
freq_column
|
Union[int, str]
|
name or index of the frequency column |
1
|
encoding
|
str
|
character encoding of the CSV file |
'utf-8'
|
delimiter
|
str
|
column delimiter of the CSV file |
','
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Generator
|
function returning list with as many series as there are value columns specified containing values generated from the input file |
Source code in gecko/generator.py
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 |
|
from_normal_distribution(mean=0, sd=1, precision=6, rng=None)
Generate data from a normal distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mean
|
float
|
mean of the normal distribution |
0
|
sd
|
float
|
standard deviation of the normal distribution |
1
|
precision
|
int
|
decimal precision of the numbers generated from the normal distribution |
6
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Generator
|
function returning list with numbers drawn from a normal distribution formatted as strings |
Source code in gecko/generator.py
from_uniform_distribution(low=0, high=1, precision=6, rng=None)
Generate data from a uniform distribution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
low
|
Union[int, float]
|
lower limit of uniform distribution (inclusive) |
0
|
high
|
Union[int, float]
|
upper limit of uniform distribution (exclusive) |
1
|
precision
|
int
|
decimal precision of the numbers generated from the uniform distribution |
6
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Generator
|
function returning list with numbers drawn from a uniform distribution formatted as strings |
Source code in gecko/generator.py
to_data_frame(generator_lst, count)
Generate data frame by using multiple generators at once. Column names must be mapped to their respective generators. A generator can be assigned to one or multiple column names, but it must always match the amount of series that the generator returns.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
generator_lst
|
_GeneratorSpec
|
list of column names to generators |
required |
count
|
int
|
amount of records to generate |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
data frame with columns and rows generated as specified |
Source code in gecko/generator.py
Mutator
The mutator module provides mutator functions for mutating data. These mutators implement common error sources such as typos based on keymaps, random edit errors and more.
mutate_data_frame(df_in, mutator_lst)
Mutate a data frame by applying several mutators on select columns. This function takes a list which contains columns and mutators that are assigned to them. A column may be assigned a single mutator, a mutator with a probability, a list of mutators where each is applied with the same probability, and a list of weighted mutators where each is applied with its assigned probability.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_in
|
DataFrame
|
data frame to mutate |
required |
mutator_lst
|
_MutatorSpec
|
list of columns with their mutator assignments |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
data frame with columns mutated as specified |
Source code in gecko/mutator.py
1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 |
|
with_categorical_values(data_source, value_column=0, encoding='utf-8', delimiter=',', rng=None)
Mutate series by replacing values with another from a list of categorical values. This mutator reads all unique values from a singular column. All values within a series will be replaced with a different random value from this column. If the value column is provided as a string, and a path to a CSV file is provided to this function, then it is automatically assumed that the CSV file has a header row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_source
|
Union[PathLike, str, DataFrame]
|
path to CSV file or data frame containing values |
required |
value_column
|
Union[str, int]
|
name or index of value column |
0
|
encoding
|
str
|
character encoding of the CSV file |
'utf-8'
|
delimiter
|
str
|
column delimiter of the CSV file |
','
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by replacing values with a different one from a limited set of permitted values |
Source code in gecko/mutator.py
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 |
|
with_cldr_keymap_file(cldr_path, charset=None, rng=None)
Mutate series by randomly introducing typos.
Potential typos are sourced from a Common Locale Data Repository (CLDR) keymap.
Any character may be replaced with one of its horizontal or vertical neighbors on a keyboard.
They may also be replaced with its upper- or lowercase variant.
It is possible for a string to not be modified if a selected character has no possible replacements.
If the charset
parameter is None
, then any character present on the keymap may be mutated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cldr_path
|
Union[PathLike, str]
|
path to CLDR keymap file |
required |
charset
|
Optional[Union[str, list[str]]]
|
character string or list of characters that may be mutated |
None
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series using a keymap |
Source code in gecko/mutator.py
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 |
|
with_datetime_offset(max_delta, unit, dt_format, prevent_wraparound=False, rng=None)
Mutate series by treating their contents it as datetime information and offsetting it by random amounts.
The delta and the unit specify which datetime field should be affected, where possible values are
d
and days
, h
and hours
, m
and minutes
, s
and seconds
.
The datetime format must include the same format codes as specified in the datetime
Python module for the
strftime
function.
By setting prevent_wraparound
to True
, this mutator will not apply a mutation if it will cause an
unrelated field to change its value, e.g. when subtracting a day from July 1st, 2001.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_delta
|
int
|
maximum amount of units to change by |
required |
unit
|
DateTimeUnit
|
affected datetime field |
required |
dt_format
|
str
|
input and output datetime format |
required |
prevent_wraparound
|
bool
|
|
False
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by applying random date and time offsets to them |
Source code in gecko/mutator.py
1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 |
|
with_delete(rng=None)
Mutate series by randomly deleting characters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by deleting random characters |
Source code in gecko/mutator.py
with_function(func, rng=None, *args, **kwargs)
Mutate series using an arbitrary function that mutates a single value at a time.
Notes
This function should be used sparingly since it is not vectorized. Only use it for testing purposes or if performance is not important.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[Concatenate[str, _P], str]
|
function to mutate values with |
required |
rng
|
Optional[Generator]
|
random number generator to use |
None
|
*args
|
object
|
positional arguments to pass to |
()
|
**kwargs
|
object
|
keyword arguments to pass to |
{}
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series using the custom function |
Source code in gecko/mutator.py
with_generator(generator, mode, join_with=' ', rng=None)
Mutate series by replacing its content by appending, prepending or replacing it with data from another generator.
A string to join generated data with when appending or prepending can be provided.
Using {}
in the join_with
parameter will cause it to be replaced by generated values.
Only the first occurrence of {}
will be replaced.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
generator
|
Generator
|
generator to source data from |
required |
mode
|
Literal['prepend', 'append', 'replace']
|
either append, prepend or replace |
required |
join_with
|
str
|
string to join present and generated data with |
' '
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series using another generator |
Source code in gecko/mutator.py
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 |
|
with_group(mutator_lst, rng=None)
Mutate series by applying multiple mutators on it. The mutators are applied in the order that they are provided in to this function. When providing a list of mutators, each row will be affected by each mutator with an equal probability. When providing a list of weighted mutators, each row will be affected by each mutator with the specified probabilities. If the probabilities do not sum up to 1, an additional mutator is added which does not modify input data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mutator_lst
|
Union[list[Mutator], list[_WeightedMutatorDef]]
|
list of mutators or weighted mutators |
required |
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series using multiple mutually exclusive mutators at once |
Source code in gecko/mutator.py
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 |
|
with_insert(charset=string.ascii_letters, rng=None)
Mutate series by inserting random characters. The characters are drawn from the provided charset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
charset
|
Union[str, list[str]]
|
character string or list of characters to sample from |
ascii_letters
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by injecting random characters |
Source code in gecko/mutator.py
with_lowercase(rng=None)
Mutate series by converting its contents to lowercase.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by converting its contents to lowercase |
Source code in gecko/mutator.py
with_missing_value(value='', rng=None)
Mutate series by replacing its values with a representative "missing" value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
str
|
"missing" value to replace select entries with |
''
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by overwriting it with a "missing" value |
Source code in gecko/mutator.py
with_noop()
Mutate series by not mutating it at all. This mutator returns the input series as-is. You might use it to leave a certain percentage of records in a series untouched.
Returns:
Type | Description |
---|---|
Mutator
|
function that does not mutate series |
Source code in gecko/mutator.py
with_permute(rng=None)
Mutate series by permuting their contents. This function ensures that rows are permuted in such a way that no value remains in the series it originated from.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by permuting their contents |
Source code in gecko/mutator.py
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 |
|
with_phonetic_replacement_table(data_source, source_column=0, target_column=1, flags_column=2, encoding='utf-8', delimiter=',', rng=None)
Mutate series by randomly replacing character sequences with others that sound similar.
The rules for similar-sounding character sequences are sourced from a table.
This table must have at least three columns: a source, target and a flag column.
A source pattern is mapped to its target under the rules imposed by the provided flags.
These flags determine where such a replacement can take place within a string.
If no flags are defined, it is implied that this replacement can take place anywhere in a string.
Conversely, if ^
, $
, _
, or any combination of the three are set, it implies that a replacement
can only occur at the start, end or in the middle of a string.
If the source, target and flags column are provided as strings, and if a path to a CSV file is
provided to this function, then it is automatically assumed that the CSV file has a header row.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_source
|
Union[PathLike, str, DataFrame]
|
path to CSV file or data frame containing phonetic replacement rules |
required |
source_column
|
Union[int, str]
|
name or index of source column |
0
|
target_column
|
Union[int, str]
|
name or index of target column |
1
|
flags_column
|
Union[int, str]
|
name or index of flag column |
2
|
encoding
|
str
|
character encoding of the CSV file |
'utf-8'
|
delimiter
|
str
|
column delimiter of the CSV file |
','
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series using phonetic rules sourced from a table |
Source code in gecko/mutator.py
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 |
|
with_regex_replacement_table(data_source, pattern_column='pattern', flags_column=None, encoding='utf-8', delimiter=',', rng=None)
Mutate series by performing regex-based substitutions sourced from a table. This table must contain a column with the regex patterns to look for and columns for each capture group to look up substitutions. When using regular capture groups, the columns must be numbered starting with 1. When using named capture groups, the columns must be named after the capture groups they are supposed to substitute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_source
|
Union[PathLike, str, DataFrame]
|
path to CSV file or data frame containing regex-based substitutions |
required |
pattern_column
|
str
|
name of regex pattern column |
'pattern'
|
flags_column
|
Optional[str]
|
name of regex flag column |
None
|
encoding
|
str
|
character encoding of the CSV file |
'utf-8'
|
delimiter
|
str
|
column delimiter of the CSV file |
','
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by performing regex-based substitutions |
Source code in gecko/mutator.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 |
|
with_repeat(join_with=' ', rng=None)
Mutate series by repeating its contents. By default, selected entries will be duplicated and separated by a whitespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
join_with
|
str
|
joining character to use, space by default |
' '
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by repeating its contents |
Source code in gecko/mutator.py
with_replacement_table(data_source, source_column=0, target_column=1, inline=False, reverse=False, encoding='utf-8', delimiter=',', rng=None)
Mutate series by randomly substituting character sequences from a replacement table. The table must have at least two columns: a source and a target value column. A source value may have multiple target values that it can map to. Strings that do not contain any possible source values are not mutated. It is possible for a string to not be modified if no target value could be picked for its assigned source value. This can only happen if a source value is mapped to multiple target values. In this case, each target value will be independently selected or not. If the source and target column are provided as strings, and a path to a CSV file is provided to this function, then it is automatically assumed that the CSV file has a header row. The mutator will favor less common replacements over more common ones.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_source
|
Union[PathLike, str, DataFrame]
|
path to CSV file or data frame containing replacement table |
required |
source_column
|
Union[str, int]
|
name or index of the source column |
0
|
target_column
|
Union[str, int]
|
name or index of the target column |
1
|
inline
|
bool
|
whether to perform replacements inline |
False
|
reverse
|
bool
|
whether to allow replacements from target to source column |
False
|
encoding
|
str
|
character encoding of the CSV file |
'utf-8'
|
delimiter
|
str
|
column delimiter of the CSV file |
','
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series according to a replacement table |
Source code in gecko/mutator.py
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 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 |
|
with_substitute(charset=string.ascii_letters, rng=None)
Mutate data by replacing single characters with a new one. The characters are drawn from the provided charset.
Notes
It is possible for a character to be replaced by itself.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
charset
|
Union[str, list[str]]
|
character string or list of characters to sample from |
ascii_letters
|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by substituting random characters |
Source code in gecko/mutator.py
with_transpose(rng=None)
Mutate series by randomly swapping neighboring characters.
Notes
It is possible for the same two neighboring characters to be swapped.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by swapping adjacent characters |
Source code in gecko/mutator.py
with_uppercase(rng=None)
Mutate series by converting its contents to uppercase.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rng
|
Optional[Generator]
|
random number generator to use |
None
|
Returns:
Type | Description |
---|---|
Mutator
|
function that mutates series by converting its contents to uppercase |