Skip to content

Commit

Permalink
update tests (use .iloc consistently)
Browse files Browse the repository at this point in the history
  • Loading branch information
ausgerechnet committed Jun 27, 2024
1 parent 65c7204 commit 01b23e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
26 changes: 13 additions & 13 deletions tests/test_frequencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def test_expected_frequencies(fixed_dataframe):

df = fq.expected_frequencies(fixed_dataframe)

assert df['E11'][0] == 1.0
assert df['E11'].iloc[0] == 1.0


def test_expected_frequencies_observed(fixed_dataframe):

df = fq.expected_frequencies(fixed_dataframe, observed=True)

assert df['O11'][0] == 10
assert df['E11'][0] == 1.0
assert df['O11'].iloc[0] == 10
assert df['E11'].iloc[0] == 1.0


def test_ucs(ucs_dataframe):
Expand All @@ -53,18 +53,18 @@ def test_ucs(ucs_dataframe):

# check observed frequencies
obs = fq.observed_frequencies(df)
assert(obs['O11'].equals(df['O11']))
assert(obs['O12'].equals(df['O12']))
assert(obs['O21'].equals(df['O21']))
assert(obs['O22'].equals(df['O22']))
assert obs['O11'].equals(df['O11'])
assert obs['O12'].equals(df['O12'])
assert obs['O21'].equals(df['O21'])
assert obs['O22'].equals(df['O22'])

# check marginals
R1 = df['O11'] + df['O12']
R2 = df['O21'] + df['O22']
C1 = df['O11'] + df['O21']
C2 = df['O12'] + df['O22']
assert((R1 + R2).equals(df['N']))
assert((C1 + C2).equals(df['N']))
assert (R1 + R2).equals(df['N'])
assert (C1 + C2).equals(df['N'])

# get expected frequencies
df['E11'] = R1 * C1 / df['N']
Expand All @@ -74,7 +74,7 @@ def test_ucs(ucs_dataframe):

# check expected frequencies
exp = fq.expected_frequencies(df)
assert(exp['E11'].equals(df['E11']))
assert(exp['E12'].equals(df['E12']))
assert(exp['E21'].equals(df['E21']))
assert(exp['E22'].equals(df['E22']))
assert exp['E11'].equals(df['E11'])
assert exp['E12'].equals(df['E12'])
assert exp['E21'].equals(df['E21'])
assert exp['E22'].equals(df['E22'])
18 changes: 9 additions & 9 deletions tests/test_measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_dice_invalid(invalid_dataframe):
def test_dice_zero(zero_dataframe):
df = zero_dataframe
df_ams = am.score(df, ['dice'])
df_ams['dice'][0] == 0.16831229174945742
assert df_ams['dice'].iloc[0] == 0.168312


##########
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_t_score_invalid(invalid_dataframe):
def test_t_score_zero(zero_dataframe):
df = zero_dataframe
df_ams = am.score(df, ['t_score'], disc=.5)
df_ams['t_score'][0] == 15.532438
assert df_ams['t_score'].iloc[0] == 15.532438


##########
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_z_score_nan(invalid_dataframe):
def test_z_score_zero(zero_dataframe):
df = zero_dataframe
df_ams = am.score(df, ['z_score'])
df_ams['z_score'].iloc[0] == 16.675431
assert df_ams['z_score'].iloc[0] == 16.675431


#################
Expand Down Expand Up @@ -295,7 +295,7 @@ def test_binomial_likelihood_brown_overflow(brown_dataframe):
def test_binomial_likelihood_zero(zero_dataframe):
df = fq.expected_frequencies(zero_dataframe, observed=True)
ams = am.binomial_likelihood(df)
assert isnan(ams[0])
assert isnan(ams.iloc[0])


#############
Expand All @@ -307,7 +307,7 @@ def test_log_ratio(fixed_dataframe):

df = fixed_dataframe
df_ams = am.score(df, ['log_ratio'], disc=.5, discounting='Hardie2014')
assert df_ams['log_ratio'][0] == 7.491853
assert df_ams['log_ratio'].iloc[0] == 7.491853


@pytest.mark.log_ratio
Expand All @@ -325,7 +325,7 @@ def test_log_ratio_zero(zero_dataframe):

df = zero_dataframe
df_ams = am.score(df, ['log_ratio'], disc=.5, discounting='Hardie2014')
assert df_ams['log_ratio'][0] == 12.03645
assert df_ams['log_ratio'].iloc[0] == 12.03645


##########################
Expand Down Expand Up @@ -408,15 +408,15 @@ def test_liddell(fixed_dataframe):

df = fixed_dataframe
df_ams = am.score(df, ['liddell'])
assert df_ams['liddell'][0] == 1
assert df_ams['liddell'].iloc[0] == 1


@pytest.mark.liddell
def test_liddell_zero(zero_dataframe):

df = fq.expected_frequencies(zero_dataframe, observed=True)
df_ams = am.score(df, ['liddell'])
assert df_ams['liddell'][0] == 0.143858
assert df_ams['liddell'].iloc[0] == 0.143858


########
Expand Down Expand Up @@ -516,4 +516,4 @@ def test_calculate_measures(zero_dataframe):
df = zero_dataframe
with pytest.deprecated_call():
df_ams = am.calculate_measures(df, ['dice'])
df_ams['dice'][0] == 0.16831229174945742
df_ams['dice'].iloc[0] == 0.16831229174945742

0 comments on commit 01b23e9

Please sign in to comment.