STALE_VALUES_ROUND
This function detects “stale” or repeating sensor values that occur when an instrument becomes stuck.
A point is marked as stale if it belongs to a contiguous sequence (of length at least window) of readings that are identical when rounded to the specified number of decimal places.
Excel Usage
=STALE_VALUES_ROUND(x, window, decimals, mark)
x(list[list], required): Numeric data values.window(int, optional, default: 6): Number of consecutive identical elements to be considered stale.decimals(int, optional, default: 3): Number of decimal places to round to before comparing.mark(str, optional, default: “tail”): How much of the sequence to mark True. One of ‘tail’, ‘end’, or ‘all’.
Returns (list[list]): 2D list of booleans (True if stale), or an error string.
Example 1: Detect repeating values over a window
Inputs:
| x | window | decimals | mark |
|---|---|---|---|
| 1.001 | 3 | 2 | all |
| 1.001 | |||
| 1.001 | |||
| 1.001 | |||
| 2 |
Excel formula:
=STALE_VALUES_ROUND({1.001;1.001;1.001;1.001;2}, 3, 2, "all")
Expected output:
| Result |
|---|
| true |
| true |
| true |
| true |
| false |
Example 2: Detect stale values with tail marking mode
Inputs:
| x | window | decimals | mark |
|---|---|---|---|
| 5 | 3 | 0 | tail |
| 5 | |||
| 5 | |||
| 6 |
Excel formula:
=STALE_VALUES_ROUND({5;5;5;6}, 3, 0, "tail")
Expected output:
| Result |
|---|
| false |
| true |
| true |
| false |
Example 3: Detect stale values with end marking mode
Inputs:
| x | window | decimals | mark |
|---|---|---|---|
| 2.2 | 3 | 1 | end |
| 2.2 | |||
| 2.2 | |||
| 2.2 | |||
| 2.2 |
Excel formula:
=STALE_VALUES_ROUND({2.2;2.2;2.2;2.2;2.2}, 3, 1, "end")
Expected output:
| Result |
|---|
| false |
| false |
| true |
| true |
| true |
Example 4: Handle scalar stale-value input
Inputs:
| x | window | decimals | mark |
|---|---|---|---|
| 7.5 | 3 | 2 | all |
Excel formula:
=STALE_VALUES_ROUND(7.5, 3, 2, "all")
Expected output:
false
Python Code
Show Code
import pandas as pd
from pvanalytics.quality.gaps import stale_values_round as result_func
def stale_values_round(x, window=6, decimals=3, mark='tail'):
"""
Identify stale or stuck-sensor values by rounding and checking for repeating sequences.
See: https://pvanalytics.readthedocs.io/en/stable/generated/pvanalytics.quality.gaps.stale_values_round.html
This example function is provided as-is without any representation of accuracy.
Args:
x (list[list]): Numeric data values.
window (int, optional): Number of consecutive identical elements to be considered stale. Default is 6.
decimals (int, optional): Number of decimal places to round to before comparing. Default is 3.
mark (str, optional): How much of the sequence to mark True. One of 'tail', 'end', or 'all'. Valid options: Tail, End, All. Default is 'tail'.
Returns:
list[list]: 2D list of booleans (True if stale), or an error string.
"""
try:
def flatten_num(data):
if not isinstance(data, list): return [float(data)]
flat = []
for row in data:
row = row if isinstance(row, list) else [row]
for val in row:
if val == "": flat.append(float('nan'))
else: flat.append(float(val))
return flat
val_list = flatten_num(x)
if len(val_list) == 0:
return "Error: input array cannot be empty"
series = pd.Series(val_list)
w = int(window) if window is not None else 6
dec = int(decimals) if decimals is not None else 3
m = str(mark) if mark is not None else "tail"
if m not in ["tail", "end", "all"]:
return "Error: mark must be 'tail', 'end', or 'all'"
res = result_func(series, window=w, decimals=dec, mark=m)
return [[bool(v)] for v in res]
except Exception as e:
return f"Error: {str(e)}"Online Calculator
Numeric data values.
Number of consecutive identical elements to be considered stale.
Number of decimal places to round to before comparing.
How much of the sequence to mark True. One of 'tail', 'end', or 'all'.