diff --git a/docs/whatsnew/v0.2.3.rst b/docs/whatsnew/v0.2.3.rst index 216f9f59..d309d726 100644 --- a/docs/whatsnew/v0.2.3.rst +++ b/docs/whatsnew/v0.2.3.rst @@ -15,6 +15,10 @@ Bug Fixes * Remove freq parameter from :py:func:`pvanalytics.quality.gaps.completeness` and :py:func:`pvanalytics.quality.gaps.completeness_score`. Frequency is now always calculated from the input data's DatetimeIndex. (:pull:`236`) +* Suppress divide-by-zero warnings in + :mod:`pvanalytics.features.snow` and precision-loss warnings in + :mod:`pvanalytics.quality.outliers` by extending ``np.errstate`` to +include ``invalid='ignore'``. (:issue:`#237`, :pull:`YYY`) Requirements ~~~~~~~~~~~~ @@ -39,3 +43,4 @@ Testing Contributors ~~~~~~~~~~~~ * Cliff Hansen (:ghuser:`cwhanse`) +* Omesh Chandure (:ghuser: `Omesh37`) \ No newline at end of file diff --git a/pvanalytics/features/snow.py b/pvanalytics/features/snow.py index c3b542db..84c98c37 100644 --- a/pvanalytics/features/snow.py +++ b/pvanalytics/features/snow.py @@ -224,7 +224,7 @@ def categorize(transmission, measured_voltage, modeled_voltage_with_snow_copy = np.where( transmission == 0, 0, modeled_voltage_with_snow) - with np.errstate(divide='ignore'): + with np.errstate(divide='ignore', invalid='ignore'): vmp_ratio =\ measured_voltage /\ modeled_voltage_with_snow_copy diff --git a/pvanalytics/quality/outliers.py b/pvanalytics/quality/outliers.py index 4efc140d..ead57f96 100644 --- a/pvanalytics/quality/outliers.py +++ b/pvanalytics/quality/outliers.py @@ -1,5 +1,6 @@ """Functions for identifying and labeling outliers.""" import pandas as pd +import numpy as np from scipy import stats from statsmodels import robust @@ -75,7 +76,8 @@ def zscore(data, zmax=1.5, nan_policy='raise'): "nan_policy. Expected 'raise' or 'omit'.") is_outlier = pd.Series(False, index=data.index) - is_outlier.loc[~nan_mask] = abs(stats.zscore(data[~nan_mask])) > zmax + with np.errstate(invalid='ignore'): + is_outlier.loc[~nan_mask] = abs(stats.zscore(data[~nan_mask])) > zmax return is_outlier diff --git a/pvanalytics/util/_fit.py b/pvanalytics/util/_fit.py index 65a61559..479be44a 100644 --- a/pvanalytics/util/_fit.py +++ b/pvanalytics/util/_fit.py @@ -127,4 +127,7 @@ def _quartic(x, a, b, c, e): ) model = _quartic(x, params[0], params[1], params[2], params[3]) residuals = y - model - return 1 - (np.sum(residuals**2) / np.sum((y - np.mean(y))**2)) + ss_tot = np.sum((y - np.mean(y))**2) + if ss_tot == 0: + return 0.0 + return 1 - (np.sum(residuals**2) / ss_tot)