summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/HOWTO_DOCUMENT.rst.txt7
-rw-r--r--numpy/doc/byteswapping.py9
-rw-r--r--numpy/ma/core.py8
-rw-r--r--numpy/ma/tests/test_core.py28
4 files changed, 46 insertions, 6 deletions
diff --git a/doc/HOWTO_DOCUMENT.rst.txt b/doc/HOWTO_DOCUMENT.rst.txt
index 8e841755a..6789ce893 100644
--- a/doc/HOWTO_DOCUMENT.rst.txt
+++ b/doc/HOWTO_DOCUMENT.rst.txt
@@ -42,8 +42,11 @@ Additional PEPs of interest regarding documentation of code:
Use a code checker:
* `pylint <http://www.logilab.org/857>`_
- * `pyflakes` easy_install pyflakes
+ * `pyflakes <https://pypi.python.org/pypi/pyflakes>`_
* `pep8.py <http://svn.browsershots.org/trunk/devtools/pep8/pep8.py>`_
+ * `flake8 <https://pypi.python.org/pypi/flake8>`_
+ * `vim-flake8 <https://github.com/nvie/vim-flake8>`_ plugin for
+ automatically checking syntax and style with flake8
The following import conventions are used throughout the NumPy source
and documentation::
@@ -260,7 +263,7 @@ The sections of the docstring are:
LinAlgException
If the matrix is not numerically invertible.
- This section should be used judiciously, i.e only for errors
+ This section should be used judiciously, i.e., only for errors
that are non-obvious or have a large chance of getting raised.
8. **See Also**
diff --git a/numpy/doc/byteswapping.py b/numpy/doc/byteswapping.py
index 8632e9794..ffefe3168 100644
--- a/numpy/doc/byteswapping.py
+++ b/numpy/doc/byteswapping.py
@@ -134,5 +134,14 @@ the previous operations:
>>> swapped_end_arr.tostring() == big_end_str
False
+An easier way of casting the data to a specific dtype and byte ordering
+can be achieved with the ndarray astype method:
+
+>>> swapped_end_arr = big_end_arr.astype('<i2')
+>>> swapped_end_arr[0]
+1
+>>> swapped_end_arr.tostring() == big_end_str
+False
+
"""
from __future__ import division, absolute_import, print_function
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index 68c5d5595..8dc2ca86e 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -6186,10 +6186,10 @@ def compressed(x):
Equivalent method.
"""
- if getmask(x) is nomask:
- return np.asanyarray(x)
- else:
- return x.compressed()
+ if not isinstance(x, MaskedArray):
+ x = asanyarray(x)
+ return x.compressed()
+
def concatenate(arrays, axis=0):
"""
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 6608cce63..764915236 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -3308,6 +3308,34 @@ class TestMaskedArrayFunctions(TestCase):
test = np.ma.compress(cond, marr, axis=0)
assert_equal(test, control)
+ def test_compressed(self):
+ # Test ma.compressed function.
+ # Address gh-4026
+ a = np.ma.array([1, 2])
+ test = np.ma.compressed(a)
+ assert_(type(test) is np.ndarray)
+ # Test case when input data is ndarray subclass
+ class A(np.ndarray):
+ pass
+ a = np.ma.array(A(shape=0))
+ test = np.ma.compressed(a)
+ assert_(type(test) is A)
+ # Test that compress flattens
+ test = np.ma.compressed([[1],[2]])
+ assert_equal(test.ndim, 1)
+ test = np.ma.compressed([[[[[1]]]]])
+ assert_equal(test.ndim, 1)
+ # Test case when input is MaskedArray subclass
+ class M(MaskedArray):
+ pass
+ test = np.ma.compressed(M(shape=(0,1,2)))
+ assert_equal(test.ndim, 1)
+ # with .compessed() overriden
+ class M(MaskedArray):
+ def compressed(self):
+ return 42
+ test = np.ma.compressed(M(shape=(0,1,2)))
+ assert_equal(test, 42)
#------------------------------------------------------------------------------
class TestMaskedFields(TestCase):