tea_tasting.experiment
#
Experiment and experiment result.
Experiment(metrics=None, variant='variant', **kw_metrics)
#
Bases: ReprMixin
Experiment definition: metrics and variant column.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metrics
|
dict[str, MetricBase[Any]] | None
|
Dictionary of metrics with metric names as keys. |
None
|
variant
|
str
|
Variant column name. |
'variant'
|
kw_metrics
|
MetricBase[Any]
|
Metrics with metric names as parameter names. |
{}
|
Examples:
>>> import tea_tasting as tt
>>> experiment = tt.Experiment(
... sessions_per_user=tt.Mean("sessions"),
... orders_per_session=tt.RatioOfMeans("orders", "sessions"),
... orders_per_user=tt.Mean("orders"),
... revenue_per_user=tt.Mean("revenue"),
... )
>>> data = tt.make_users_data(seed=42)
>>> result = experiment.analyze(data)
>>> result
metric control treatment rel_effect_size rel_effect_size_ci pvalue
sessions_per_user 2.00 1.98 -0.66% [-3.7%, 2.5%] 0.674
orders_per_session 0.266 0.289 8.8% [-0.89%, 19%] 0.0762
orders_per_user 0.530 0.573 8.0% [-2.0%, 19%] 0.118
revenue_per_user 5.24 5.73 9.3% [-2.4%, 22%] 0.123
Using the first argument metrics
which accepts metrics in a form of dictionary:
>>> experiment = tt.Experiment({
... "sessions per user": tt.Mean("sessions"),
... "orders per session": tt.RatioOfMeans("orders", "sessions"),
... "orders per user": tt.Mean("orders"),
... "revenue per user": tt.Mean("revenue"),
... })
>>> data = tt.make_users_data(seed=42)
>>> result = experiment.analyze(data)
>>> result
metric control treatment rel_effect_size rel_effect_size_ci pvalue
sessions per user 2.00 1.98 -0.66% [-3.7%, 2.5%] 0.674
orders per session 0.266 0.289 8.8% [-0.89%, 19%] 0.0762
orders per user 0.530 0.573 8.0% [-2.0%, 19%] 0.118
revenue per user 5.24 5.73 9.3% [-2.4%, 22%] 0.123
Power analysis:
>>> data = tt.make_users_data(
... seed=42,
... sessions_uplift=0,
... orders_uplift=0,
... revenue_uplift=0,
... covariates=True,
... )
>>> with tt.config_context(n_obs=(10_000, 20_000)):
... experiment = tt.Experiment(
... sessions_per_user=tt.Mean("sessions", "sessions_covariate"),
... orders_per_session=tt.RatioOfMeans(
... numer="orders",
... denom="sessions",
... numer_covariate="orders_covariate",
... denom_covariate="sessions_covariate",
... ),
... orders_per_user=tt.Mean("orders", "orders_covariate"),
... revenue_per_user=tt.Mean("revenue", "revenue_covariate"),
... )
>>> power_result = experiment.solve_power(data)
>>> power_result
metric power effect_size rel_effect_size n_obs
sessions_per_user 80% 0.0458 2.3% 10000
sessions_per_user 80% 0.0324 1.6% 20000
orders_per_session 80% 0.0177 6.8% 10000
orders_per_session 80% 0.0125 4.8% 20000
orders_per_user 80% 0.0374 7.2% 10000
orders_per_user 80% 0.0264 5.1% 20000
revenue_per_user 80% 0.488 9.2% 10000
revenue_per_user 80% 0.345 6.5% 20000
Source code in src/tea_tasting/experiment.py
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 |
|
analyze(data, control=None, *, all_variants=False)
#
Analyze the experiment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
IntoFrame | Table
|
Experimental data. |
required |
control
|
object
|
Control variant. If |
None
|
all_variants
|
bool
|
If |
False
|
Returns:
Type | Description |
---|---|
ExperimentResult | ExperimentResults
|
Experiment result. |
Source code in src/tea_tasting/experiment.py
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 |
|
simulate(data, n_simulations=10000, *, seed=None, ratio=1, treat=None, map_=map, progress=None)
#
Simulate the experiment analysis multiple times.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
IntoFrame | Table | DataGenerator
|
Experimental data or a callable that generates the data. |
required |
n_simulations
|
int
|
Number of simulations. |
10000
|
seed
|
int | Generator | SeedSequence | None
|
Random seed. |
None
|
ratio
|
float | int
|
Ratio of the number of users in treatment relative to control. |
1
|
treat
|
Callable[[Table], Table] | None
|
Treatment function that takes a PyArrow Table as an input and returns an updated PyArrow Table. |
None
|
map_
|
MapLike[Any]
|
Map-like function to run simulations. |
map
|
progress
|
ProgressFn[Any] | type[Iterable[Any]] | None
|
tqdm-like class or function to show the progress of simulations. |
None
|
Returns:
Type | Description |
---|---|
SimulationResults
|
Simulation results. |
Source code in src/tea_tasting/experiment.py
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 |
|
solve_power(data, parameter='rel_effect_size')
#
Solve for a parameter of the power of a test.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
IntoFrame | Table
|
Sample data. |
required |
parameter
|
Literal['power', 'effect_size', 'rel_effect_size', 'n_obs']
|
Parameter name. |
'rel_effect_size'
|
Returns:
Type | Description |
---|---|
ExperimentPowerResult
|
Power analysis result. |
Source code in src/tea_tasting/experiment.py
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 |
|
ExperimentPowerResult
#
Bases: DictsReprMixin
, UserDict[str, MetricPowerResults[Any]]
Result of the analysis of power in a experiment.
to_arrow()
#
Convert the object to a PyArrow Table.
Source code in src/tea_tasting/utils.py
303 304 305 306 |
|
to_dicts()
#
Convert the result to a sequence of dictionaries.
Source code in src/tea_tasting/experiment.py
152 153 154 155 156 157 158 |
|
to_html(keys=None, formatter=get_and_format_num, *, max_rows=None, indent=None)
#
Convert the object to HTML.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
indent
|
str | None
|
Whitespace to insert for each indentation level. If |
None
|
Returns:
Type | Description |
---|---|
str
|
A table with results rendered as HTML. |
Source code in src/tea_tasting/utils.py
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 |
|
to_pandas()
#
Convert the object to a Pandas DataFrame.
Source code in src/tea_tasting/utils.py
308 309 310 311 312 |
|
to_polars()
#
Convert the object to a Polars DataFrame.
Source code in src/tea_tasting/utils.py
314 315 316 317 318 |
|
to_pretty_dicts(keys=None, formatter=get_and_format_num, *, max_rows=None)
#
Convert the object to a list of dictionaries with formatted values.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, str]]
|
List of dictionaries with formatted values. |
Source code in src/tea_tasting/utils.py
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 |
|
to_string(keys=None, formatter=get_and_format_num, *, max_rows=None)
#
Convert the object to a string.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
Returns:
Type | Description |
---|---|
str
|
A table with results rendered as string. |
Source code in src/tea_tasting/utils.py
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 |
|
with_defaults(*, keys=None, max_rows=None)
#
Copies the object and sets the new default parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
New default |
None
|
max_rows
|
int | None
|
New default |
None
|
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default keys. |
Source code in src/tea_tasting/utils.py
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 |
|
with_keys(keys)
#
Copies the object and sets the new default keys
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str]
|
New default |
required |
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default |
Source code in src/tea_tasting/utils.py
516 517 518 519 520 521 522 523 524 525 526 |
|
with_max_rows(max_rows)
#
Copies the object and sets the new default max_rows
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_rows
|
int
|
New default |
required |
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default |
Source code in src/tea_tasting/utils.py
529 530 531 532 533 534 535 536 537 538 539 |
|
ExperimentResult
#
Bases: DictsReprMixin
, UserDict[str, MetricResult]
Experiment result for a pair of variants.
to_arrow()
#
Convert the object to a PyArrow Table.
Source code in src/tea_tasting/utils.py
303 304 305 306 |
|
to_dicts()
#
Convert the result to a sequence of dictionaries.
Examples:
>>> import pprint
>>> import tea_tasting as tt
>>> experiment = tt.Experiment(
... orders_per_user=tt.Mean("orders"),
... revenue_per_user=tt.Mean("revenue"),
... )
>>> data = tt.make_users_data(seed=42)
>>> result = experiment.analyze(data)
>>> pprint.pprint(result.to_dicts())
({'control': 0.5304003954522986,
'effect_size': 0.04269014577177832,
'effect_size_ci_lower': -0.010800201598205515,
'effect_size_ci_upper': 0.09618049314176216,
'metric': 'orders_per_user',
'pvalue': np.float64(0.11773177998716214),
'rel_effect_size': 0.08048664016431273,
'rel_effect_size_ci_lower': -0.019515294044061937,
'rel_effect_size_ci_upper': 0.1906880061278886,
'statistic': 1.5647028839586707,
'treatment': 0.5730905412240769},
{'control': 5.241028175976273,
'effect_size': 0.4890831037404775,
'effect_size_ci_lower': -0.13261881482742033,
'effect_size_ci_upper': 1.1107850223083753,
'metric': 'revenue_per_user',
'pvalue': np.float64(0.1230698855425058),
'rel_effect_size': 0.09331815958981626,
'rel_effect_size_ci_lower': -0.02373770894855798,
'rel_effect_size_ci_upper': 0.22440926894909308,
'statistic': 1.5423440700784083,
'treatment': 5.73011127971675})
Source code in src/tea_tasting/experiment.py
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 |
|
to_html(keys=None, formatter=get_and_format_num, *, max_rows=None, indent=None)
#
Convert the object to HTML.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
indent
|
str | None
|
Whitespace to insert for each indentation level. If |
None
|
Returns:
Type | Description |
---|---|
str
|
A table with results rendered as HTML. |
Source code in src/tea_tasting/utils.py
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 |
|
to_pandas()
#
Convert the object to a Pandas DataFrame.
Source code in src/tea_tasting/utils.py
308 309 310 311 312 |
|
to_polars()
#
Convert the object to a Polars DataFrame.
Source code in src/tea_tasting/utils.py
314 315 316 317 318 |
|
to_pretty_dicts(keys=None, formatter=get_and_format_num, *, max_rows=None)
#
Convert the object to a list of dictionaries with formatted values.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, str]]
|
List of dictionaries with formatted values. |
Source code in src/tea_tasting/utils.py
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 |
|
to_string(keys=None, formatter=get_and_format_num, *, max_rows=None)
#
Convert the object to a string.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
Returns:
Type | Description |
---|---|
str
|
A table with results rendered as string. |
Source code in src/tea_tasting/utils.py
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 |
|
with_defaults(*, keys=None, max_rows=None)
#
Copies the object and sets the new default parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
New default |
None
|
max_rows
|
int | None
|
New default |
None
|
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default keys. |
Source code in src/tea_tasting/utils.py
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 |
|
with_keys(keys)
#
Copies the object and sets the new default keys
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str]
|
New default |
required |
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default |
Source code in src/tea_tasting/utils.py
516 517 518 519 520 521 522 523 524 525 526 |
|
with_max_rows(max_rows)
#
Copies the object and sets the new default max_rows
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_rows
|
int
|
New default |
required |
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default |
Source code in src/tea_tasting/utils.py
529 530 531 532 533 534 535 536 537 538 539 |
|
ExperimentResults
#
Bases: DictsReprMixin
, UserDict[tuple[object, object], ExperimentResult]
Experiment results for multiple pairs of variants.
to_arrow()
#
Convert the object to a PyArrow Table.
Source code in src/tea_tasting/utils.py
303 304 305 306 |
|
to_dicts()
#
Convert the results to a sequence of dictionaries.
Source code in src/tea_tasting/experiment.py
111 112 113 114 115 116 117 118 |
|
to_html(keys=None, formatter=get_and_format_num, *, max_rows=None, indent=None)
#
Convert the object to HTML.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
indent
|
str | None
|
Whitespace to insert for each indentation level. If |
None
|
Returns:
Type | Description |
---|---|
str
|
A table with results rendered as HTML. |
Source code in src/tea_tasting/utils.py
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 |
|
to_pandas()
#
Convert the object to a Pandas DataFrame.
Source code in src/tea_tasting/utils.py
308 309 310 311 312 |
|
to_polars()
#
Convert the object to a Polars DataFrame.
Source code in src/tea_tasting/utils.py
314 315 316 317 318 |
|
to_pretty_dicts(keys=None, formatter=get_and_format_num, *, max_rows=None)
#
Convert the object to a list of dictionaries with formatted values.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, str]]
|
List of dictionaries with formatted values. |
Source code in src/tea_tasting/utils.py
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 |
|
to_string(keys=None, formatter=get_and_format_num, *, max_rows=None)
#
Convert the object to a string.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
Returns:
Type | Description |
---|---|
str
|
A table with results rendered as string. |
Source code in src/tea_tasting/utils.py
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 |
|
with_defaults(*, keys=None, max_rows=None)
#
Copies the object and sets the new default parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
New default |
None
|
max_rows
|
int | None
|
New default |
None
|
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default keys. |
Source code in src/tea_tasting/utils.py
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 |
|
with_keys(keys)
#
Copies the object and sets the new default keys
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str]
|
New default |
required |
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default |
Source code in src/tea_tasting/utils.py
516 517 518 519 520 521 522 523 524 525 526 |
|
with_max_rows(max_rows)
#
Copies the object and sets the new default max_rows
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_rows
|
int
|
New default |
required |
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default |
Source code in src/tea_tasting/utils.py
529 530 531 532 533 534 535 536 537 538 539 |
|
SimulationResults
#
Bases: DictsReprMixin
, UserList[ExperimentResult]
Simulation results.
Simulations are not enumerated for better performance.
to_arrow()
#
Convert the object to a PyArrow Table.
Source code in src/tea_tasting/utils.py
303 304 305 306 |
|
to_dicts()
#
Convert the results to a sequence of dictionaries.
Source code in src/tea_tasting/experiment.py
136 137 138 139 140 141 142 |
|
to_html(keys=None, formatter=get_and_format_num, *, max_rows=None, indent=None)
#
Convert the object to HTML.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
indent
|
str | None
|
Whitespace to insert for each indentation level. If |
None
|
Returns:
Type | Description |
---|---|
str
|
A table with results rendered as HTML. |
Source code in src/tea_tasting/utils.py
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 |
|
to_pandas()
#
Convert the object to a Pandas DataFrame.
Source code in src/tea_tasting/utils.py
308 309 310 311 312 |
|
to_polars()
#
Convert the object to a Polars DataFrame.
Source code in src/tea_tasting/utils.py
314 315 316 317 318 |
|
to_pretty_dicts(keys=None, formatter=get_and_format_num, *, max_rows=None)
#
Convert the object to a list of dictionaries with formatted values.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, str]]
|
List of dictionaries with formatted values. |
Source code in src/tea_tasting/utils.py
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 |
|
to_string(keys=None, formatter=get_and_format_num, *, max_rows=None)
#
Convert the object to a string.
Default formatting rules:
- If a name starts with
"rel_"
or equals to"power"
consider it a percentage value. Round percentage values to 2 significant digits, multiply by100
and add"%"
. - Round other values to 3 significant values.
- If value is less than
0.001
or is greater than or equal to10_000_000
, format it in exponential presentation. - If a name ends with
"_ci"
, consider it a confidence interval. Look up for attributes"{name}_lower"
and"{name}_upper"
, and format the interval as"[{lower_bound}, {upper_bound}]"
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
Keys to convert. If a key is not defined in the dictionary
it's assumed to be |
None
|
formatter
|
Callable[[dict[str, object], str], str]
|
Custom formatter function. It should accept a dictionary of metric result attributes and an attribute name, and return a formatted attribute value. |
get_and_format_num
|
max_rows
|
int | None
|
Maximum number of rows to convert.
If |
None
|
Returns:
Type | Description |
---|---|
str
|
A table with results rendered as string. |
Source code in src/tea_tasting/utils.py
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 |
|
with_defaults(*, keys=None, max_rows=None)
#
Copies the object and sets the new default parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str] | None
|
New default |
None
|
max_rows
|
int | None
|
New default |
None
|
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default keys. |
Source code in src/tea_tasting/utils.py
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 |
|
with_keys(keys)
#
Copies the object and sets the new default keys
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keys
|
Sequence[str]
|
New default |
required |
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default |
Source code in src/tea_tasting/utils.py
516 517 518 519 520 521 522 523 524 525 526 |
|
with_max_rows(max_rows)
#
Copies the object and sets the new default max_rows
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_rows
|
int
|
New default |
required |
Returns:
Type | Description |
---|---|
DictsReprMixinT
|
A copy of the object with the new default |
Source code in src/tea_tasting/utils.py
529 530 531 532 533 534 535 536 537 538 539 |
|