Skip to content

Commit fe02c56

Browse files
copy anndata in metric decorator (openproblems-bio#819)
1 parent 52d1ecc commit fe02c56

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ Metrics should take an AnnData object and return a `float`.
178178
function metric(AnnData adata) -> float
179179
```
180180

181+
Note that the AnnData object is passed to the metric function as a copy, so there is no
182+
need to copy it internally, even if you modify the object.
183+
181184
Task-specific APIs are described in the README for each task.
182185

183186
* [Label Projection](openproblems/tasks/label_projection)

openproblems/tools/decorators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ def metric(metric_name, maximize, paper_reference, image="openproblems"):
126126

127127
def decorator(func):
128128
@functools.wraps(func)
129-
def apply_metric(*args, **kwargs):
129+
def apply_metric(adata: anndata.AnnData, *args, **kwargs):
130130
log.debug("Running {} metric".format(func.__name__))
131-
return func(*args, **kwargs)
131+
return func(adata.copy(), *args, **kwargs)
132132

133133
apply_metric.metadata = dict(
134134
metric_name=metric_name,

0 commit comments

Comments
 (0)