Repository: pvlib/pvanalytics

Issue:
Increase default window in stale_values_diff and interpolation_diff
Consider setting `window=6` as default. See [discussion](https://github.com/SolarArbiter/solarforecastarbiter-core/issues/124#issuecomment-631754114)


Discussion:

Patch:
diff --git a/pvanalytics/__init__.py b/pvanalytics/__init__.py
index e69de29..432885d 100644
--- a/pvanalytics/__init__.py
+++ b/pvanalytics/__init__.py
@@ -0,0 +1,6 @@
+from pvanalytics import features   # noqa: F401
+from pvanalytics import filtering  # noqa: F401
+from pvanalytics import fitting    # noqa: F401
+from pvanalytics import metrics    # noqa: F401
+from pvanalytics import quality    # noqa: F401
+from pvanalytics import system     # noqa: F401
diff --git a/pvanalytics/features/__init__.py b/pvanalytics/features/__init__.py
index e69de29..dfb7a12 100644
--- a/pvanalytics/features/__init__.py
+++ b/pvanalytics/features/__init__.py
@@ -0,0 +1,2 @@
+from pvanalytics.features import clearsky  # noqa: F401
+from pvanalytics.features import clipping  # noqa: F401
diff --git a/pvanalytics/fitting/__init__.py b/pvanalytics/fitting/__init__.py
index e69de29..6ec9e6b 100644
--- a/pvanalytics/fitting/__init__.py
+++ b/pvanalytics/fitting/__init__.py
@@ -0,0 +1,1 @@
+from pvanalytics.fitting import temperature  # noqa: F401
diff --git a/pvanalytics/quality/__init__.py b/pvanalytics/quality/__init__.py
index e69de29..7a4c60f 100644
--- a/pvanalytics/quality/__init__.py
+++ b/pvanalytics/quality/__init__.py
@@ -0,0 +1,6 @@
+from pvanalytics.quality import gaps        # noqa: F401
+from pvanalytics.quality import util        # noqa: F401
+from pvanalytics.quality import irradiance  # noqa: F401
+from pvanalytics.quality import weather     # noqa: F401
+from pvanalytics.quality import outliers    # noqa: F401
+from pvanalytics.quality import time        # noqa: F401
diff --git a/pvanalytics/quality/gaps.py b/pvanalytics/quality/gaps.py
index 61d78e9..ff872da 100644
--- a/pvanalytics/quality/gaps.py
+++ b/pvanalytics/quality/gaps.py
@@ -15,9 +15,12 @@ def _all_close_to_first(x, rtol=1e-5, atol=1e-8):
     ----------
     x : array
     rtol : float, default 1e-5
-        Relative tolerance for detecting a change in data values.
+        Tolerance for detecting a change relative to x[0].
     atol : float, default 1e-8
-        Absolute tolerance for detecting a change in data values.
+        Absolute tolerance for detecting a change from x[0].
+
+    Parameters rtol and atol have the same meaning as in
+    numpy.allclose.
 
     Returns
     -------
@@ -48,7 +51,7 @@ def _backfill_window(endpoints, window):
     return flags
 
 
-def stale_values_diff(x, window=3, rtol=1e-5, atol=1e-8, label_all=False):
+def stale_values_diff(x, window=6, rtol=1e-5, atol=1e-8, label_all=False):
     """Identify stale values in the data.
 
     For a window of length N, the last value (index N-1) is considered
@@ -62,7 +65,7 @@ def stale_values_diff(x, window=3, rtol=1e-5, atol=1e-8, label_all=False):
     ----------
     x : Series
         data to be processed
-    window : int, default 3
+    window : int, default 6
         number of consecutive values which, if unchanged, indicates
         stale data
     rtol : float, default 1e-5
@@ -105,7 +108,7 @@ def stale_values_diff(x, window=3, rtol=1e-5, atol=1e-8, label_all=False):
     return flags
 
 
-def interpolation_diff(x, window=3, rtol=1e-5, atol=1e-8, label_all=False):
+def interpolation_diff(x, window=6, rtol=1e-5, atol=1e-8, label_all=False):
     """Identify sequences which appear to be linear.
 
     Sequences are linear if the first difference appears to be
@@ -119,7 +122,7 @@ def interpolation_diff(x, window=3, rtol=1e-5, atol=1e-8, label_all=False):
     ----------
     x : Series
         data to be processed
-    window : int, default 3
+    window : int, default 6
         number of sequential values that, if the first difference is
         constant, are classified as a linear sequence
     rtol : float, default 1e-5


Test patch:
diff --git a/pvanalytics/tests/quality/test_gaps.py b/pvanalytics/tests/quality/test_gaps.py
index 036225c..6c27558 100644
--- a/pvanalytics/tests/quality/test_gaps.py
+++ b/pvanalytics/tests/quality/test_gaps.py
@@ -52,13 +52,16 @@ def test_stale_values_diff(stale_data):
     for more information.
 
     """
-    res1 = gaps.stale_values_diff(stale_data)
+    res0 = gaps.stale_values_diff(stale_data)
+    res1 = gaps.stale_values_diff(stale_data, window=3)
     res2 = gaps.stale_values_diff(stale_data, rtol=1e-8, window=2)
     res3 = gaps.stale_values_diff(stale_data, window=7)
     res4 = gaps.stale_values_diff(stale_data, window=8)
     res5 = gaps.stale_values_diff(stale_data, rtol=1e-8, window=4)
-    res6 = gaps.stale_values_diff(stale_data[1:])
-    res7 = gaps.stale_values_diff(stale_data[1:8])
+    res6 = gaps.stale_values_diff(stale_data[1:], window=3)
+    res7 = gaps.stale_values_diff(stale_data[1:8], window=3)
+    assert_series_equal(res0, pd.Series([False, False, False, False, False,
+                                         False, True, True, False, False]))
     assert_series_equal(res1, pd.Series([False, False, False, True, True, True,
                                          True, True, False, False]))
     assert_series_equal(res2, pd.Series([False, False, True, True, True, False,
@@ -88,16 +91,16 @@ def test_stale_values_diff_handles_negatives(data_with_negatives):
     for more information.
 
     """
-    res = gaps.stale_values_diff(data_with_negatives)
+    res = gaps.stale_values_diff(data_with_negatives, window=3)
     assert_series_equal(res, pd.Series([False, False, True, True, False, False,
                                         False]))
-    res = gaps.stale_values_diff(data_with_negatives, atol=1e-3)
+    res = gaps.stale_values_diff(data_with_negatives, window=3, atol=1e-3)
     assert_series_equal(res, pd.Series([False, False, True, True, True, True,
                                         True]))
-    res = gaps.stale_values_diff(data_with_negatives, atol=1e-5)
+    res = gaps.stale_values_diff(data_with_negatives, window=3, atol=1e-5)
     assert_series_equal(res, pd.Series([False, False, True, True, True, False,
                                         False]))
-    res = gaps.stale_values_diff(data_with_negatives, atol=2e-5)
+    res = gaps.stale_values_diff(data_with_negatives, window=3, atol=2e-5)
     assert_series_equal(res, pd.Series([False, False, True, True, True, True,
                                         True]))
 
@@ -170,12 +173,17 @@ def test_interpolation_diff(interpolated_data):
     for more information.
 
     """
-    res1 = gaps.interpolation_diff(interpolated_data)
+    res0 = gaps.interpolation_diff(interpolated_data)
+    assert_series_equal(res0, pd.Series([False, False, False, False, False,
+                                         False, False, False, False, False,
+                                         False, False, False, False, False,
+                                         False, False]))
+    res1 = gaps.interpolation_diff(interpolated_data, window=3)
     assert_series_equal(res1, pd.Series([False, False, False, False, False,
                                          False, False, True, False, False,
                                          False, False, False, True, True, True,
                                          False]))
-    res2 = gaps.interpolation_diff(interpolated_data, rtol=1e-2)
+    res2 = gaps.interpolation_diff(interpolated_data, window=3, rtol=1e-2)
     assert_series_equal(res2, pd.Series([False, False, True, True, True,
                                          False, False, True, False, False,
                                          False, False, False, True, True, True,
@@ -185,7 +193,7 @@ def test_interpolation_diff(interpolated_data):
                                          False, False, False, False, False,
                                          False, False, False, False, False,
                                          True, False]))
-    res4 = gaps.interpolation_diff(interpolated_data, atol=1e-2)
+    res4 = gaps.interpolation_diff(interpolated_data, window=3, atol=1e-2)
     assert_series_equal(res4, pd.Series([False, False, True, True, True,
                                          True, True, True, False, False,
                                          False, False, False, True, True, True,
@@ -204,10 +212,10 @@ def test_interpolation_diff_handles_negatives(data_with_negatives):
     for more information.
 
     """
-    res = gaps.interpolation_diff(data_with_negatives, atol=1e-5)
+    res = gaps.interpolation_diff(data_with_negatives, window=3, atol=1e-5)
     assert_series_equal(res, pd.Series([False, False, True, True, True, True,
                                         False]))
-    res = gaps.stale_values_diff(data_with_negatives, atol=1e-4)
+    res = gaps.stale_values_diff(data_with_negatives, window=3, atol=1e-4)
     assert_series_equal(res, pd.Series([False, False, True, True, True, True,
                                         True]))