GeezerVison is showing github.com — BUG: Fix np.quantile([Fraction(2,1)], 0.5) (#24711) · charris/numpy@fee88ab
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: numpy/lib/function_base.py +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -4655,7 +4655,8 @@ def _lerp(a, b, t, out=None): | 4655 | 4655 | diff_b_a = subtract(b, a) | 4656 | 4656 | # asanyarray is a stop-gap until gh-13105 | 4657 | 4657 | lerp_interpolation = asanyarray(add(a, diff_b_a * t, out=out)) | 4658 | | - subtract(b, diff_b_a * (1 - t), out=lerp_interpolation, where=t >= 0.5) | | 4658 | + subtract(b, diff_b_a * (1 - t), out=lerp_interpolation, where=t >= 0.5, | | 4659 | + casting='unsafe', dtype=type(lerp_interpolation.dtype)) | 4659 | 4660 | if lerp_interpolation.ndim == 0 and out is None: | 4660 | 4661 | lerp_interpolation = lerp_interpolation[()] # unpack 0d arrays | 4661 | 4662 | return lerp_interpolation | |
Collapse file Copy file name to clipboardExpand all lines: numpy/lib/tests/test_function_base.py +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3606,6 +3606,10 @@ def test_fraction(self): | 3606 | 3606 | assert_equal(q, Fraction(7, 2)) | 3607 | 3607 | assert_equal(type(q), Fraction) | 3608 | 3608 |
| | 3609 | + q = np.quantile(x, .5) | | 3610 | + assert_equal(q, 1.75) | | 3611 | + assert_equal(type(q), np.float64) | | 3612 | + | 3609 | 3613 | q = np.quantile(x, Fraction(1, 2)) | 3610 | 3614 | assert_equal(q, Fraction(7, 4)) | 3611 | 3615 | assert_equal(type(q), Fraction) | |
|