Skip to content

Commit

Permalink
Fix Flake8 Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jrm5100 committed May 26, 2020
1 parent 6f2d8ae commit 56c66e4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
10 changes: 5 additions & 5 deletions clarite/internal/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _validate_skip_only(
only = [only]

if skip is not None and only is not None:
raise ValueError(f"It isn't possible to specify 'skip' and 'only' at the same time.")
raise ValueError("It isn't possible to specify 'skip' and 'only' at the same time.")
elif skip is not None and only is None:
invalid_cols = set(skip) - set(list(data))
if len(invalid_cols) > 0:
Expand Down Expand Up @@ -178,7 +178,7 @@ def validate_ewas_params(covariates, data, phenotype, survey_design_spec):

# Make sure the index of each dataset is not a multiindex and give it a consistent name
if isinstance(data.index, pd.MultiIndex):
raise ValueError(f"Data must not have a multiindex")
raise ValueError("Data must not have a multiindex")
data.index.name = "ID"

# Collects lists of regression variables
Expand All @@ -188,7 +188,7 @@ def validate_ewas_params(covariates, data, phenotype, survey_design_spec):
rv_cont = [v for v, t in types.iteritems() if t == 'continuous' and v not in covariates and v != phenotype]
# Ensure there are variables which can be regressed
if len(rv_bin + rv_cat + rv_cont) == 0:
raise ValueError(f"No variables are available to run regression on")
raise ValueError("No variables are available to run regression on")
else:
click.echo(
f"Running {len(rv_bin):,} binary, {len(rv_cat):,} categorical, and {len(rv_cont):,} continuous variables")
Expand All @@ -214,7 +214,7 @@ def validate_ewas_params(covariates, data, phenotype, survey_design_spec):
elif pheno_kind == 'categorical':
raise NotImplementedError("Categorical Phenotypes are not yet supported.")
elif pheno_kind == 'continuous':
click.echo(f"Running EWAS on a Continuous Outcome (family = Gaussian)")
click.echo("Running EWAS on a Continuous Outcome (family = Gaussian)")
elif pheno_kind == 'binary':
# Use the order according to the categorical
counts = data[phenotype].value_counts().to_dict()
Expand All @@ -226,7 +226,7 @@ def validate_ewas_params(covariates, data, phenotype, survey_design_spec):
f"\t{counts[categories[1]]:,} occurrences of '{categories[1]}' coded as 1",
fg='green'))
else:
raise ValueError(f"The phenotype's type could not be determined. Please report this error.")
raise ValueError("The phenotype's type could not be determined. Please report this error.")

# Log how many NA outcomes
na_outcome_count = data[phenotype].isna().sum()
Expand Down
4 changes: 2 additions & 2 deletions clarite/modules/modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def recode_values(data, replacement_dict,
if cells_with_changes > 0:
click.echo(f"Replaced {cells_with_changes:,} values from {len(data):,} observations in {cols_with_changes:,} variables")
else:
click.echo(f"No occurences of replaceable values were found, so nothing was replaced.")
click.echo("No occurences of replaceable values were found, so nothing was replaced.")

# Return
return result
Expand Down Expand Up @@ -897,7 +897,7 @@ def drop_extra_categories(data: pd.DataFrame,
message = f"\t{str(var)} had categories with no occurrences: {', '.join([str(c) for c in cats])}"
click.echo(message)
elif len(removed_cats) > 1:
message = f"\tMultiple categorical variables had categories with no occurrences:"
message = "\tMultiple categorical variables had categories with no occurrences:"
for var, cats in removed_cats.items():
message += f"\n\t{str(var)}: {', '.join([str(c) for c in cats])}"
click.echo(message)
Expand Down
6 changes: 3 additions & 3 deletions clarite/modules/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,12 @@ def top_results(
# Ensure corrected pvalues are present
if pvalue_name == 'pvalue_fdr' or pvalue_name == 'pvalue_bonferroni':
if pvalue_name not in list(ewas_result):
raise ValueError(f"Missing corrected pvalues in ewas result. Run clarite.analyze.add_corrected_pvalues")
raise ValueError("Missing corrected pvalues in ewas result. Run clarite.analyze.add_corrected_pvalues")
elif pvalue_name == 'pvalue':
pass
else:
raise ValueError(f"Incorrect value specified for 'pvalue_name': must be one of 'pvalue', 'pvalue_fdr',"
f" or 'pvalue_bonferroni'.")
raise ValueError("Incorrect value specified for 'pvalue_name': must be one of 'pvalue', 'pvalue_fdr',"
" or 'pvalue_bonferroni'.")

# Sort and filter data
df = ewas_result.sort_values(pvalue_name, ascending=True).head(num_rows).reset_index()
Expand Down
12 changes: 6 additions & 6 deletions clarite/modules/survey/survey_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def __init__(self,

# Load single_cluster
if single_cluster not in {'fail', 'adjust', 'average', 'certainty'}:
raise ValueError(f"if provided, 'single_cluster' must be one of "
f"'fail', 'adjust', 'average', or 'certainty'.")
raise ValueError("if provided, 'single_cluster' must be one of "
"'fail', 'adjust', 'average', or 'certainty'.")
else:
self.single_cluster = single_cluster

Expand All @@ -148,27 +148,27 @@ def __str__(self):
if self.has_strata:
result += f"\tStrata: {len(self.strata.unique())} unique values of {self.strata_name}\n"
else:
result += f"\tStrata: None\n"
result += "\tStrata: None\n"
# Clusters
if self.has_cluster:
result += f"\tCluster: {len(self.cluster.unique())} unique values of {self.cluster_name}\n"
# Nest
result += f"\t\tClusters nested in Strata: {self.nest}\n"
else:
result += f"\tCluster: None\n"
result += "\tCluster: None\n"
# FPC
if self.has_fpc:
result += f"\tFPC: {self.fpc_name}\n"
else:
result += f"\tFPC: None\n"
result += "\tFPC: None\n"
# Weights
if self.single_weight:
result += f"\tWeight: {self.weight_name}\n"
elif self.multi_weight:
result += f"\tMultiple Weights: {len(set(self.weight_names.values())):,} " \
f"unique weights associated with {len(set(self.weight_names.keys())):,} variables\n"
else:
result += f"\tWeights: None\n"
result += "\tWeights: None\n"
# single cluster
result += f"\tSingle Cluster ('Lonely PSU') Option: {self.single_cluster}"

Expand Down
1 change: 1 addition & 0 deletions clarite/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
from statsmodels import datasets


# Datasets for testing
@pytest.fixture
def plantTraits():
Expand Down

0 comments on commit 56c66e4

Please sign in to comment.