diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index fe41a996fe15..4d765bbc1769 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -2764,7 +2764,7 @@ def median(a, axis=None, out=None, overwrite_input=False): >>> assert not np.all(a==b) """ - a = np.asarray(a) + a = np.asanyarray(a) if axis is not None and axis >= a.ndim: raise IndexError( "axis %d out of bounds (%d)" % (axis, a.ndim)) diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index dd0b6e0ee64f..8dd862d740b5 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1621,6 +1621,19 @@ def test_array_like(self): assert_almost_equal(np.median(x2), 2) assert_allclose(np.median(x2, axis=0), x) + def test_subclass(self): + # gh-3846 + class MySubClass(np.ndarray): + def __new__(cls, input_array, info=None): + obj = np.asarray(input_array).view(cls) + obj.info = info + return obj + + def mean(self, axis=None, dtype=None, out=None): + return -7 + + a = MySubClass([1,2,3]) + assert_equal(np.median(a), -7) class TestAdd_newdoc_ufunc(TestCase):