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

BUG: Failing type return on masked array on LHS #176

Merged
merged 2 commits into from
Dec 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be from biggus.tests import mock. I'm not sure why Travis has mock installed on Python 3; it's not supposed to be.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, #197

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()