Skip to content

Commit d21faff

Browse files
Guard outlier_indicator against all-NaN columns
Skip nanpercentile on empty slices to avoid RuntimeWarning; flag defaults to 0 for columns with no valid observations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2a278c6 commit d21faff

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/statspai/utils/egen.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,12 @@ def outlier_indicator(
145145
raise ValueError(f"Column '{v}' not found")
146146
col = df[v].astype(float)
147147
valid = col.notna()
148-
lo = np.nanpercentile(col[valid], lo_pct)
149-
hi = np.nanpercentile(col[valid], hi_pct)
150-
flag = ((col < lo) | (col > hi)).astype(int)
148+
if valid.any():
149+
lo = np.nanpercentile(col[valid], lo_pct)
150+
hi = np.nanpercentile(col[valid], hi_pct)
151+
flag = ((col < lo) | (col > hi)).astype(int)
152+
else:
153+
flag = pd.Series(0, index=col.index, dtype=int)
151154
flag[~valid] = 0
152155
name = f'{v}_outlier'
153156
df[name] = flag

0 commit comments

Comments
 (0)