From 98b259be337e592407b0f748acc55a6c02926d81 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Tue, 12 May 2015 10:40:25 +0100 Subject: [PATCH] energy_model: fix np.vectorize on ImportError np.vectorize was being unconditionally invoked at top level. On an ImportError, np as set to None, so this was resuling in an AttributeError when loading the module if one of the dependent libraries was not present on the host system. This moves the invocation into the try block with the imports to avoid an error when energy_model module is loaded by the extension is not used. --- wlauto/instrumentation/energy_model/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wlauto/instrumentation/energy_model/__init__.py b/wlauto/instrumentation/energy_model/__init__.py index 5e84ac3a..04313e81 100644 --- a/wlauto/instrumentation/energy_model/__init__.py +++ b/wlauto/instrumentation/energy_model/__init__.py @@ -15,6 +15,7 @@ try: matplotlib.use('AGG') import matplotlib.pyplot as plt import numpy as np + low_filter = np.vectorize(lambda x: x > 0 and x or 0) # pylint: disable=no-member import_error = None except ImportError as e: import_error = e @@ -22,6 +23,7 @@ except ImportError as e: pd = None plt = None np = None + low_filter = None from wlauto import Instrument, Parameter, File from wlauto.exceptions import ConfigError, InstrumentError, DeviceError @@ -100,9 +102,6 @@ class PowerPerformanceAnalysis(object): self.summary['max_power'] = data[data.cpus == 1].power.max() -low_filter = np.vectorize(lambda x: x > 0 and x or 0) # pylint: disable=no-member - - def build_energy_model(freq_power_table, cpus_power, idle_power, first_cluster_idle_state): # pylint: disable=too-many-locals em = EnergyModel()