summaryrefslogtreecommitdiff
path: root/numpy/lib/npyio.py
Commit message (Collapse)AuthorAgeFilesLines
* MAINT: Make like= in Python functions strictPeter Andreas Entschev2020-11-161-14/+16
| | | | Only allow objects that implement __array_function__
* MAINT: Chaining exceptions in npyio.pyBijesh Mohan2020-09-161-5/+5
|
* ENH: Allow genfromtxt to unpack structured arrays (#16650)Andrew Eckart2020-09-111-5/+17
| | | | | | | | | | | | | * ENH: Allow genfromtxt to unpack structured arrays genfromtxt failed to transpose output when unpack=True and `dtype` was structured (or None). This patch resolves the issue by returning a list of arrays, as in `loadtxt`. Co-authored-by: Matti Picus <matti.picus@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net> Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* Merge pull request #17235 from hugovk/rm-old-codeCharles Harris2020-09-071-38/+8
|\ | | | | MAINT: Remove old PY_VERSION_HEX and sys.version_info code
| * MAINT: Remove old sys.version_info codeHugo2020-09-031-38/+8
| |
* | Merge pull request #17193 from eric-wieser/clean-compatSebastian Berg2020-09-031-1/+1
|\ \ | | | | | | MAINT: Remove some callers of functions in numpy.compat
| * | MAINT: Remove users of `numpy.compat.bytes`Eric Wieser2020-08-311-1/+1
| |/ | | | | | | Some more Python 2 cleanup.
* | MAINT, DOC: move informational files from numpy.doc.*.py to their *.rst ↵Matti Picus2020-09-021-1/+1
|/ | | | | | | | | counterparts (#17222) * DOC: redistribute docstring-only content from numpy/doc * DOC: post-transition clean-up * DOC, MAINT: reskip doctests, fix a few easy ones
* ENH: implement NEP-35's `like=` argument (gh-16935)Peter Andreas Entschev2020-08-281-3/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* MAINT: Avoid exception in NpzFile destructor if constructor raises ↵John Zwinck2020-07-211-2/+3
| | | | | | | | | | | | | | | | | BadZipFile (#15604) Previously if you gave an invalid zip file to NpzFile, zipfile_factory would raise BadZipFile and NpzFile.__exit__ would be called, which accessed members which had not yet been set, leading to a confusing second exception like this: zipfile.BadZipFile: File is not a zip file Exception ignored in: <function NpzFile.__del__ at 0x9b8ef0> Traceback (most recent call last): File "numpy/lib/npyio.py", line 230, in __del__ self.close() File "numpy/lib/npyio.py", line 221, in close if self.zip is not None: AttributeError: 'NpzFile' object has no attribute 'zip' This change makes __exit__ safe even when __init__ did not complete.
* DOC: Minor RST formatting. (#16792)Matthias Bussonnier2020-07-091-1/+1
| | | DOC: fixes to capitalization and header lines
* MAINT: Chain exceptions in npyio.py (gh16121)Kerem Hallaç2020-06-301-4/+6
| | | | | | this solution is related to the following issue #15986 Co-authored-by: Ross Barnowski <rossbar@berkeley.edu>
* MAINT: lib: A few PEP-8 fixes.Warren Weckesser2020-06-181-3/+6
|
* MAINT: lib: In loadtxt, move some code out of a try/finally block.Warren Weckesser2020-06-181-5/+8
| | | | | | In loadtxt, there is a try/finally block that ensures that the file is closed if it was opened in the function. Some code that did not need to be in that block was moved up, outside the try/finally block.
* MAINT: lib: In loadtxt, validate ndmin argument earlier.Warren Weckesser2020-06-181-3/+4
| | | | | | Validation of `ndmin` is moved to the beginning of the function, so we don't read the entire file only to raise an exception at the end because of a bad argument.
* MAINT: lib: Move some nested function definitions in loadtxt.Warren Weckesser2020-06-181-61/+70
| | | | | This change moves the nested function definitions in loadtxt to the top of the function body.
* DOC: Add missing bracket (gh-16051)Chunlin2020-04-251-1/+1
| | | Add missing closing brackets, script to generate the list in the PR gh-16051.
* DOC: Add converters example to the loadtxt docstring (gh-16043)Warren Weckesser2020-04-231-4/+15
| | | Co-Authored-By: Ross Barnowski <rossbar@berkeley.edu>
* STY: use 'yield from <expr>' for simple cases (#15444)Mike Taves2020-01-271-8/+4
| | | | | | | | | This PR uses simple cases of PEP 380 to rewrite: for v in g: yield v into: yield from <expr>
* ENH: Make use of ExitStack in npyio.pySeth Troisi2020-01-241-21/+12
|
* MAINT: Replace basestring with str.Charles Harris2020-01-231-5/+5
| | | | | | | This replaces basestring with str except in - tools/npy_tempita/ - numpy/compat/py3k.py
* MAINT: Cleanup python2 referencesSeth Troisi2020-01-211-1/+1
|
* [MAINT] Cleanup python2 sys.version checksSeth Troisi2020-01-201-40/+21
|
* MAINT: Remove implicit inheritance from object class (#15236)Jon Dufresne2020-01-051-3/+3
| | | | | | | Inheriting from object was necessary for Python 2 compatibility to use new-style classes. In Python 3, this is unnecessary as there are no old-style classes. Dropping the object is more idiomatic Python.
* 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.
* DOC: Fix typo in loadtxt and genfromtxtAnis Ladram2019-11-291-2/+2
|
* DOC: Fix typo in numpy.loadtxt documentationAnis Ladram2019-11-291-1/+1
| | | Parameter fname: generator must return byte strings for Python 3, not Python3k.
* MAINT: Remove uses of scalar aliasesEric Wieser2019-11-131-2/+2
| | | | Relates to gh-6103
* Use filename (vs file name) consistentlyStefan van der Walt2019-10-151-8/+8
|
* Tidy up savez keys-as-file-names languageStefan van der Walt2019-10-151-20/+8
|
* DOC: edited numpy.savez docstring note to be more specificDmytro2019-10-151-4/+13
| | | | | | | Note states that dictionary keys are stored as file names and may undergo unintended changes when they are not recognized as valid file names. In such cases the keys must be properly encapsulated and escaped to avoid being changed.
* DOC: added note to docstring of numpy.savezDmytro2019-10-151-0/+5
| | | | | | Note indicates that when used with dictionaries, savez will remove leading "/" in dictionary keys. See #9265
* Merge remote-tracking branch 'upstream/master' into fix-if-fieldsEric Wieser2019-08-191-317/+372
|\
| * DOC:Add example to clarify "numpy.save" behavior on already open file #10445 ↵Omar Merghany2019-08-161-1/+12
| | | | | | | | | | (#14070) * DOC:Add example to clarify "numpy.save" behavior on already unclosed file
| * fixes StopIteration error for empty file with skip_header > 0Maxwell Aladago2019-08-111-5/+6
| |
| * BUG: Fix file-like object check when saving arraysLuis Pedro Coelho2019-07-201-2/+2
| | | | | | | | For writing arrays, only the ``write`` method is necessary.
| * Merge branch 'master' into force-zip64Charles Harris2019-06-261-0/+22
| |\
| | * Merge pull request #13222 from kritisingh1/patch1Matti Picus2019-06-101-0/+22
| | |\ | | | | | | | | DOC: Document/ Deprecate functions exposed in "numpy" namespace
| | | * fix testskritisingh12019-06-071-4/+12
| | | |
| | | * Issue deprecation warningskritisingh12019-04-051-0/+14
| | | |
| * | | ENH: always use zip64, upgrade pickle protocol to 3mattip2019-05-231-2/+2
| |/ /
| * | Complete the exampleBharat123rox2019-05-121-0/+2
| | |
| * | Add suggested exampleBharat123rox2019-05-121-5/+9
| | |
| * | Merge upstream branch 'master' of https://github.com/numpy/numpy into ↵Bharat123rox2019-05-121-2/+3
| |\ \ | | | | | | | | | | | | fix-genfromtxt
| | * \ Merge pull request #13402 from eric-wieser/genfromtxt-defaultsSebastian Berg2019-05-111-1/+2
| | |\ \ | | | | | | | | | | DOC: Show the default value of deletechars in the signature of genfromtxt
| | | * | DOC: Show the default value of deletechars in the signature of genfromtxtEric Wieser2019-05-111-1/+2
| | | | |
| | * | | Merge pull request #13409 from seberg/fix-unicode-fmt-savetxtMatti Picus2019-04-261-1/+1
| | |\ \ \ | | | |/ / | | |/| | BUG: (py2 only) fix unicode support for savetxt fmt string
| | | * | BUG: (py2 only) fix unicode support for savetxt fmt stringSebastian Berg2019-04-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By now, all that is needed is to also allow unicode strings to pass through. Adds a test for the support which already succeeds on python3. Closes gh-4053 (replaces the old PR)
| * | | | Clarify deletechars in docsBharat123rox2019-04-241-2/+5
| | | | |
| * | | | Resolve confusion regarding hashtag in header line of csvBharat123rox2019-04-241-0/+1
| |/ / /