From 4628f7d6ac3b3ab45d2b623b4b574da9adf5b4c1 Mon Sep 17 00:00:00 2001 From: xgboosted <1528712+xgboosted@users.noreply.github.com> Date: Wed, 8 Jul 2026 19:23:59 +1000 Subject: [PATCH] test(metrics): align optimal_leverage test with float contract optimal_leverage returns float instead of int(...) and raises ValueError on zero-variance input; the old test pinned the int truncation. Adds finiteness asserts and the zero-std raise path. --- tests/test_utils_metrics.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/test_utils_metrics.py b/tests/test_utils_metrics.py index 216aa29..5167e4e 100644 --- a/tests/test_utils_metrics.py +++ b/tests/test_utils_metrics.py @@ -1,6 +1,7 @@ +import math from unittest import TestCase -from pandas import DataFrame +from pandas import DataFrame, Series from tests.config import get_sample_data import pandas_ta_classic as pandas_ta @@ -94,17 +95,20 @@ class TestUtilityMetrics(TestCase): def test_optimal_leverage(self): result = pandas_ta.optimal_leverage(self.close) - self.assertIsInstance(result, int) + self.assertIsInstance(result, float) + self.assertTrue(math.isfinite(result)) result = pandas_ta.optimal_leverage(self.close, log=True) - self.assertIsInstance(result, int) + self.assertIsInstance(result, float) + self.assertTrue(math.isfinite(result)) + constant = Series([100.0] * 60) + with self.assertRaises(ValueError): + pandas_ta.optimal_leverage(constant) def test_pure_profit_score(self): result = pandas_ta.pure_profit_score(self.close) self.assertGreaterEqual(result, 0) def test_sharpe_ratio(self): - import math - result = pandas_ta.sharpe_ratio(self.close) self.assertIsInstance(result, float) self.assertGreaterEqual(result, 0)