From f143351944781462872e25e71703c4d840036657 Mon Sep 17 00:00:00 2001 From: Shing Chan Date: Tue, 11 Jun 2024 12:35:26 +0100 Subject: [PATCH] refactor: global shut "Mean of empty slice" warning when .median() of all NA --- src/stepcount/stepcount.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/stepcount/stepcount.py b/src/stepcount/stepcount.py index 2c05fe3..75b4bed 100644 --- a/src/stepcount/stepcount.py +++ b/src/stepcount/stepcount.py @@ -19,6 +19,9 @@ from stepcount import __model_version__ from stepcount import __model_md5__ +warnings.filterwarnings('ignore', message='Mean of empty slice') # shut .median() warning when all-NaN + + def main(): @@ -456,9 +459,7 @@ def _max(x, min_wear=None, dt=None): def _median(x, min_wear=None, dt=None): if not _is_enough(x, min_wear, dt): return np.nan - with warnings.catch_warnings(): - warnings.filterwarnings('ignore', message='Mean of empty slice') - return x.median() + return x.median() def _percentile_at(x, ps=(5, 25, 50, 75, 95), min_wear=None, dt=None): percentiles = {f'p{p:02}_at': np.nan for p in ps}