diff --git a/src/numta/api/momentum_indicators.py b/src/numta/api/momentum_indicators.py index 143c4bd..ed3210b 100644 --- a/src/numta/api/momentum_indicators.py +++ b/src/numta/api/momentum_indicators.py @@ -2534,11 +2534,12 @@ def MFI(high: Union[np.ndarray, list], if timeperiod < 2: raise ValueError("timeperiod must be >= 2") - # Convert to numpy arrays - high = np.asarray(high, dtype=np.float64) - low = np.asarray(low, dtype=np.float64) - close = np.asarray(close, dtype=np.float64) - volume = np.asarray(volume, dtype=np.float64) + # Convert to numpy arrays with float64 dtype and ensure contiguous memory layout + # This prevents potential segfaults in numba JIT-compiled functions + high = np.ascontiguousarray(np.asarray(high, dtype=np.float64)) + low = np.ascontiguousarray(np.asarray(low, dtype=np.float64)) + close = np.ascontiguousarray(np.asarray(close, dtype=np.float64)) + volume = np.ascontiguousarray(np.asarray(volume, dtype=np.float64)) n = len(high) if len(low) != n or len(close) != n or len(volume) != n: diff --git a/tests/test_pandas_ext_comprehensive.py b/tests/test_pandas_ext_comprehensive.py index 7ab8a0f..72dcef0 100644 --- a/tests/test_pandas_ext_comprehensive.py +++ b/tests/test_pandas_ext_comprehensive.py @@ -357,7 +357,14 @@ def test_ad_calculation(self, sample_df): def test_mfi_calculation(self, sample_df): """Test MFI calculation.""" - result = sample_df.ta.mfi(timeperiod=14) + # Ensure OHLCV data has correct dtypes to prevent numba JIT issues + df = sample_df.copy() + df['high'] = df['high'].astype(np.float64) + df['low'] = df['low'].astype(np.float64) + df['close'] = df['close'].astype(np.float64) + df['volume'] = df['volume'].astype(np.float64) + + result = df.ta.mfi(timeperiod=14) assert isinstance(result, pd.Series) # MFI should be bounded between 0 and 100