Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #176 from cpelley/BUG_MASKED_ARRAY_LHS
Browse files Browse the repository at this point in the history
BUG: Failing type return on masked array on LHS
  • Loading branch information
pelson authored Dec 13, 2016
2 parents 15fc0e9 + b61e6e3 commit 56c87f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions biggus/_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions biggus/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

0 comments on commit 56c87f3

Please sign in to comment.