Skip to content

Commit e6981a9

Browse files
committed
cherry pick local commit 3cbbd17
1 parent f76a936 commit e6981a9

File tree

2 files changed

+1
-90
lines changed

2 files changed

+1
-90
lines changed

ibllib/qc/task_metrics.py

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@
5252
"""
5353
import logging
5454
import sys
55-
import warnings
5655
from packaging import version
5756
from pathlib import Path, PurePosixPath
5857
from datetime import datetime, timedelta
5958
from inspect import getmembers, isfunction
60-
from functools import reduce, wraps
59+
from functools import reduce
6160
from collections.abc import Sized
6261

6362
import numpy as np
@@ -91,34 +90,6 @@
9190
}
9291

9392

94-
def _static_check(func):
95-
"""Log a warning when static method called with class instead of object.
96-
97-
The TaskQC 'criteria' attribute is now varies depending on the task version and may be changed
98-
in subclasses depending on hardware and task protocol. Therefore the
99-
TaskQC.compute_session_status_from_dict method should be called with an object instance in
100-
order use the correct criteria.
101-
"""
102-
@wraps(func)
103-
def inner(*args, **kwargs):
104-
warnings.warn('TaskQC.compute_session_status_from_dict is deprecated. '
105-
'Use ibllib.qc.task_metrics.compute_session_status_from_dict instead', DeprecationWarning)
106-
if not args: # allow function to raise on missing param
107-
return compute_session_status_from_dict(*args, **kwargs)
108-
if not isinstance(args[0], TaskQC):
109-
_log.warning(
110-
'Calling TaskQC.compute_session_status_from_dict as a static method yields inconsistent results.'
111-
)
112-
if len(args) == 1 and kwargs.get('criteria', None) is None:
113-
kwargs['criteria'] = BWM_CRITERIA # old behaviour
114-
else:
115-
if kwargs.get('criteria', None) is None and len(args) == 2:
116-
kwargs['criteria'] = args[0].criteria # ensure we use the obj's modified criteria
117-
args = args[1:]
118-
return compute_session_status_from_dict(*args, **kwargs)
119-
return inner
120-
121-
12293
def compute_session_status_from_dict(results, criteria=None):
12394
"""
12495
Given a dictionary of results, computes the overall session QC for each key and aggregates
@@ -389,32 +360,6 @@ def run(self, update=False, namespace='task', **kwargs):
389360
self.update(outcome, namespace)
390361
return outcome, results
391362

392-
@_static_check
393-
@staticmethod
394-
def compute_session_status_from_dict(results, criteria=None):
395-
"""
396-
(DEPRECATED) Given a dictionary of results, computes the overall session QC for each key
397-
and aggregates in a single value.
398-
399-
NB: Use :func:`ibllib.qc.task_metrics.compute_session_status_from_dict` instead and always
400-
pass in the criteria.
401-
402-
Parameters
403-
----------
404-
results : dict
405-
A dictionary of QC keys containing (usually scalar) values.
406-
criteria : dict
407-
A dictionary of qc keys containing map of PASS, WARNING, FAIL thresholds.
408-
409-
Returns
410-
-------
411-
str
412-
Overall session QC outcome as a string.
413-
dict
414-
A map of QC tests and their outcomes.
415-
"""
416-
... # no longer called by decorator
417-
418363
def compute_session_status(self):
419364
"""
420365
Computes the overall session QC for each key and aggregates in a single value.

ibllib/tests/qc/test_task_metrics.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,6 @@ def _create_test_qc_outcomes():
3030

3131
class TestAggregateOutcome(unittest.TestCase):
3232

33-
def test_deprecation_warning(self):
34-
"""Remove TaskQC.compute_session_status_from_dict after 2024-06-01. Cherry pick commit
35-
3cbbd1769e1ba82a51b09a992b2d5f4929f396b2 for removal of this test and applicable code"""
36-
from datetime import datetime
37-
self.assertFalse(datetime.now() > datetime(2024, 6, 1), 'remove TaskQC.compute_session_status_from_dict method.')
38-
qc_dict = {'_task_iti_delays': .99}
39-
with self.assertWarns(DeprecationWarning), self.assertLogs(qcmetrics.__name__, spec.QC.WARNING):
40-
out = qcmetrics.TaskQC.compute_session_status_from_dict(qc_dict)
41-
expected = (spec.QC.NOT_SET, {'_task_iti_delays': spec.QC.NOT_SET})
42-
self.assertEqual(expected, out, 'failed to use BWM criteria')
43-
# Should handle criteria as input, both as arg and kwarg
44-
criteria = {'_task_iti_delays': {spec.QC.PASS: 0.9, spec.QC.FAIL: 0},
45-
'default': {spec.QC.PASS: 0.9, spec.QC.WARNING: 0.4}}
46-
out = qcmetrics.TaskQC.compute_session_status_from_dict(qc_dict, criteria=criteria)
47-
expected = (spec.QC.PASS, {'_task_iti_delays': spec.QC.PASS})
48-
self.assertEqual(expected, out, 'failed to use BWM criteria')
49-
out = qcmetrics.TaskQC.compute_session_status_from_dict(qc_dict, criteria)
50-
self.assertEqual(expected, out, 'failed to use BWM criteria')
51-
qc = qcmetrics.TaskQC('/foo/subject/2024-01-01/001', one=ONE(mode='local', **TEST_DB))
52-
self.assertRaises(TypeError, qcmetrics.TaskQC.compute_session_status_from_dict)
53-
if getattr(self, 'assertNoLogs', False) is False:
54-
self.skipTest('Python < 3.10') # py 3.8
55-
with self.assertWarns(DeprecationWarning), self.assertNoLogs(qcmetrics.__name__, 'WARNING'):
56-
out = qc.compute_session_status_from_dict(qc_dict)
57-
expected = (spec.QC.NOT_SET, {'_task_iti_delays': spec.QC.NOT_SET})
58-
self.assertEqual(expected, out, 'failed to use BWM criteria')
59-
# Should handle criteria as input, both as arg and kwarg
60-
criteria = {'_task_iti_delays': {spec.QC.PASS: 0.9, spec.QC.FAIL: 0}, 'default': {spec.QC.PASS: 0}}
61-
out, _ = qc.compute_session_status_from_dict(qc_dict, criteria=criteria)
62-
self.assertEqual(spec.QC.PASS, out)
63-
out, _ = qc.compute_session_status_from_dict(qc_dict, criteria)
64-
self.assertEqual(spec.QC.PASS, out)
65-
self.assertRaises(TypeError, qc.compute_session_status_from_dict)
66-
6733
def test_outcome_from_dict_default(self):
6834
# For a task that has no costume thresholds, default is 0.99 PASS and 0.9 WARNING and 0 FAIL,
6935
# np.nan and None return not set

0 commit comments

Comments
 (0)