Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove calls to .format #3325

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/scanpy/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@
possible_types_str = types.__name__
else:
type_names = [t.__name__ for t in types]
possible_types_str = "{} or {}".format(
", ".join(type_names[:-1]), type_names[-1]
)
possible_types_str = f"{', '.join(type_names[:-1])} or {type_names[-1]}"

Check warning on line 85 in src/scanpy/_settings.py

View check run for this annotation

Codecov / codecov/patch

src/scanpy/_settings.py#L85

Added line #L85 was not covered by tests
raise TypeError(f"{varname} must be of type {possible_types_str}")


Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/external/exporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@


def _frac_to_hex(frac):
rgb = tuple(np.array(np.array(plt.cm.jet(frac)[:3]) * 255, dtype=int))
return "#{:02x}{:02x}{:02x}".format(*rgb)
r, g, b = tuple(np.array(np.array(plt.cm.jet(frac)[:3]) * 255, dtype=int))
return f"#{r:02x}{g:02x}{b:02x}"

Check warning on line 349 in src/scanpy/external/exporting.py

View check run for this annotation

Codecov / codecov/patch

src/scanpy/external/exporting.py#L348-L349

Added lines #L348 - L349 were not covered by tests


def _get_color_stats_genes(color_stats, E, gene_list):
Expand Down
4 changes: 2 additions & 2 deletions src/scanpy/external/tl/_phenograph.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@
comm_key = (
f"pheno_{clustering_algo}" if clustering_algo in ["louvain", "leiden"] else ""
)
ig_key = "pheno_{}_ig".format("jaccard" if jaccard else "gaussian")
q_key = "pheno_{}_q".format("jaccard" if jaccard else "gaussian")
ig_key = f"pheno_{'jaccard' if jaccard else 'gaussian'}_ig"
q_key = f"pheno_{'jaccard' if jaccard else 'gaussian'}_q"

Check warning on line 248 in src/scanpy/external/tl/_phenograph.py

View check run for this annotation

Codecov / codecov/patch

src/scanpy/external/tl/_phenograph.py#L247-L248

Added lines #L247 - L248 were not covered by tests

communities, graph, Q = phenograph.cluster(
data=data,
Expand Down
8 changes: 4 additions & 4 deletions src/scanpy/plotting/_tools/paga.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,11 @@
and isinstance(node_labels, str)
and node_labels != adata.uns["paga"]["groups"]
):
raise ValueError(
"Provide a list of group labels for the PAGA groups {}, not {}.".format(
adata.uns["paga"]["groups"], node_labels
)
msg = (

Check warning on line 704 in src/scanpy/plotting/_tools/paga.py

View check run for this annotation

Codecov / codecov/patch

src/scanpy/plotting/_tools/paga.py#L704

Added line #L704 was not covered by tests
"Provide a list of group labels for the PAGA groups "
f"{adata.uns['paga']['groups']}, not {node_labels}."
)
raise ValueError(msg)

Check warning on line 708 in src/scanpy/plotting/_tools/paga.py

View check run for this annotation

Codecov / codecov/patch

src/scanpy/plotting/_tools/paga.py#L708

Added line #L708 was not covered by tests
groups_key = adata.uns["paga"]["groups"]
if node_labels is None:
node_labels = adata.obs[groups_key].cat.categories
Expand Down
27 changes: 11 additions & 16 deletions src/scanpy/preprocessing/_qc.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,28 +193,23 @@ def describe_var(
var_metrics = pd.DataFrame(index=adata.var_names)
if issparse(X):
# Current memory bottleneck for csr matrices:
var_metrics["n_cells_by_{expr_type}"] = X.getnnz(axis=0)
var_metrics["mean_{expr_type}"] = mean_variance_axis(X, axis=0)[0]
var_metrics[f"n_cells_by_{expr_type}"] = X.getnnz(axis=0)
var_metrics[f"mean_{expr_type}"] = mean_variance_axis(X, axis=0)[0]
else:
var_metrics["n_cells_by_{expr_type}"] = np.count_nonzero(X, axis=0)
var_metrics["mean_{expr_type}"] = X.mean(axis=0)
var_metrics[f"n_cells_by_{expr_type}"] = np.count_nonzero(X, axis=0)
var_metrics[f"mean_{expr_type}"] = X.mean(axis=0)
if log1p:
var_metrics["log1p_mean_{expr_type}"] = np.log1p(
var_metrics["mean_{expr_type}"]
var_metrics[f"log1p_mean_{expr_type}"] = np.log1p(
var_metrics[f"mean_{expr_type}"]
)
var_metrics["pct_dropout_by_{expr_type}"] = (
1 - var_metrics["n_cells_by_{expr_type}"] / X.shape[0]
var_metrics[f"pct_dropout_by_{expr_type}"] = (
1 - var_metrics[f"n_cells_by_{expr_type}"] / X.shape[0]
) * 100
var_metrics["total_{expr_type}"] = np.ravel(X.sum(axis=0))
var_metrics[f"total_{expr_type}"] = np.ravel(X.sum(axis=0))
if log1p:
var_metrics["log1p_total_{expr_type}"] = np.log1p(
var_metrics["total_{expr_type}"]
var_metrics[f"log1p_total_{expr_type}"] = np.log1p(
var_metrics[f"total_{expr_type}"]
)
# Relabel
new_colnames = []
for col in var_metrics.columns:
new_colnames.append(col.format(**locals()))
var_metrics.columns = new_colnames
if inplace:
adata.var[var_metrics.columns] = var_metrics
else:
Expand Down
7 changes: 4 additions & 3 deletions src/scanpy/tools/_rank_genes_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,11 @@ def __init__(
)

if len(invalid_groups_selected) > 0:
raise ValueError(
"Could not calculate statistics for groups {} since they only "
"contain one sample.".format(", ".join(invalid_groups_selected))
msg = (
f"Could not calculate statistics for groups {', '.join(invalid_groups_selected)} "
"since they only contain one sample."
)
raise ValueError(msg)

adata_comp = adata
if layer is not None:
Expand Down
2 changes: 1 addition & 1 deletion tests/notebooks/test_paga_paul15_subsampled.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,6 @@ def test_paga_paul15_subsampled(image_comparer, plt):
show=False,
)
# add a test for this at some point
# data.to_csv('./write/paga_path_{}.csv'.format(descr))
# data.to_csv(f"./write/paga_path_{descr}.csv")

save_and_compare_images("paga_path")
Loading