| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
|
|
|
|
|
|
| |
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.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
| |
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.
|
|
|
|
| |
Also add test for IndexError exception when axis is out of bounds.
|
| |
|
| |
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|\
| |
| | |
BUG: np.insert must copy index array
|
| |
| |
| |
| | |
Otherwise it would do in-place changes to it. Fixes gh-3279.
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
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.
|
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
| |
Add `print_function` to all `from __future__ import ...` statements
and use the python3 print function syntax everywhere.
Closes #3078.
|
|\
| |
| | |
DOC: Formatting fixes using regex
|
| |
| |
| |
| | |
also other spacing or formatting mistakes
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
| |
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.
|
|\
| |
| | |
2to3: Fix callable.
|
| | |
|
|/
|
|
| |
This changes the `exec` command to the `exec` function.
|
|
|
| |
fix percentile docstring
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
The original code used arange with offsets and scaling to generate
sample points. Using linspace simplifies the code and clarifies
the intent.
|
|
|
|
|
|
| |
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.
|
|\
| |
| | |
BF bug #808
|
| |
| |
| |
| |
| |
| |
| | |
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
|
|\ \
| |/
|/| |
Meshgrid enhancements (>2-D, sparse grids, matrix indexing)
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
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.
|
|\ \
| | |
| | | |
ENH: Add kwarg support for vectorize (tickets #2100, #1156, and #1487) (clean)
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
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.
|
|/ / |
|
| | |
|
|/ |
|
| |
|
| |
|
| |
|