diff --git a/powerprofile/powerprofile.py b/powerprofile/powerprofile.py index de18880..263845b 100644 --- a/powerprofile/powerprofile.py +++ b/powerprofile/powerprofile.py @@ -277,21 +277,23 @@ def min(self, magn, ret='value', magn_0=None, force_magn_gt_0=False): :param ret: value or timestamp of minimum :return: min magnitude value """ - filtered = self.curve.copy() + if self._check_magn_is_valid(magn): + filtered = self.curve.copy() - if force_magn_gt_0: - filtered = filtered[self.curve[magn] > 0] - if magn_0 is not None: - filtered = filtered[self.curve[magn_0] == 0] + if force_magn_gt_0: + filtered = filtered[self.curve[magn] > 0] - if self._check_magn_is_valid(magn): - if ret == 'value': - return filtered[magn].min() - elif ret == 'timestamp': - idx_min = filtered[magn].idxmin() - return self[idx_min][self.datetime_field] + if magn_0 is not None and self._check_magn_is_valid(magn_0): + filtered = filtered[self.curve[magn_0] == 0] + + if not filtered.empty: + if ret == 'value': + return filtered[magn].min() + elif ret == 'timestamp': + idx_min = filtered[magn].idxmin() + return self[idx_min][self.datetime_field] - return False + return False def avg(self, magn): """