From a39485e3b9805d3ea3ec53a0ffdff50c0b33d24e Mon Sep 17 00:00:00 2001 From: Carwyn Pelley Date: Tue, 29 Mar 2016 18:06:32 +0100 Subject: [PATCH 1/2] BUG: Failing type return on masked array on LHS --- biggus/_init.py | 8 ++++++++ biggus/tests/test_integration.py | 13 +++++++++++++ 2 files changed, 21 insertions(+) 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..8a2e4e1 100644 --- a/biggus/tests/test_integration.py +++ b/biggus/tests/test_integration.py @@ -49,6 +49,19 @@ 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) + if __name__ == '__main__': unittest.main() From b61e6e3b4ef1395088fd6adfc06cb0f85788324b Mon Sep 17 00:00:00 2001 From: Carwyn Pelley Date: Tue, 13 Dec 2016 08:54:20 +0000 Subject: [PATCH 2/2] TEST: Added case with no array_priority --- biggus/tests/test_integration.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/biggus/tests/test_integration.py b/biggus/tests/test_integration.py index 8a2e4e1..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 @@ -62,6 +63,13 @@ def test_masked_array_numpy_first_biggus_second(self): 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()