diff --git a/Lib/test/test_statistics.py b/Lib/test/test_statistics.py index 31074fd7a..9ce6d3847 100644 --- a/Lib/test/test_statistics.py +++ b/Lib/test/test_statistics.py @@ -2133,8 +2133,6 @@ class TestGeometricMean(unittest.TestCase): self.assertTrue(math.isclose(small_gm, 36.0 * small)) self.assertNotEqual(small_gm, 0.0) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_error_cases(self): geometric_mean = statistics.geometric_mean StatisticsError = statistics.StatisticsError @@ -2155,8 +2153,6 @@ class TestGeometricMean(unittest.TestCase): with self.assertRaises(TypeError): geometric_mean([10, 20, 60], 70) # too many arguments - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_special_values(self): # Rules for special values are inherited from math.fsum() geometric_mean = statistics.geometric_mean diff --git a/stdlib/src/math.rs b/stdlib/src/math.rs index 6635f266a..b2437563a 100644 --- a/stdlib/src/math.rs +++ b/stdlib/src/math.rs @@ -130,8 +130,18 @@ mod math { } #[pyfunction] - fn log(x: ArgIntoFloat, base: OptionalArg) -> f64 { - base.map_or_else(|| x.to_f64().ln(), |base| x.to_f64().log(base.to_f64())) + fn log(x: ArgIntoFloat, base: OptionalArg, vm: &VirtualMachine) -> PyResult { + let x = x.to_f64(); + base.map_or_else( + || { + if x.is_nan() || x > 0.0_f64 { + Ok(x.ln()) + } else { + Err(vm.new_value_error("math domain error".to_owned())) + } + }, + |base| Ok(x.log(base.to_f64())), + ) } #[pyfunction]