summaryrefslogtreecommitdiff
path: root/numpy/ma/tests
Commit message (Collapse)AuthorAgeFilesLines
* Revert "Merge pull request #7001 from shoyer/NaT-comparison"Charles Harris2016-01-161-1/+1
| | | | | | | | | | | | This reverts commit 7141f40b58ed1e7071cde78ab7bc8ab37e9c5983, reversing changes made to 8fa6e3bef26a6d4a2c92f2824129aa4409be2590. The original broke some pandas tests. The current plan to get this in is * reversion * issue FutureWarning in 1.11 and 1.12 * make the change in 1.13.
* TEST: Ignore `FutureWarning` if raised from running masked array operations.John Kirkham2016-01-151-0/+8
|
* BUG: Enforce order param for MaskedArray constructiongfyoung2016-01-151-0/+16
| | | | | | | | Adds the 'order' parameter to the __new__ override in MaskedArray construction, enabling it to be enforced in methods like np.ma.core.array and np.ma.core.asarray. Closes gh-6646.
* TST, ENH: make all comparisons with NaT falseStephan Hoyer2016-01-141-1/+1
| | | | | | | | | Now, NaT compares like NaN: - NaT != NaT -> True - NaT == NaT (and all other comparisons) -> False We discussed this on the mailing list back in October: https://mail.scipy.org/pipermail/numpy-discussion/2015-October/073968.html
* Merge pull request #6728 from ↵ahaldane2016-01-121-0/+4
|\ | | | | | | | | gerritholl/structured_multidim_masked_array_fillvalue BUG/TST: Fix for #6723 including test: force fill_value.ndim==0
| * BUG/TST: Fix for #6723 including test: force fill_value.ndim==0Gerrit Holl2015-12-071-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | Fix issue #6723. Given an exotic masked structured array, where one of the fields has a multidimensional dtype, make sure that, when accessing this field, the fill_value still makes sense. As it stands prior to this commit, the fill_value will end up being multidimensional, possibly with a shape incompatible with the mother array, which leads to broadcasting errors in methods such as .filled(). This commit uses the first element of this multidimensional fill value as the new fill value. When more than one unique value existed in fill_value, a warning is issued. Also add a test to verify that fill_value.ndim remains 0 after indexing.
* | BUG trace is not subclass aware, such that np.trace(ma) != ma.trace().Marten van Kerkwijk2016-01-061-0/+1
| |
* | Merge pull request #6886 from charris/use-temppathCharles Harris2016-01-021-10/+6
|\ \ | | | | | | MAINT: Simplify some tests using temppath context manager.
| * | MAINT: Simplify some tests using temppath context manager.Charles Harris2015-12-261-10/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This replaces code of the pattern ``` fd, name = tempfile.mkstemp(...) os.close(fd) try: do stuff with name finally: os.remove(name) ``` with ``` with temppath() as name: do stuff with name ``` A few more complicated cases are also handled. The remains some particularly gnarly code the could probably be refactored to use temppath, but that is a more demanding project.
* | | MAINT: Cleanup and spelling fixups in ma.core testsgfyoung2015-12-301-24/+2
|/ /
* | MAINT: Remove commented out code blocksgfyoung2015-12-201-58/+0
| |
* | DOC: Use print only as function when print_function is imported from __future__gfyoung2015-12-191-3/+3
| | | | | | | | Closes gh-6863.
* | TST: Fix test_mvoid_multidim_print failures on Python 2.x for WindowsChristoph Gohlke2015-12-111-4/+4
| |
* | TST,BUG: Make test_mvoid_multidim_print work for 32 bit systems.Charles Harris2015-12-111-1/+1
| | | | | | | | | | | | | | The test currently uses an `<i8` type which is converted to a Python long integer when running on a 32 bit system with Python 2. That changes the string printed by appending `L` to the printed integer value and results in a failed test.
* | MAINT: Replace assert with assert_(...) in some tests.Charles Harris2015-12-101-16/+16
|/
* Merge pull request #6763 from ↵Charles Harris2015-12-041-0/+8
|\ | | | | | | | | gerritholl/structured_multidim_masked_array_mvoid_alt BUG/TST: Fix for #6724, make numpy.ma.mvoid consistent with numpy.void
| * BUG/TST: Fix for #6724, make numpy.ma.mvoid consistent with numpy.voidGerrit Holl2015-12-031-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make indexing on numpy.ma.mvoid consistent with indexing on numpy.void. Changes behaviour in rare cases (see below). Fixes #6724. Sometimes, indexing ma.mvoid results in a non-scalar mask. For example, dimension increases if indexing with a multi-dimensional field. Previously, this led to a ValueError (truth value ambiguous). With this commit, indexing now returns an ma.masked_array so that there is no loss of information. Note that there is a precedence for returning from void to array. Z = zeros((2,), dtype="(2,)i2,(2,)i2"), then Z[0] is a void, but Z[0][0] and Z[0]["f1"] are array. This commit therefore implements behaviouk such that numpy.ma.mvoid is consistent with numpy.void. Also adds a related test. The behaviour changes in cases where for a masked array `X`, X.dtype["A"] is multidimensional but size 1, such as in the example below. Any case where X.dtype["A"] is multidimensional but with size>1 would previously fail. Old behaviour: In [15]: X = ma.masked_array(data=[([0],)], mask=[([False],)], dtype=[("A", "(1,1)i2", (1,1))]) In [16]: X[0]["A"] Out[16]: array([[[[0]]]], dtype=int16) In [17]: X = ma.masked_array(data=[([0],)], mask=[([True],)], dtype=[("A", "(1,1)i2", (1,1))]) In [18]: X[0]["A"] Out[18]: masked New behaviour: In [1]: X = ma.masked_array(data=[([0],)], mask=[([False],)], dtype=[("A", "(1,1)i2", (1,1))]) In [2]: X[0]["A"] Out[2]: masked_array(data = [[[[0]]]], mask = [[[[False]]]], fill_value = [[[[16959]]]]) In [3]: X = ma.masked_array(data=[([0],)], mask=[([True],)], dtype=[("A", "(1,1)i2", (1,1))]) In [4]: X[0]["A"] Out[4]: masked_array(data = [[[[--]]]], mask = [[[[ True]]]], fill_value = [[[[16959]]]]) The new behaviour is more consistent with indexing the data themselves: In [7]: X.data[0]["A"] Out[7]: array([[[[0]]]], dtype=int16) In theory, this change in behaviour can break code, but I would consider it very unlikely.
* | BUG/TST: Fix #6760 by correctly describing mask on nested subdtypesGerrit Holl2015-12-031-0/+7
|/ | | | | | Fix #6760. In ma.core._recursive_make_descr, consider the case where a subdtype does itself have named fields. This ensures the correct mask for an array like `ma.zeros(2, dtype([("A", "(2,2)i1,(2,2)i1", (2,2))]))`.
* Merge pull request #6734 from saimn/ma-mask-memoryCharles Harris2015-12-011-0/+9
|\ | | | | ENH: Avoid memory peak when creating a MaskedArray with mask=True/False.
| * Add some tests for mask creation with mask=True or False.Simon Conseil2015-12-011-0/+9
| |
* | BUG/TST: Fix for #6729Gerrit Holl2015-12-011-0/+12
|/ | | | | | Fix representation of a structured masked array with dimension zero. The effect of representing a masked array with dimension zero is now similar to respresenting an mvoid. This commit fixes #6729.
* BUG: ma.make_mask should always return nomask for nomask argument.Charles Harris2015-11-111-0/+11
| | | | | | | | | | When the mask argument was nomask, commit 8da9c71 changed the behavior to depend on shrink=True as well, resulting in array(False) false being returned when shrink=True, which in turn led to bugs because nomask is a singleton and is detected by `mask is nomask`. That dectection fails when nomask is replaced by array(False). Closes #6667.
* TST: Add tests for ma.dot.Charles Harris2015-11-102-21/+37
| | | | | Test that ma.dot always returns a masked array. Test basic that the new out parameter in ma.dot works.
* BUG: immutable _arraymethod function in ma.coreJonathan Helmus2015-10-291-0/+8
| | | | | | | | | | | Replace the _arraymethod class in ma.core with a function factory which returns class method wrappers around basic array methods. These methods are bound to the MaskedArray instance and are immutable. Previously _arraymethod was a class which would incorrectly operate on the MaskedArray object which last accessed the particular named function. closes #5247
* Merge pull request #6537 from jjhelmus/ma_atleast_fixCharles Harris2015-10-211-4/+24
|\ | | | | BUG: scalar argument to ma.atleast_* return arrays
| * BUG: scalar argument to ma.atleast_* return arraysJonathan Helmus2015-10-201-4/+24
| | | | | | | | | | | | | | | | | | | | | | The np.ma.atleast_1d, np.ma.atleast_2d, np.ma.atleast_3d and np.ma.diagflat function return arrays when given a scalar in the same manner as their non-ma counterparts. Previously these function would return None. Additionally, the np.ma vstack, row_stack, hstack, column_stack, dstack, and hsplit functions now raise an expection when given a scalar argument. closes #3367
* | BUG: ma.masked_values does not shrink mask if requestedJonathan Helmus2015-10-201-0/+5
|/ | | | | | | | When called with the shrink parameter set to False, np.ma.masked_values will create a False filled array mask and not shrink the mask. Previously the mask would be shrunk to a single False scalar. closes #2674
* Merge pull request #6432 from jjhelmus/fix_ma_putahaldane2015-10-121-0/+14
|\ | | | | BUG: ma.put expands nomask
| * BUG: ma.put expands nomaskJonathan Helmus2015-10-121-0/+14
| | | | | | | | | | | | | | Previously when put was used on a MaskedArray with nomask the mask would be incorrectly set to the mask of the values argument. closes #6425
* | ENH: improve worst case of ma.clump_maskedJulian Taylor2015-10-081-0/+20
|/ | | | | | The worst case of alternating masked iterated all boundaries and sliced half away, improve this by only iterating the needed half of the boundary index array.
* Merge pull request #6094 from astrofrog/fix-gh-6019ahaldane2015-10-041-0/+36
|\ | | | | BUG: Fixed a bug with string representation of masked structured arrays
| * BUG: Fixed string representation of mvoid with multi-dimensional columnsThomas Robitaille2015-10-041-0/+36
| | | | | | | | | | This fixes a bug that caused the string representation of masked structured array rows with multi-dimensional columns to fail (numpy/numpy#6019), and includes a regression test. Since __repr__ suffered from a similar bug, and since previously __repr__ returned the same as __str__ for mvoid, we now set __repr__ to reference the same method as __str__.
* | BUG: numpy.ma.round works on zero dimensional arraysJonathan Helmus2015-10-021-0/+25
| | | | | | | | | | | | | | numpy.ma.round returns a scalar or np.ma.masked when called with a zero dimensional array. This behavior is consistent with numpy.round. closes #2244
* | BUG: numpy.ma functions can be called with only keyword argumentsJonathan Helmus2015-09-241-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | numpy.ma.empty, zeros, ones, etc can be called using only keyword arguments without a positional argument. Previously a single positional argument was required. For example: np.ma.zeros(shape=(10, )) closes #6106
* | BUG: fix use of undefined ‘unicode’ in Python 3Thomas Robitaille2015-08-221-1/+6
| |
* | BUG: fix use of undefined ‘numpy’ variableThomas Robitaille2015-08-211-0/+9
| |
* | STY,MAINT: Run pyflakes and pep8 on numpy/ma/tests/*.Charles Harris2015-07-255-236/+253
|/ | | | | | | | Also fix "*" imports. The formatting of test arrays is not fixed for multiple spaces following "," and other violations that are common in tests. To be precise, E241 and E201 are added to the errors that are excluded.
* BUG: automatically convert recarray dtype to np.recordAllan Haldane2015-06-191-0/+26
| | | | | | | | | | | | Viewing an ndarray as a np.recarray now automatically converts the dtype to np.record. This commit also fixes assignment to MaskedArray's dtype attribute, fixes the repr of recarrays with non-structured dtype, and removes recarray.view so that viewing a recarray as a non-structured dtype no longer converts to ndarray type. Fixes #3581
* BUG Ensure masked object arrays can always return single items.Marten van Kerkwijk2015-06-171-0/+12
| | | | | | | | | | | | | | | | | | | | For a masked array holding objects that themselves are arrays, when selecting a single item, it is treated as if it were a slice of the array and an attempt is made to set its mask. This was always a bug, but it become visible with a recent change to `MaskedArray.__getitem__` (gh-4586) where it is attempted to change the shape of the mask. With this PR, this case gets special treatment in that the object is made into a Masked Array with a full set mask. (A previous attempt to do the perhaps more logical think and just return `masked` caused quite a few errors in astropy.io.votable; it seemed it was not worth breaking backwards compatibility that much). Test case that now works but used to fail: ``` mx1 = MaskedArray([1.], mask=[True]) mx2 = MaskedArray([1., 2.]) mx = MaskedArray([mx1, mx2], mask=[False, True]) mx[0] ```
* BUG Allow subclasses in MaskedArray ufuncs -- for non-ndarray _dataMarten van Kerkwijk2015-06-162-10/+53
|
* MAINT: add __array_priority__ special case to masked array binary opsNathaniel J. Smith2015-06-131-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | ndarray special methods like __add__ have a special case where if the right argument is not an ndarray or subclass, and it has higher __array_priority__ than the left argument, then we return NotImplemented and let the right argument handle the operation. ufuncs have traditionally had a similar but different special case, where if it's a 2 input - 1 output ufunc, and the right argument is not an ndarray (exactly, subclasses don't count), and when converted to an ndarray ends up as an object array (presumably b/c it doesn't have a meaningful coercion route, though who knows), and it has a higher __array_priority__ than the left argument AND it has a __r<operation>__ attribute, then they return NotImplemented. In practice this latter special case is not used by regular ndarrays, b/c anytime it would need to be triggered, the former special case triggers first and the ufunc is never called. However, numpy.ma did not have the former special case, and was thus relying on the ufunc special case. This commit adds the special case to the numpy.ma special methods directly, so that they no longer depend on the quirky ufunc behaviour. It also cleans up the relevant test to things that actually should be true in general, instead of just testing some implementation details.
* Merge pull request #4586 from mhvk/ma/subclass-item-setting-gettingCharles Harris2015-06-032-5/+131
|\ | | | | ENH: Let MaskedArray getter, setter respect baseclass overrides
| * ENH: Let MaskedArray getter, setter respect baseclass overridesMarten van Kerkwijk2015-04-222-5/+131
| |
* | BUG: setdiff1d return dtypeChristian Brodbeck2015-05-071-0/+2
| | | | | | | | | | Fixes #5846 (If called with an empty array as first argument, the returned array had dtype bool instead of the dtype of the input array)
* | Merge pull request #5703 from ddasilva/ddasilva/compress_rowcolsJaime2015-05-041-5/+117
|\ \ | | | | | | ENH: Improve np.ma.compress_rowcols() performance, ENH: add compress_nd()
| * | ENH: Introduce np.ma.compress_nd(), generalizes np.ma.compress_rowcols()Daniel da Silva2015-05-031-5/+117
| |/ | | | | | | Provides a way to supress slices along an abitrary tuple of dimensions.
* | BUG: Fix `numpy.ma.where` to be consistent with unmasked version.John Kirkham2015-05-021-0/+7
| | | | | | | | Closes #5679.
* | TST: Add test for fix to issue #2972Gerrit Holl2015-05-021-0/+9
| | | | | | | | | | | | Add a test to TestMaskedArrayFunctions to verify that a masked structures array created with masked_where has a structured mask. The mask was previously unstructured, leading to bug #2972.
* | TST: Test that masked array addition works when dtype=objectLev Abalkin2015-04-231-0/+6
|/ | | | See issue #4452.
* Use Python 2.6 compatible assertions in tests.Alexander Belopolsky2015-03-301-2/+2
|