Skip to content

Commit 8adef5a

Browse files
Minimizing the warnigns on create recipe
1 parent 5e22409 commit 8adef5a

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

wfcommons/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
# it under the terms of the GNU General Public License as published by
88
# the Free Software Foundation, either version 3 of the License, or
99
# (at your option) any later version.
10+
import warnings
11+
warnings.filterwarnings('ignore')
1012

1113
import json
1214
import logging
1315
import math
1416
import pathlib
1517
import scipy.stats
16-
import warnings
18+
1719
import numpy as np
1820
import operator as op
1921

@@ -23,6 +25,7 @@
2325
from typing import Any, Dict, Optional, List, Tuple
2426

2527

28+
2629
class NoValue(Enum):
2730
def __repr__(self):
2831
return '<%s.%s>' % (self.__class__.__name__, self.name)
@@ -82,8 +85,6 @@ def best_fit_distribution(data: List[float], logger: Optional[Logger] = None) ->
8285
for dist_name in distribution_names:
8386
# Ignore warnings from data that can't be fit
8487
with warnings.catch_warnings():
85-
warnings.filterwarnings('ignore')
86-
8788
try:
8889
distribution = getattr(scipy.stats, dist_name)
8990
params = distribution.fit(y)
@@ -98,7 +99,7 @@ def best_fit_distribution(data: List[float], logger: Optional[Logger] = None) ->
9899
best_params = params
99100
best_sse = sse
100101
except Exception as e:
101-
print(f"WARNING: distribution \"{dist_name}\" failed ({e})")
102+
logger.warning(f"WARNING: distribution \"{dist_name}\" failed ({e})")
102103

103104
logger.debug(f'Best distribution fit: {best_distribution}')
104105
return best_distribution, best_params

wfcommons/wfinstances/instance_analyzer.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import math
1313
import numpy
1414
import scipy.stats
15+
import warnings
1516

1617
from logging import Logger
1718
from matplotlib import pyplot
@@ -207,14 +208,16 @@ def _best_fit_distribution_for_file(dict_obj, include_raw_data) -> None:
207208
:param include_raw_data:
208209
:type include_raw_data: bool
209210
"""
210-
for ext in dict_obj:
211-
dict_obj[ext]['min'] = min(dict_obj[ext]['data'])
212-
dict_obj[ext]['max'] = max(dict_obj[ext]['data'])
213-
if dict_obj[ext]['min'] != dict_obj[ext]['max']:
214-
dict_obj[ext]['distribution'] = _json_format_distribution_fit(
215-
best_fit_distribution(dict_obj[ext]['data']))
216-
if not include_raw_data:
217-
del dict_obj[ext]['data']
211+
with warnings.catch_warnings():
212+
warnings.simplefilter("ignore")
213+
for ext in dict_obj:
214+
dict_obj[ext]['min'] = min(dict_obj[ext]['data'])
215+
dict_obj[ext]['max'] = max(dict_obj[ext]['data'])
216+
if dict_obj[ext]['min'] != dict_obj[ext]['max']:
217+
dict_obj[ext]['distribution'] = _json_format_distribution_fit(
218+
best_fit_distribution(dict_obj[ext]['data']))
219+
if not include_raw_data:
220+
del dict_obj[ext]['data']
218221

219222

220223
def _json_format_distribution_fit(dist_tuple: Tuple) -> Dict[str, Any]:

0 commit comments

Comments
 (0)