Skip to content

move the testing code in the preprocessing.py module to tests #62

Description

@sambra95

this code is at the bottom of the file

`if name == "main":
# Example usage
data = np.array([20, 1, 2, 3, 4, 5, 20, 6, 7, 8, 9, 10, 25])
print(out_of_iqr_window(data))

# rolling windows of size 5: shape -> (len(data)-4, 5)
window_size = 5
edge_idx = window_size // 2
windows = np.lib.stride_tricks.sliding_window_view(data, window_size)

# outlier flag for each 5-value window (checks center element of each window)
# center points (indices 2..-3)
window_flags = np.apply_along_axis(out_of_iqr_window, 1, windows)
edge_window_size = window_size + window_size // 2 - 1
start_windows = np.lib.stride_tricks.sliding_window_view(
    data[:edge_window_size], window_size
)
start_window_flags = np.apply_along_axis(
    out_of_iqr_window,
    1,
    start_windows,
    position="first",  # passed to out_of_iqr_window
)
end_windows = np.lib.stride_tricks.sliding_window_view(
    data[-(edge_window_size):], window_size
)
end_window_flags = np.apply_along_axis(
    out_of_iqr_window,
    1,
    end_windows,
    position="last",  # passed to out_of_iqr_window
)
print("center windows flags:", window_flags)
print("start edge windows:", start_windows)
print("start edge window flags:", start_window_flags)
print("end edge windows:", end_windows)
print("end edge window flags:", end_window_flags)
# optional: align back to original array length (center indices only)
flags = np.full(data.shape, False)

flags[:edge_idx] = start_window_flags  # [:edge_idx]
flags[edge_idx:-edge_idx] = window_flags
flags[-edge_idx:] = end_window_flags

print("windows:\n", windows)
print("window_flags:", window_flags)
print("aligned flags:", flags)
mask = detect_outliers_iqr(data, window_size=5)

print("final mask:", mask)
assert (mask == flags).all()`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions