Skip to content

Commit b5a8737

Browse files
committed
Re-allow using cov directly
1 parent 4bc905a commit b5a8737

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

flasc/analysis/expected_power_analysis.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,10 @@ def _total_uplift_expected_power_with_standard_error(
378378
# # Synchronize any null values in the covariance back to df_bin
379379
# df_bin = _synchronize_cov_nulls_back_to_mean(df_bin=df_bin, test_cols=test_cols)
380380

381+
# Set to null any mean values associated with null variance by row/turbine
381382
df_bin = _synchronize_var_nulls_back_to_mean(df_bin=df_bin, test_cols=test_cols)
382383

383-
with pl.Config(tbl_cols=-1):
384-
print(df_bin)
385-
386-
# Synchronize the null values in the mean columns
384+
# Synchronize the null values in the mean columns across uplift pairs
387385
df_bin = _synchronize_nulls(
388386
df_bin=df_bin,
389387
sync_cols=[f"{col}_mean" for col in test_cols],

flasc/analysis/expected_power_analysis_utilities.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ def _fill_cov_with_var(
322322
n_col = f"count_{t1}_{t2}"
323323
var_1_col = f"cov_{t1}_{t1}"
324324
var_2_col = f"cov_{t2}_{t2}"
325-
# n_1_col = f"count_{t1}_{t1}"
326-
# n_2_col = f"count_{t2}_{t2}"
325+
n_1_col = f"count_{t1}_{t1}"
326+
n_2_col = f"count_{t2}_{t2}"
327327

328328
# For the rows where cov_col is null, fill the cov_col with the product of the square
329329
# root of the variances of the two test columns and the n_col with the minimum of the
@@ -334,30 +334,27 @@ def _fill_cov_with_var(
334334
if fill_all:
335335
df_cov = df_cov.with_columns(pl.lit(True).alias("null_map"))
336336

337-
with pl.Config(tbl_cols=-1):
338-
print(cov_col)
339-
print(df_cov)
340-
341337
df_cov = df_cov.with_columns(
342338
pl.when(pl.col("null_map"))
343339
.then((pl.col(var_1_col).sqrt() * pl.col(var_2_col).sqrt()))
344340
.otherwise(pl.col(cov_col))
345341
.alias(cov_col)
346342
)
347343

348-
# Leave n_col as is (number of joint points)
349-
# df_cov = df_cov.with_columns(
350-
# pl.when(pl.col("null_map"))
351-
# .then(pl.min_horizontal(n_1_col, n_2_col))
352-
# .otherwise(pl.col(n_col))
353-
# .alias(n_col)
354-
# )
344+
# Num points as the minimum between the values of the two variances
345+
df_cov = df_cov.with_columns(
346+
pl.when(pl.col("null_map"))
347+
.then(pl.min_horizontal(n_1_col, n_2_col))
348+
.otherwise(pl.col(n_col))
349+
.alias(n_col)
350+
)
355351

356-
# For any rows where n_col is 0 or null, set n_col and cov_col to null
352+
# For any rows where n_col is < 2 set n_col to null
357353
df_cov = df_cov.with_columns(
358-
pl.when(pl.col(n_col) == 0).then(None).otherwise(pl.col(n_col)).alias(n_col)
354+
pl.when(pl.col(n_col) < 2).then(None).otherwise(pl.col(n_col)).alias(n_col)
359355
)
360356

357+
# Wherever n_col is null, set cov_col to null
361358
df_cov = df_cov.with_columns(
362359
pl.when(pl.col(n_col).is_null())
363360
.then(None)

tests/expected_power_analysis_test.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def test_fill_cov_with_var_dont_fill_all():
467467
"cov_pow_001_pow_000": [1, 1],
468468
"cov_pow_001_pow_001": [4, 4],
469469
"count_pow_000_pow_000": [1, 2],
470-
"count_pow_000_pow_001": [3, 4], # Note values not updated here
470+
"count_pow_000_pow_001": [3, 2], # Note values are updated here too as min
471471
"count_pow_001_pow_000": [5, 6],
472472
"count_pow_001_pow_001": [7, 8],
473473
}
@@ -502,12 +502,18 @@ def test_fill_cov_with_var_fill_all():
502502
"ws_bin": [0, 0],
503503
"df_name": ["baseline"] * 2,
504504
"cov_pow_000_pow_000": [4, 4],
505-
"cov_pow_000_pow_001": [4, 6], # Note filled values
506-
"cov_pow_001_pow_000": [4, 6], # Note filled values
505+
"cov_pow_000_pow_001": [
506+
None,
507+
6,
508+
], # Note filled values (None because count goes below 2)
509+
"cov_pow_001_pow_000": [
510+
None,
511+
6,
512+
], # Note filled values (None because count goes below 2)
507513
"cov_pow_001_pow_001": [4, 9],
508514
"count_pow_000_pow_000": [1, 2],
509-
"count_pow_000_pow_001": [3, 4], # Note values not updated here
510-
"count_pow_001_pow_000": [5, 6], # Note values not updated here
515+
"count_pow_000_pow_001": [None, 2], # Note values updated here to minimum
516+
"count_pow_001_pow_000": [None, 2], # Note values updated here to minimum
511517
"count_pow_001_pow_001": [7, 8],
512518
}
513519
)

0 commit comments

Comments
 (0)