Skip to content

Fix detect_outliers_ecod to handle pandas Series and missing values - #64

Draft
enryH with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-ecod-missing-data-handling
Draft

Fix detect_outliers_ecod to handle pandas Series and missing values#64
enryH with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-ecod-missing-data-handling

Conversation

Copilot AI commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

detect_outliers_ecod used raw integer indexing (N[0], N[i], slices) which breaks silently when passed a pandas Series with a non-default index (label-based access). Additionally, NaN inputs caused obscure ECOD fitting errors with no actionable message.

Changes

  • Input coercion: Convert N to np.ndarray via np.asarray(N, dtype=float) at function entry — fixes label-vs-position indexing for any pandas Series index
  • NaN guard: Raise ValueError with a clear message when input contains NaN values, rather than letting ECOD fail opaquely
import pandas as pd
import numpy as np
from growthcurves.preprocessing import detect_outliers_ecod

# Previously broken: non-default index causes KeyError or wrong results
s = pd.Series([0.1, 0.2, 0.3, 0.5, 0.8], index=range(5, 10))
mask = detect_outliers_ecod(s)  # now works correctly

# Missing values now raise a clear error
s_nan = pd.Series([0.1, np.nan, 0.3])
detect_outliers_ecod(s_nan)  # raises ValueError: "...does not support missing values (NaN)..."

Tests added

  • test_ecod_pandas_series_default_index — baseline Series case
  • test_ecod_pandas_series_non_default_index — previously broken path
  • test_ecod_numpy_array — regression guard
  • test_ecod_missing_values_raises — NaN in ndarray raises ValueError
  • test_ecod_missing_values_in_series_raises — NaN in Series raises ValueError

Copilot AI linked an issue Apr 27, 2026 that may be closed by this pull request
2 tasks
Copilot AI changed the title [WIP] Fix ECOD to accept missing data and pandas Series Fix detect_outliers_ecod to handle pandas Series and missing values Apr 27, 2026
Copilot AI requested a review from enryH April 27, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ECOD does not accept missing data and pandas Series

2 participants