diff --git a/biggus/_init.py b/biggus/_init.py index 2b378c8..18eb0df 100644 --- a/biggus/_init.py +++ b/biggus/_init.py @@ -701,6 +701,10 @@ def ndarray(self): except AttributeError: return np.array(self.array) + @property + def __array_priority__(self): + return self.array.__array_priority__ + def masked_array(self): try: return self.array.masked_array() @@ -1322,6 +1326,10 @@ def fill_value(self): def shape(self): return _sliced_shape(self.concrete.shape, self._keys) + @property + def __array_priority__(self): + return self.concrete.__array_priority__ + def _cleanup_new_key(self, key, size, axis): """ Return a key of type int, slice, or tuple that is guaranteed diff --git a/biggus/tests/test_integration.py b/biggus/tests/test_integration.py index ac3c345..aea5532 100644 --- a/biggus/tests/test_integration.py +++ b/biggus/tests/test_integration.py @@ -17,6 +17,7 @@ from __future__ import absolute_import, division, print_function from six.moves import (filter, input, map, range, zip) # noqa +import mock import unittest import numpy as np @@ -49,6 +50,26 @@ def test_mean_of_mean(self): result = mean2.ndarray() np.testing.assert_array_equal(result, expected) + def test_masked_array_numpy_first_biggus_second(self): + # Ensure that an operation where the biggus array is second (i.e. + # calling the special method of the numpy array not the biggus array, + # returns the expected type). + mask = [False, True, False] + arr = np.ma.array([1, 2, 3], mask=mask) + barr = biggus.NumpyArrayAdapter(arr) + result = (np.array([[1.]]) * barr).masked_array() + target = np.array([[1.]]) * arr + + np.testing.assert_array_equal(result, target) + np.testing.assert_array_equal(result.mask, target.mask) + + def test_no_array_priority_attribute_present(self): + arr = biggus.ConstantArray((3), 1.0) + barr = biggus.NumpyArrayAdapter(arr) + result = np.array([[1.]]) * barr + target = np.array([[1.]]) * arr + np.testing.assert_array_equal(result, target) + if __name__ == '__main__': unittest.main()