summaryrefslogtreecommitdiff
path: root/numpy/lib/twodim_base.py
Commit message (Collapse)AuthorAgeFilesLines
* MAINT: Make like= in Python functions strictPeter Andreas Entschev2020-11-161-3/+15
| | | | Only allow objects that implement __array_function__
* ENH: implement NEP-35's `like=` argument (gh-16935)Peter Andreas Entschev2020-08-281-3/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR adds the implementation of NEP-35's like= argument, allowing dispatch of array creation functions with __array_function__ based on a reference array. * ENH: Add like= kwarg via __array_function__ dispatcher to asarray * ENH: Add new function for __array_function__ dispatching from C This new function allows dispatching from C directly, while also implementing the new `like=` argument, requiring only minimal changes to existing array creation functions that need to add support for that argument. * ENH: Add like= support to numpy.array The implementation uses array_implement_c_array_function, thus introducing minimal complexity to the original _array_fromobject code. * BUG: Fix like= dispatcher for np.full * ENH: Remove np.asarray like= dispatcher via Python np.asarray can rely on np.array's C dispatcher instead. * TST: Add some tests for like= argument Tests comprise some of the functions that have been implemented already: * np.array (C dispatcher) * np.asarray (indirect C dispatcher via np.array) * np.full (Python dispatcher) * np.ones (Python dispatcher) * ENH: Remove like= argument during array_implement_array_function * ENH: Add like= kwarg to ones and full * BUG: prevent duplicate removal of `like=` argument * ENH: Make `like=` a keyword-only argument * ENH: Use PyUnicode_InternFromString in arrayfunction_override Replace PyUnicode_FromString by PyUnicode_InternFromString to cache "like" string. * ENH: Check for arrayfunction_override import errors Check and handle errors on importing NumPy's Python functions * BUG: Fix array_implement_c_array_function error handling * ENH: Handle exceptions with C implementation of `like=` * ENH: Add `like=` dispatch for all asarray functions Using Python dispatcher for all of them. Using the C dispatcher directly on the `np.array` call can result in incorrect behavior. Incorrect behavior may happen if the downstream library's implementation is different or if not all keyword arguments are supported. * ENH: Simplify handling of exceptions with `like=` * TST: Add test for exception handling with `like=` * ENH: Add support for `like=` to `np.empty` and `np.zeros` * TST: Add `like=` tests for `np.empty` and `np.zeros` * ENH: Add `like=` to remaining multiarraymodule.c functions Functions are: * np.arange * np.frombuffer * np.fromfile * np.fromiter * np.fromstring * TST: Add tests for multiarraymodule.c functions with like= Functions are: * np.arange * np.frombuffer * np.fromfile * np.fromiter * np.fromstring * ENH: Add `like=` support to more creation functions Support for the following functions is added: * np.eye * np.fromfunction * np.genfromtxt * np.identity * np.loadtxt * np.tri * TST: Add `like=` tests for multiple functions Tests for the following functions are added: * np.eye * np.fromfunction * np.genfromtxt * np.identity * np.loadtxt * np.tri * TST: Reduce code duplication in `like=` tests * DOC: Document `like=` in functions that support it Add documentations for the following functions: * np.array * np.arange * np.asarray * np.asanyarray * np.ascontiguousarray * np.asfortranarray * np.require * np.empty * np.full * np.ones * np.zeros * np.identity * np.eye * np.tri * np.frombuffer * np.fromfile * np.fromiter * np.fromstring * np.loadtxt * np.genfromtxt * ENH: Add `like=` to numpy/__init__.pyi stubs * BUG: Remove duplicate `like=` dispatching in as*array Functions `np.asanyarray`, `np.contiguousarray` and `np.fortranarray` were dispatching both via their definitions and `np.array` calls, the latter should be avoided. * BUG: Fix missing check in array_implement_array_function * BUG: Add missing keyword-only markers in stubs * BUG: Fix duplicate keyword-only marker in array stub * BUG: Fix syntax error in numpy/__init__.pyi * BUG: Fix more syntax errors in numpy/__init__.pyi * ENH: Intern arrayfunction_override strings in multiarraymodule * STY: Add missing brackets to arrayfunction_override.c * MAINT: Remove arrayfunction_override dict check for kwarg * TST: Assert that 'like' is not in TestArrayLike kwargs * MAINT: Rename array_implement_c_array_function(_creation) This is done to be more explicit as to its usage being intended for array creation functions only. * MAINT: Use NotImplemented to indicate fallback to default * TST: Test that results with `like=np.array` are correct * TST: Avoid duplicating MyArray code in TestArrayLike * TST: Don't delete temp file, it may cause issues with Windows * TST: Don't rely on eval in TestArrayLike * TST: Use lambda with StringIO in TestArrayLike * ENH: Avoid unnecessary Py_XDECREF in arrayfunction_override * TST: Make TestArrayLike more readable * ENH: Cleaner error handling in arrayfunction_override * ENH: Simplify array_implement_c_array_function_creation * STY: Add missing spaces to multiarraymodule.c * STY: C99 declaration style in arrayfunction_override.c * ENH: Simplify arrayfunction_override.c further Remove cleanup label from array_implementation_c_array_function, simplifying the code. Fix unitialized variable warning in array_implementation_array_function_internal. * DOC: Use string replacement for `like=` documentation Avoid repeating the full text for the `like=` argument by storing it as a variable and using `replace` on each docstring. * DOC: Update `like=` docstring * TST: Test like= with array not implementing __array_function__ * TST: Add missing asanyarray to TestArrayLike * ENH: Use helper function for like= dispatching Avoid dispatching like= from Python implementation functions to improve their performance. This is achieved by only calling a dispatcher function when like is passed by the users. * ENH: Rename array_function_dispatch kwarg to public_api * BUG: Add accidentally removed decorator for np.eye back * DOC: Add set_array_function_like_doc function The function keeps Python files cleaner and resolve errors when __doc__ is not defined due to PYTHONOPTIMIZE or -OO . * DOC: Add mention to like= kwarg being experimental * TST: Test like= with not implemented downstream function * DOC: Fix like= docstring reference to NEP 35. * ENH: Prevent silent errors if public_api is not callable * ENH: Make set_array_function_like_doc a decorator * ENH: Simplify `_*_with_like` functions * BUG: Fix multiple `like=` dispatching in `require` * MAINT: Remove now unused public_api from array_function_dispatch Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
* BUG,DOC: Fix bad MPL kwarg.Ross Barnowski2020-07-161-1/+1
| | | | | Invalide kwarg to imshow causes failures in the plot directive for docs builds using MPL > v3.3
* DOC: rm matrix from triu docstring.Ross Barnowski2020-06-251-1/+1
| | | | | Replace "matrix" with "array" to avoid confusion re: np.matrix. Consistent with other np.tri\* functions.
* MAINT: Remove unnecessary 'from __future__ import ...' statementsJon Dufresne2020-01-031-2/+0
| | | | | As numpy is Python 3 only, these import statements are now unnecessary and don't alter runtime behavior.
* MAINT: lib: Clean up in twodim_base.py.Warren Weckesser2020-01-011-2/+2
| | | | * Remove unused imports.
* DOC: fix documentation of i and j for tri.hvy2019-07-241-1/+1
|
* BUG: further fixup to histogram2d dispatcher.Marten van Kerkwijk2019-06-201-1/+1
| | | | Now with tests....
* MAINT: check bins length in histogram2d_dispatcherStephan Hoyer2019-06-111-4/+11
|
* MAINT: fix histogram*d dispatchersStephan Hoyer2019-06-111-1/+7
| | | | fixes GH-13728
* DOC, TST: clean up matplotlib importsTyler Reddy2019-01-021-4/+2
| | | | | | * as requested by review in gh-12634, the vast majority of docstring matplotlib imports can be simplified to a single line
* DOC, TST: remove agg setting from docsTyler Reddy2019-01-021-1/+0
| | | | | | | * there is no longer any usage of "agg" backend switching in our docstrings because this backend is already activated in the refguide_check machinery
* TST, DOC: enable refguide_checkTyler Reddy2018-12-141-21/+26
| | | | | | | | * ported the refguide_check module from SciPy for usage in NumPy docstring execution/ verification; added the refguide_check run to Azure Mac OS CI * adjusted NumPy docstrings such that refguide_check passes
* ENH: set correct __module__ for objects in numpy's public APIStephan Hoyer2018-11-131-0/+6
| | | | | | | | | | | | | Fixes GH-12271 Tests verify that everything in ``dir(numpy)`` either has ``__module__`` set to ``'numpy'``, or appears in an explicit whitelist of undocumented functions and exported bulitins. These should eventually be documented or removed. I also identified a handful of functions for which I had accidentally not setup dispatch for with ``__array_function__`` before, because they were listed under "ndarray methods" in ``_add_newdocs.py``. I guess that should be a lesson in trusting code comments :).
* MAINT: set preferred __module__ for numpy functionsStephan Hoyer2018-10-231-1/+7
|
* ENH: __array_function__ support for np.lib, part 2/2 (#12119)Stephan Hoyer2018-10-221-0/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * ENH: __array_function__ support for np.lib, part 2 xref GH12028 np.lib.npyio through np.lib.ufunclike * Fix failures in numpy/core/tests/test_overrides.py * CLN: handle depreaction in dispatchers for np.lib.ufunclike * CLN: fewer dispatchers in lib.twodim_base * CLN: fewer dispatchers in lib.shape_base * CLN: more dispatcher consolidation * BUG: fix test failure * Use all method instead of function in assert_equal * DOC: indicate n is array_like in scimath.logn * MAINT: updates per review * MAINT: more conservative changes in assert_array_equal * MAINT: add back in comment * MAINT: casting tweaks in assert_array_equal * MAINT: fixes and tests for assert_array_equal on subclasses
* MAINT: Rename histogramdd's normed argument to density, to match histogramEric Wieser2018-07-081-4/+10
| | | | Fixes gh-4371
* ENH: Disable fuzzing on histogram boundariesEric Wieser2018-04-301-1/+1
| | | | | | | | | | Previously a fuzzy rounded comparison was used for the rightmost bin of histogramdd. It's not clear why this was done, and it resulted in surprising behavior. This also removes the restriction that bin edges must be floats, and allows integer arrays to be passed (and returned) Fixes gh-10864
* ENH: Add `order=` keyword to `np.eye()` (#9996)Danny Hermes2017-11-121-2/+7
| | | Fixes #9995
* MAINT: Don't internally use the one-argument whereEric Wieser2017-06-031-3/+4
| | | | nonzero is a clearer spelling
* DOC: Correct shape of edges in np.histogram2d (#8980)Importance of Being Ernest2017-04-231-2/+2
| | | | | If nx and ny are the bin counts (as stated in the bins argument's text), then the return H has indeed shape (nx, ny). However, the returned xedges and yedges will then have shape (nx+1,) and (ny+1,) respectively. Fixes #8979
* DOC: Improve histogram2d() example.wrwrwr2016-10-081-29/+17
| | | | Closes #8115.
* ENH: generalize rot90 with axes kwarg, move to function_base.py, and add testsDenis Alevi2016-03-201-57/+4
|
* ENH: Add generalized flip function and its testsEren Sezener2016-03-121-4/+4
|
* DOC: fix a number of reST formatting issues in docstrings.Ralf Gommers2016-02-131-2/+2
|
* DOC: Use print only as function when print_function is imported from __future__gfyoung2015-12-191-1/+1
| | | | Closes gh-6863.
* DOC: Updated docstring for histogram2d as suggested in issue #5538Åsmund Hjulstad2015-02-131-3/+5
| | | | Also, added unittest for [int, array] combination arguments
* BUG: Make diag, diagonal return 1-D arrays for matrix arguments.Charles Harris2015-01-041-2/+2
| | | | | | | | This is an ugly hack to preserve backwards compatibility for code that uses matrices. It is needed since both diag and diagonal have been changed to preserve subtypes otherwise. Note that a.diagonal() still returns matrices when a is a matrix.
* Improved PEP-8 complianceGarrett-R2014-12-081-0/+2
|
* BUG: Closes #2015: diag returns ndarrayGarrett-R2014-12-081-1/+1
| | | | | | | If x is a matrix, np.diag(x) and np.diagonal(x) now return matrices instead of arrays. Both of these cause x.diagonal() to be called. That means they return row vectors (just like x.flatten(), x.ravel(), x.cumprod(), etc.)
* Merge pull request #4929 from juliantaylor/charris-pep8-numpy-libCharles Harris2014-07-311-8/+8
|\ | | | | Charris pep8 numpy lib
| * MAINT: Fixes for problems in numpy/lib revealed by pyflakes.Charles Harris2014-07-311-8/+8
| | | | | | | | | | | | Some of those problems look like potential coding errors. In those cases a Fixme comment was made and the offending code, usually an unused variable, was commented out.
* | BUG: Avoid type promotion in tril and triu.Yotam Doron2014-07-291-2/+2
| |
* | BUG: Use `np.where` in np.triu/np.tril, fixes #4859jaimefrio2014-07-101-3/+6
|/ | | | | Replaces the current method to zero items, from multiplication to using `np.where`.
* STY: Use `.astype`'s `copy` kwarg in `np.tri`jaimefrio2014-05-271-4/+2
| | | | Replace an explicit type check with setting `copy=False` in call to `astype`.
* ENH: Replace exponentiation with cumulative product in np.vanderjaimefrio2014-03-311-25/+27
| | | | | Speeds calculation up by ~3x for 100x100 matrices, and by ~45x for 1000x1000
* ENH: use smallest integer for tri rangesJulian Taylor2014-03-271-2/+17
| | | | reduces buffer copy and comparison overhead for boolean outer product
* ENH: speed-up of triangular matrix functionsjaimefrio2014-03-251-21/+41
| | | | | | | | | | | | | | | * `np.tri` now produces less intermediate arrays. Runs about 40% faster for general dtypes, up to 3x faster for boolean arrays. * `np.tril` now does smarter type conversions (thanks Julian!), and together with the improvements in `np.tri` now runs about 30% faster. `np.triu` runs almost 2x faster than before, but still runs 20% slower than `np.tril`, which is an improvement over the 50% difference before. * `np.triu_indices` and `np.tril_indices` do not call `np.mask_indices`, instead they call `np.where` directly on a boolean array created with `np.tri`. They now run roughly 2x faster. * Removed the constraint for the array to be square in calls to `np.triu_indices`, `np.tril_indices`, `np.triu_indices_from` and `np.tril_indices_from`.
* DOC: Fix documentation of normed in histogram2d and histogramdd.Charles Harris2014-02-261-21/+18
| | | | | | | | | | The documentation misrepresented what happened, leaving out division by the total number of sample points. Also run spellcheck over function_base.py and twodim_base.py and break some long lines. Closes #2423.
* ENH: tril and triu broadcastingalex2014-02-241-2/+2
|
* Merge pull request #4316 from charris/fix-gh-4092seberg2014-02-181-3/+3
|\ | | | | DOC: Remove \n from strings in plot examples.
| * DOC: Remove \n from strings in plot examples.Charles Harris2014-02-171-3/+3
| | | | | | | | | | | | | | | | The \n occur in plot titles and mess up the generated html. An alternative fix would be to use a raw docstring or \\n, but here it looks simpler to just delete the problem. Closes #4092.
* | DOC: Document that fliplr only works on 2-D arrays.Charles Harris2014-02-161-3/+2
|/ | | | | | Docstring claimed 2-D was not required, but it is. Fix that. Closes #3332.
* Fix typo.Markus Roth2013-11-151-1/+1
|
* DOC: Spelling correction for numpy.diag see alsoChris Kerr2013-11-111-1/+1
|
* MAINT: lib: Use a consistent PEP8-compliant import style in twodim_base.py ↵Warren Weckesser2013-11-021-2/+4
| | | | and tests/test_twodim_base.py. Also make a couple more PEP8 tweaks.
* MAINT: lib: Add a 'See Also' section to the vander docstring, and make a few ↵Warren Weckesser2013-11-021-3/+7
| | | | more PEP8 tweaks.
* MAINT: lib: remove unused imports and PEP8 clean up in twodim_base.pyWarren Weckesser2013-11-021-7/+18
|
* ENH: lib: Rewrite vander: make it faster, and add an option to specify the ↵Warren Weckesser2013-11-021-14/+34
| | | | order of the powers (either decreasing or increasing).
* STY: Giant comma spacing fixup.Charles Harris2013-08-181-17/+17
| | | | | | | 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.