refactor: 분모 연산을 1e-8 epsilon 패턴으로 통일
Made-with: Cursor
This commit is contained in:
@@ -93,6 +93,30 @@ def test_matches_original_generate_dataset(sample_df):
|
||||
)
|
||||
|
||||
|
||||
def test_epsilon_no_division_by_zero():
|
||||
"""bb_range=0, close=0, vol_ma20=0 극단값에서 nan/inf가 발생하지 않아야 한다."""
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from src.dataset_builder import _calc_features_vectorized, _calc_signals, _calc_indicators
|
||||
|
||||
n = 100
|
||||
# close를 모두 같은 값으로 → bb_range=0 유발
|
||||
df = pd.DataFrame({
|
||||
"open": np.ones(n),
|
||||
"high": np.ones(n),
|
||||
"low": np.ones(n),
|
||||
"close": np.ones(n),
|
||||
"volume": np.ones(n),
|
||||
})
|
||||
d = _calc_indicators(df)
|
||||
sig = _calc_signals(d)
|
||||
feat = _calc_features_vectorized(d, sig)
|
||||
|
||||
numeric_cols = feat.select_dtypes(include=[np.number]).columns
|
||||
assert not feat[numeric_cols].isin([np.inf, -np.inf]).any().any(), \
|
||||
"inf 값이 있으면 안 됨"
|
||||
|
||||
|
||||
def test_oi_nan_masking_no_column():
|
||||
"""oi_change 컬럼이 없으면 전체가 nan이어야 한다."""
|
||||
import numpy as np
|
||||
|
||||
Reference in New Issue
Block a user