Skip to content

Commit 0206e46

Browse files
Jacobluke-JAnns98
authored andcommitted
Add new tests, modify warnings
1 parent 04377cd commit 0206e46

File tree

4 files changed

+59
-22
lines changed

4 files changed

+59
-22
lines changed

dabest/_dabest_object.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# %% ../nbs/API/dabest_object.ipynb 5
99
# Import standard data science libraries
10+
import warnings
1011
from numpy import array, repeat, random, issubdtype, number
1112
import numpy as np
1213
import pandas as pd
@@ -62,7 +63,6 @@ def __init__(
6263

6364
# Check if there is NaN under any of the paired settings
6465
if self.__is_paired and self.__output_data.isnull().values.any():
65-
import warnings
6666
warn1 = f"NaN values detected under paired setting and removed,"
6767
warn2 = f" please check your data."
6868
warnings.warn(warn1 + warn2)
@@ -500,7 +500,10 @@ def _check_errors(self, x, y, idx, experiment, experiment_label, x1_level):
500500
if x is None:
501501
error_msg = "If `delta2` is True. `x` parameter cannot be None. String or list expected"
502502
raise ValueError(error_msg)
503-
503+
504+
if self.__proportional:
505+
mes1 = "Only mean_diff is supported for proportional data when `delta2` is True"
506+
warnings.warn(message=mes1, category=UserWarning)
504507

505508
# idx should not be specified
506509
if idx:
@@ -578,8 +581,6 @@ def _get_plot_data(self, x, y, all_plot_groups):
578581
"""
579582
# Check if there is NaN under any of the paired settings
580583
if self.__is_paired is not None and self.__output_data.isnull().values.any():
581-
print("Nan")
582-
import warnings
583584
warn1 = f"NaN values detected under paired setting and removed,"
584585
warn2 = f" please check your data."
585586
warnings.warn(warn1 + warn2)
@@ -631,7 +632,6 @@ def _get_plot_data(self, x, y, all_plot_groups):
631632

632633
# Check if there is NaN under any of the paired settings
633634
if self.__is_paired is not None and self.__output_data.isnull().values.any():
634-
import warnings
635635
warn1 = f"NaN values detected under paired setting and removed,"
636636
warn2 = f" please check your data."
637637
warnings.warn(warn1 + warn2)

dabest/_effsize_objects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ def _check_errors(self, control, test):
257257
raise ValueError(err1)
258258

259259
if self.__proportional and self.__effect_size not in ["mean_diff", "cohens_h"]:
260-
err1 = "`proportional` is True; therefore effect size other than mean_diff and cohens_h is not defined."
260+
err1 = "`proportional` is True; therefore effect size other than mean_diff and cohens_h is not defined." + \
261+
"If you are calculating deltas' g, it's the same as delta-delta when `proportional` is True"
261262
raise ValueError(err1)
262263

263264
if self.__proportional and (

nbs/tests/mpl_image_tests/test_07_delta-delta_plots.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def create_demo_dataset_delta(seed=9999, N=20):
2626
y = norm.rvs(loc=3, scale=0.4, size=N*4)
2727
y[N:2*N] = y[N:2*N]+1
2828
y[2*N:3*N] = y[2*N:3*N]-0.5
29+
ind = np.random.binomial(1, 0.5, size=N*4)
30+
ind[N:2*N] = np.random.binomial(1, 0.2, size=N)
31+
ind[2*N:3*N] = np.random.binomial(1, 0.7, size=N)
2932

3033
# Add drug column
3134
t1 = np.repeat('Placebo', N*2).tolist()
@@ -54,10 +57,11 @@ def create_demo_dataset_delta(seed=9999, N=20):
5457

5558
# Combine all columns into a DataFrame.
5659
df = pd.DataFrame({'ID' : id_col,
57-
'Rep' : rep,
60+
'Rep' : rep,
5861
'Genotype' : genotype,
59-
'Treatment': treatment,
60-
'Y' : y
62+
'Treatment' : treatment,
63+
'Y' : y,
64+
'Cat' :ind
6165
})
6266
return df
6367

@@ -81,6 +85,34 @@ def create_demo_dataset_delta(seed=9999, N=20):
8185
experiment = "Genotype",
8286
paired="sequential", id_col="ID")
8387

88+
unpaired_prop = load(data = df, proportional=True,
89+
# id_col="index", paired='baseline',
90+
x = ["Genotype", "Genotype"],
91+
y = "Cat", delta2=True,
92+
experiment="Treatment",)
93+
94+
unpaired_specified_prop = load(data = df, proportional=True,
95+
# id_col="index", paired='baseline',
96+
x = ["Genotype", "Genotype"],
97+
y = "Cat", delta2=True,
98+
experiment="Treatment",
99+
experiment_label = ["Drug", "Placebo"],
100+
x1_level = ["M", "W"])
101+
102+
paired_prop = load(data = df, proportional=True,
103+
id_col="ID", paired='baseline',
104+
x = ["Genotype", "Genotype"],
105+
y = "Cat", delta2=True,
106+
experiment="Treatment",)
107+
108+
paired_specified_prop = load(data = df, proportional=True,
109+
id_col="ID", paired='baseline',
110+
x = ["Genotype", "Genotype"],
111+
y = "Cat", delta2=True,
112+
experiment="Treatment",
113+
experiment_label = ["Drug", "Placebo"],
114+
x1_level = ["M", "W"])
115+
84116

85117
@pytest.mark.mpl_image_compare(tolerance=8)
86118
def test_47_cummings_unpaired_delta_delta_meandiff():
@@ -164,4 +196,20 @@ def test_72_sequential_delta_g():
164196

165197
@pytest.mark.mpl_image_compare(tolerance=8)
166198
def test_73_baseline_delta_g():
167-
return baseline.mean_diff.plot();
199+
return baseline.mean_diff.plot();
200+
201+
@pytest.mark.mpl_image_compare(tolerance=8)
202+
def test_74_unpaired_prop_delta2():
203+
return unpaired_prop.mean_diff.plot()
204+
205+
@pytest.mark.mpl_image_compare(tolerance=8)
206+
def test_75_unpaired_specified_prop_delta2():
207+
return unpaired_specified_prop.mean_diff.plot()
208+
209+
@pytest.mark.mpl_image_compare(tolerance=8)
210+
def test_76_paired_prop_delta2():
211+
return paired_prop.mean_diff.plot()
212+
213+
@pytest.mark.mpl_image_compare(tolerance=8)
214+
def test_77_paired_specified_prop_delta2():
215+
return paired_specified_prop.mean_diff.plot()

nbs/tests/test_load_errors.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,6 @@ def test_wrong_params_combinations():
3535

3636
assert error_msg in str(excinfo.value)
3737

38-
error_msg = "`proportional` and `delta2` cannot be True at the same time."
39-
with pytest.raises(ValueError) as excinfo:
40-
my_data = load(
41-
dummy_df,
42-
x=["Control 1", "Control 1"],
43-
y="Test 1",
44-
delta2=True,
45-
proportional=True
46-
)
47-
48-
assert error_msg in str(excinfo.value)
49-
5038
error_msg = "`idx` should not be specified when `delta2` is True.".format(N)
5139
with pytest.raises(ValueError) as excinfo:
5240
my_data = load(

0 commit comments

Comments
 (0)