summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
Commit message (Collapse)AuthorAgeFilesLines
...
* STY: Giant comma spacing fixup.Charles Harris2013-08-181-26/+26
| | | | | | | Run the 2to3 ws_comma fixer on *.py files. Some lines are now too long and will need to be broken at some point. OTOH, some lines were already too long and need to be broken at some point. Now seems as good a time as any to do this with open PRs at a minimum.
* BUG: fix np.median so it accepts array_like input. Clean up median tests.Ralf Gommers2013-08-171-0/+1
|
* MAINT: Separate nan functions into their own module.Charles Harris2013-08-121-334/+8
| | | | | | | | | | | | | | New files lib/nanfunctions.py and lib/tests/test_nanfunctions.py are added and both the previous and new nan functions and tests are moved into them. The existing nan functions moved from lib/function_base are: nansum, nanmin, nanmax, nanargmin, nanargmax The added nan functions moved from core/numeric are: nanmean, nanvar, nanstd
* ENH: implement median in terms of partitionJulian Taylor2013-08-121-12/+32
| | | | | | Partitioning is sufficient to obtain the median and is much faster. In the case of overwrite_input=True the resulting array will not be fully sorted anymore.
* BUG: Make np.insert check for out of bounds axis arguments.Félix Hartmann2013-08-021-1/+6
| | | | Also add test for IndexError exception when axis is out of bounds.
* BUG: Fix bug in np.insert when axis=-1Félix Hartmann2013-08-021-1/+1
|
* Link cumsum and diff to one another as theyre roughly the inverse of each otherNils Werner2013-07-241-1/+1
|
* DOC: Harmonize max and min docstrings with each otherendolith2013-05-171-8/+10
|
* DOC: Mention all min/max functions from all others, clarify differencesendolith2013-05-161-10/+28
|
* MAINT: Apply 2to3 idioms fixer.Charles Harris2013-05-021-2/+1
| | | | | | | | | | | | | | | | | | | The idioms fixer makes the following replacements. 1) int <- bool 2) comparison or identity of types <- isinstance 3) a.sort() <- sorted(a) There were two problems that needed to be dealt with after the application of the fixer. First, the replacement of comparison or identity of types by isinstance was not always correct. The isinstance function returns true for subtypes whereas many of the places where the fixer made a substitution needed to check for exact type equality. Second, the sorted function was applied to arrays, but because it treats them as iterators and constructs a sorted list from the result, that is the wrong thing to do. Closes #3062.
* Merge pull request #3280 from seberg/issue-3279seberg2013-04-271-1/+2
|\ | | | | BUG: np.insert must copy index array
| * BUG: np.insert must copy index arraySebastian Berg2013-04-271-1/+2
| | | | | | | | Otherwise it would do in-place changes to it. Fixes gh-3279.
* | 2to3: Apply the `numliterals` fixer and skip the `long` fixer.Charles Harris2013-04-131-0/+1
|/ | | | | | | | | | | | | | | | | | | The numliterals fixer replaces the old style octal number like '01' by '0o1' removes the 'L' suffix. Octal values were previously mistakenly specified in some dates, those uses have been corrected by removing the leading zeros. Simply Removing the 'L' suffix should not be a problem, but in some testing code it looks neccesary, so in those places the Python long constructor is used instead. The 'long' type is no longer defined in Python 3. Because we need to have it defined for Python 2 it is added to numpy/compat/np3k.py where it is defined as 'int' for Python 3 and 'long' for Python 2. The `long` fixer then needs to be skipped so that it doesn't undo the good work. Closes #3074, #3067.
* FIX: rename xrange to range in python 2Sebastian Berg2013-04-111-1/+4
| | | | | | np.delete abuses range to calculate start/stop/step and len. This would create potentially large intermediates if it was a list, so for numpy/lib/function_base.py and python < 3, use range = xrange.
* MAINT: np.delete keep old out of bound/negative index behaviorSebastian Berg2013-04-111-9/+23
|
* FIX: insert/delete fixes and warnings for non-integer indicesSebastian Berg2013-04-111-25/+43
|
* ENH: larger fixes for np.delete and np.insert functionsSebastian Berg2013-04-111-53/+147
| | | | | | | | | | | | | | | | | | There were several smaller to larger problems for these two functions, that this addresses: * delete did not handle out of bound values graciously (ignoring negative ones) * both were unnecessarily slow due to use of sets * insert did not handle unsorted indices correctly Further changes: * Add FutureWarning for boolean obj, so it can be handled similar to a boolean mask with indexing. * Add FutureWarning to remove inconsistent special cases for 0-d arrays (neither insertion nor deletion along an axis make sense for a scalar) * Allow insertion of an array with more then one element along axis when obj is a sequence with a single item. (i.e. array([1])). * Reintroduce speed optimization for scalar in insert that existed in 1.6.
* 2to3: Apply `print` fixer.Charles Harris2013-04-061-1/+1
| | | | | | | Add `print_function` to all `from __future__ import ...` statements and use the python3 print function syntax everywhere. Closes #3078.
* Merge pull request #460 from endolith/regex_formattingCharles Harris2013-04-031-1/+1
|\ | | | | DOC: Formatting fixes using regex
| * DOC: Used regex to find colons missing spaces which render wrong online, ↵endolith2013-03-191-1/+1
| | | | | | | | also other spacing or formatting mistakes
* | 2to3: Use absolute imports.Charles Harris2013-03-281-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new import `absolute_import` is added the `from __future__ import` statement and The 2to3 `import` fixer is run to make the imports compatible. There are several things that need to be dealt with to make this work. 1) Files meant to be run as scripts run in a different environment than files imported as part of a package, and so changes to those files need to be skipped. The affected script files are: * all setup.py files * numpy/core/code_generators/generate_umath.py * numpy/core/code_generators/generate_numpy_api.py * numpy/core/code_generators/generate_ufunc_api.py 2) Some imported modules are not available as they are created during the build process and consequently 2to3 is unable to handle them correctly. Files that import those modules need a bit of extra work. The affected files are: * core/__init__.py, * core/numeric.py, * core/_internal.py, * core/arrayprint.py, * core/fromnumeric.py, * numpy/__init__.py, * lib/npyio.py, * lib/function_base.py, * fft/fftpack.py, * random/__init__.py Closes #3172
* | 2to3: Replace xrange by range and use list(range(...)) where neededCharles Harris2013-03-271-2/+2
|/ | | | | | | | | | | | | | | In python3 range is an iterator and `xrange` has been removed. This has two consequence for code: 1) Where a list is needed `list(range(...))` must be used. 2) `xrange` must be replaced by `range` Both of these changes also work in python2 and this patch makes both. There are three places fixed that do not need it, but I left them in so that the result would be `xrange` clean. Closes #3092
* 2to3: Put `from __future__ import division in every python file.Charles Harris2013-03-011-0/+2
| | | | | | | | This should be harmless, as we already are division clean. However, placement of this import takes some care. In the future a script can be used to append new features without worry, at least until such time as it exceeds a single line. Having that ability will make it easier to deal with absolute imports and printing updates.
* Merge pull request #3047 from charris/2to3-callablenjsmith2013-02-281-1/+2
|\ | | | | 2to3: Fix callable.
| * 2to3: Fix callable.Charles Harris2013-02-281-1/+2
| |
* | 2to3: apply exec fixer results.Charles Harris2013-02-281-1/+1
|/ | | | This changes the `exec` command to the `exec` function.
* Update numpy/lib/function_base.pyAndreas Hilboll2013-02-171-1/+1
| | | fix percentile docstring
* BUG: Make nansum work with booleans.Charles Harris2013-02-121-1/+3
| | | | | | | | This broke when function_base._nannop tried to fill a boolean array with integer zeros, raising a 'safe_casting' error. It looks like nanargmax and nanargmin would also break, and were probably incorrect for booleans in any case. The fix is not to use fill values for boolean and integer dtypes. Previously that was only done for the integer dtypes.
* [FIX] preserve memory order in np.copy()Nathaniel J. Smith2012-10-011-2/+4
| | | | | This switches us back to the behaviour seen in numpy 1.6 and earlier, which it turns out that scikit-learn (and probably others) relied on.
* MAINT: Use linspace instead of arange in some examples.endolith2012-09-171-3/+3
| | | | | | The original code used arange with offsets and scaling to generate sample points. Using linspace simplifies the code and clarifies the intent.
* BUG: Fix for issues #378 and #392Han Genuit2012-09-071-6/+8
| | | | | | This should fix the problems with numpy.insert(), where the input values were not checked for all scalar types and where values did not get inserted properly, but got duplicated by default.
* Merge pull request #352 from HackerSchool12/bugfix808Travis E. Oliphant2012-07-171-13/+7
|\ | | | | BF bug #808
| * BUG: Ticket #808: Insert was not performing properly when an integer wasLoftie Ellis2012-07-151-13/+7
| | | | | | | | | | | | | | the argument passed to be used as the item to be insterted, and a list was passed as the positions. This was fixed by simply duplicating the item to be inserted so that it was a list of equal length and then control was passed to the already exsisting code to handel this case
* | Merge pull request #192 from rgommers/meshgrid3dTravis E. Oliphant2012-07-171-33/+106
|\ \ | |/ |/| Meshgrid enhancements (>2-D, sparse grids, matrix indexing)
| * STY: meshgrid: some minor changes to address review comments.Ralf Gommers2012-02-051-1/+1
| |
| * TST: meshgrid: test expected shapes for Cartesian and matrix indexing.Ralf Gommers2011-12-281-5/+11
| |
| * BUG: meshgrid: raise error on single input.Ralf Gommers2011-12-281-4/+5
| |
| * MAINT: clean up docstring and some minor items in meshgrid. Remove ndgrid.Ralf Gommers2011-12-131-42/+36
| |
| * ENH: enhance meshgrid to generate 3D grids, sparse grids, matrix indexing.Per A. Brodtkorb2011-12-131-34/+106
| |
* | DOC: merge doc wiki edits. A number of small edits in linalg and lib.Ralf Gommers2012-07-071-3/+8
| |
* | DOC: merge wiki edits. Add percentile to statistics routines (ML suggestion).Ralf Gommers2012-07-071-3/+4
| |
* | Remove maskna API from ndarray, and all (and only) the code supporting itNathaniel J. Smith2012-06-161-10/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original masked-NA-NEP branch contained a large number of changes in addition to the core NA support. For example: - ufunc.__call__ support for where= argument - nditer support for arbitrary masks (in support of where=) - ufunc.reduce support for simultaneous reduction over multiple axes - a new "array assignment API" - ndarray.diagonal() returning a view in all cases - bug-fixes in __array_priority__ handling - datetime test changes etc. There's no consensus yet on what should be done with the maskna-related part of this branch, but the rest is generally useful and uncontroversial, so the goal of this branch is to identify exactly which code changes are involved in maskna support. The basic strategy used to create this patch was: - Remove the new masking-related fields from ndarray, so no arrays are masked - Go through and remove all the code that this makes dead/inaccessible/irrelevant, in a largely mechanical fashion. So for example, if I saw 'if (PyArray_HASMASK(a)) { ... }' then that whole block was obviously just dead code if no arrays have masks, and I removed it. Likewise for function arguments like skipna that are useless if there aren't any NAs to skip. This changed the signature of a number of functions that were newly exposed in the numpy public API. I've removed all such functions from the public API, since releasing them with the NA-less signature in 1.7 would create pointless compatibility hassles later if and when we add back the NA-related functionality. Most such functions are removed by this commit; the exception is PyArray_ReduceWrapper, which requires more extensive surgery, and will be handled in followup commits. I also removed the new ndarray.setasflat method. Reason: a comment noted that the only reason this was added was to allow easier testing of one branch of PyArray_CopyAsFlat. That branch is now the main branch, so that isn't an issue. Nonetheless this function is arguably useful, so perhaps it should have remained, but I judged that since numpy's API is already hairier than we would like, it's not a good idea to add extra hair "just in case". (Also AFAICT the test for this method in test_maskna was actually incorrect, as noted here: https://github.com/njsmith/numpyNEP/blob/master/numpyNEP.py so I'm not confident that it ever worked in master, though I haven't had a chance to follow-up on this.) I also removed numpy.count_reduce_items, since without skipna it became trivial. I believe that these are the only exceptions to the "remove dead code" strategy.
* | Merge pull request #290 from mforbes/new-vectorize-cleanTravis E. Oliphant2012-06-121-141/+179
|\ \ | | | | | | ENH: Add kwarg support for vectorize (tickets #2100, #1156, and #1487) (clean)
| * | ENH: Add kwarg support for vectorize (tickets #2100, #1156, and #1487)Michael McNeil Forbes2012-05-311-141/+179
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a substantial rewrite of vectorize to remove all introspection and caching behaviour. This greatly simplifies the logic of the code, and allows for much more generalized behaviour, simultaneously fixing tickets #1156, #1487, and #2100. There will probably be a performance hit because caching is no longer used (but should be able to be reinstated if needed). As vectorize is a convenience function with poor performance in general, perhaps this is okay. Rather than trying to inspect the function to determine the number of arguments, defaults, and argument names, we just use the arguments passed on the call to determine the behaviour on each call. All tests pass and code is fully covered Fixes: Ticket #2100: kwarg support for vectorize - API: Optional excluded argument to exclude some args from vectorization. - Added documentation, examples, and coverage tests - Added additional coverage test and base case for functions with no args - Factored original behaviour into _vectorize_call - Some minor documentation and error message corrections Ticket #1156: Support vectorizing over instance methods - No longer an issue since everything is determined by the call. Ticket: #1487: result depends on execution order - No longer caching, so the behaviour is as was expected. ENH: Simple cache for vectorize - Added simple cache to prevent vectorize from calling pyfunc twice on the first argument when determining the output types and added regression test. - Added documentation for excluded positional arguments. - Documentation cleanups. - Cleaned up variable names. ENH: Performance improvements for backward compatibility of vectorize. After some simple profiling, I found that the wrapping used to support the caching of the previous commit wasted more time than it saved, so I added a flag to allow the user to toggle. Moral: caching makes sense only if the function is expensive and is off by default. I also compared performance with the original vectorize and opted for keeping a cache of _ufunc if otypes is specified and there are no kwargs/excluded vars. This case is easy to implement, and allows users to reproduce (almost) the old performance characteristics if needed. (The new version is about 5% slower in this case). It would be much more complicated to add a similar cache in the case where kwargs are used, and since a wrapper is used here, the performance gain would be negligible (profiling showed that wrapping was a more significant slowdown than the extra call to frompyfunc). - API: Added cache kwarg which allows the user to toggle caching of the first result. - DOC: Added Notes section with a discussion of performance and a warning that vectorize should not be used for performance. - Added private _ufunc member to implement old-style of cache for special case with no kwargs, excluded, and with otypes specified. - Modified test case. Partially address ticket #1982 - I tried to use hasattr(outputs, '__len__') rather than isinstance(outputs, tuple) in order to allow for functions to return lists. This, however, means that strings will get vectorized over each character which breaks previous behaviour. Keeping old behaviour for now.
* | | remove unused variables from histogramddJake Vanderplas2012-06-111-2/+0
|/ /
* | DOC: merge wiki doc edits.Ralf Gommers2012-03-031-5/+5
| |
* | ENH: Support datetime64, timedelta64 in gradient. Allow array-like input.Ben Root2012-01-271-2/+11
|/
* ENH: Add function for adding docstrings to ufuncs.Chris Jordan-Squire2011-08-291-1/+7
|
* ENH: missingdata: Add maskna= parameter to np.copy and ndarray.copyMark Wiebe2011-08-271-2/+11
|
* ENH: missingdata: trying some more functions to see how they treat NAsMark Wiebe2011-08-271-0/+4
|