summaryrefslogtreecommitdiff
path: root/numpy/lib/tests/test_io.py
Commit message (Collapse)AuthorAgeFilesLines
* MAINT: Simplify some tests using temppath context manager.Charles Harris2015-12-261-55/+31
| | | | | | | | | | | | | | | | | | | | | | | | 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: Use temppath in test_not_closing_opened_fid.Charles Harris2015-12-201-21/+12
| | | | | The test is in numpy/lib/tests/test_io.py. This commit is intended as a demonstration of using temppath.
* MAINT: Replace assert with assert_(...) in some tests.Charles Harris2015-12-101-3/+3
|
* TST: attempt to make test_load_refcount deterministicNathaniel J. Smith2015-10-281-6/+11
| | | | | | Use a different strategy to detect whether np.load creates cycles. Fixes gh-6571, I hope.
* STY: PEP8 and pyflakes fixes for numpy/lib/testsCharles Harris2015-07-251-82/+73
|
* BUG: Fix imports in test_io.py and test_recfunctions.py.Charles Harris2015-07-041-7/+9
| | | | | | | | | Those test functions were incorrectly importing test functions from numpy/ma/testutils that were actually not defined there, but rather in numpy/testing. That did not cause an error when testutils was '*' importing all the test functions, but it was deceptive as some of the functions might appear to support masked arrays when they do not.
* ENH: Multiple comment tokens in loadtxtJoseph Martinot-Lagarde2015-04-221-3/+37
|
* BUG: loadtxt fails with complex data in Python 3.Charles Harris2015-03-111-0/+8
| | | | | | | | | | | The problem is that the Python complex type constructor only accepts a pair of numbers or a string, unlike other numeric types it does not work with byte strings. The numpy error is subtle, as loadtxt opens the file in the default text mode, but then converts the input lines to byte strings when they are split into separate values. The fix here is to convert the values back to strings in the complex converter. Closes #5655.
* BUG: genfromtxt gave OverflorError for large integersThomas Robitaille2015-03-061-2/+27
| | | | | | | | | Fix StringConverter to avoid OverflowError in genfromtxt. Before, int(2**66) would work (and return a ‘long’) but then np.array([2**66], dtype=np.integer) would not work and return an OverflowError which would propagate to genfromtxt. This commit fixes this by ensuring testing in advance whether an OverflowError will occur. In addition, this adds an explicit np.int64 entry on systems where integer means int32. Values larger than 2**63-1 will be cast as float. This includes a regression test and adds an entry to the release notes.
* TST: Make loadtxt able to load floats as hex strings.Charles Harris2015-02-131-0/+13
| | | | The strings must be produced by the python float.hex method.
* Merge pull request #5495 from charris/cleanup-gh-4649Charles Harris2015-01-241-2/+26
|\ | | | | BUG: Fix genfromtext NameValidator arguments passed to easy_dtype.
| * TST: Fix bug in test_dtype_with_converters_and_usecols.Charles Harris2015-01-231-2/+2
| | | | | | | | | | | | | | The case_sensitive argument to np.recfromcsv has a default value of 'lower'. That value was not previously correctly passed on, but is now, so the previous expected values in this test were incorrectly upper cased.
| * BUG: Fix genfromtext NameValidator arguments passed to easy_dtype.Alan Briolat2015-01-231-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | np.genfromtxt validates field names twice: once in genfromtxt and once in easy_dtype. Whilst the arguments to genfromtxt are used in the first validation, they aren't passed to easy_dtype (which is used only when dtype != None) and therefore in this case the default validation (strip non-alphanum, replace spaces) gets confusingly applied, ignoring genfromtxt's arguments. This patch adds fixes genfromtxt by passing the appropriate arguments onwards to easy_dtype. That is probably the least invasive way to fix the issue.
* | ENH: genfromtxt: Change 'nrows' to 'max_rows'.Warren Weckesser2015-01-231-12/+40
| |
* | ENH:Add keyword nrows to genfromtxt.styr2015-01-231-0/+26
|/ | | | | | | | | | This allows one to specify the maximum number of row processed in in a call. The new functionality allows for reading more complex data formats. For instance, multiple calls can be used to read in multiple arrays stored in a single file. Closes #5084. Closes #5093.
* TST: Add test for loadtxt with None as string type.Charles Harris2015-01-231-0/+8
|
* TEST: added test of BagObjWendell Smith2014-11-181-0/+11
|
* Merge pull request #5006 from dhomeier/ioconv_usecolsJulian Taylor2014-08-271-0/+15
|\ | | | | | | BUG: fix genfromtxt check of converters when using usecols
| * BUG: fix genfromtxt check of converters when using usecolsDerek Homeier2014-08-271-0/+15
| | | | | | | | | | | | fixes an issue reported by Adrian Altenhoff where user-supplied converters in genfromtxt were not tested with the right first_values when also specifying usecols.
* | BUG: io: genfromtxt did not handle filling_values=0 correctly. Closes gh-2317.Warren Weckesser2014-08-151-0/+10
| |
* | Move tempdir context manager to numpy.testing.utilsOlivier Grisel2014-06-301-12/+4
|/
* TST: add a format 2.0 roundtrip testJulian Taylor2014-06-031-0/+7
|
* BUG: fix test deleting temporary file before using it on windowsJulian Taylor2014-06-031-22/+28
| | | | | | | The version check was not valid for python3, though the whole logic can be removed with a finally clause. This requires that the savez tests need to cleanup the NpyzFile results which still hold an open file descriptor.
* ENH: Better error w/ line num for bad column count in np.loadtxt()Daniel da Silva2014-04-051-2/+13
| | | | Resolves #2591. Adds more explicit error handling in line parsing loop.
* TST: Added regression test for recfromcsv dtype error, as suggested by @hpauljYaron de Leeuw2014-02-281-0/+8
|
* Merge pull request #4273 from juliantaylor/test-file-leakJulian Taylor2014-02-091-7/+8
|\ | | | | TST: clean up tempfile in test_closing_zipfile_after_load
| * TST: clean up tempfile in test_closing_zipfile_after_loadJulian Taylor2014-02-081-7/+8
| |
* | TST: fix test_io.TestSavezLoadJulian Taylor2014-02-081-1/+1
|/
* ENH: remove insecure mktemp useJulian Taylor2014-02-061-8/+16
| | | | | mktemp only returns a filename, a malicous user could replace it before it gets used.
* TST: Increase test coverage of numpy.save/load roundtripsOlivier Grisel2013-11-261-6/+36
|
* MAINT: io: handle a bad fmt argument in savetxt by raising a ValueError.Warren Weckesser2013-10-201-0/+4
|
* STY: Make numpy/lib/test/*.py PEP8 compliant.Charles Harris2013-09-031-129/+110
| | | | | | | Run autopep8 over the test files in numpy/lib/test and make fixes to the result. Also remove Python5 workaround.
* STY: Giant comma spacing fixup.Charles Harris2013-08-181-2/+2
| | | | | | | 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.
* TST: Test that savetxt works with objects having a write method.Daniel2013-08-151-0/+12
|
* MAINT: Remove uses of the WarningManager class.Charles Harris2013-07-121-26/+10
| | | | | | | | | | | | WarningManager was a workaround for the lack of the with statement in Python versions < 2.6. As those versions are no longer supported it can be removed. Deprecation notes are added to WarningManager and WarningMessage, but to avoid a cascade of messages in third party apps, no warnings are raised at this time, that can be done later. Closes #3519.
* BUG: Make np.load transfer file ownership to the returned NpzFile.Charles Harris2013-06-221-1/+13
| | | | | | | This assures that when the loaded file is closed it also closes the file descriptor, avoiding a resource warning in Python3. Closes #3457.
* adjust the optimal IO buffer size for npz filesBartosz Telenczuk2013-06-121-5/+3
|
* BUG: fix loading large npz files (fixes #2922)Bartosz Telenczuk2013-06-121-1/+18
|
* 2to3: Apply zip fixer.Charles Harris2013-04-131-2/+2
| | | | | | | | | | In Python 3 zip returns an iterator instead of a list. Consequently, in places where an iterator won't do it must be enclosed in list(...). Lists instead of iterators are also used in array constructors as using iterators there usually results in an object array containing an iterator object. Closes #3094
* 2to3: apply `dict` fixer.Charles Harris2013-04-061-2/+2
| | | | | | | | | | | | | | | In Python3 `dict.items()`, `dict.keys()`, and `dict.values()` are iterators. This causes problems when a list is needed so the 2to3 fixer explicitly constructs a list when is finds on of those functions. However, that is usually not necessary, so a lot of the work here has been cleaning up those places where the fix is not needed. The big exception to that is the `numpy/f2py/crackfortran.py` file. The code there makes extensive use of loops that modify the contents of the dictionary being looped through, which raises an error. That together with the obscurity of the code in that file made it safest to let the `dict` fixer do its worst. Closes #3050.
* 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.
* 2to3: Apply `imports` fixer.Charles Harris2013-04-021-223/+238
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The `imports` fixer deals with the standard packages that have been renamed, removed, or methods that have moved. cPickle -- removed, use pickle commands -- removed, getoutput, getstatusoutput moved to subprocess urlparse -- removed, urlparse moved to urllib.parse cStringIO -- removed, use StringIO or io.StringIO copy_reg -- renamed copyreg _winreg -- renamed winreg ConfigParser -- renamed configparser __builtin__ -- renamed builtins In the case of `cPickle`, it is imported as `pickle` when python < 3 and performance may be a consideration, but otherwise plain old `pickle` is used. Dealing with `StringIO` is a bit tricky. There is an `io.StringIO` function in the `io` module, available since Python 2.6, but it expects unicode whereas `StringIO.StringIO` expects ascii. The Python 3 equivalent is then `io.BytesIO`. What I have done here is used BytesIO for anything that is emulating a file for testing purposes. That is more explicit than using a redefined StringIO as was done before we dropped support for Python 2.4 and 2.5. Closes #3180.
* 2to3: Use absolute imports.Charles Harris2013-03-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | 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
* TST: Get rid of a ResourceWarning.Charles Harris2013-03-031-6/+15
| | | | | | | | I'm not sure this is the right fix, but test_closing_fid need to check that garbage collection will close a file that goes through a bunch of openings followed by dropping the reference. So the fix is to ignore warnings during the test. I'd just ignore ResourceWarning, but it does not look to be a built in warning in Python 2.7.
* 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.
* 2to3: Use modern exception syntax.Charles Harris2013-02-261-2/+2
| | | | Example: except ValueError,msg: -> except ValueError as msg:
* Fix `WindowsError: [Error 32]` in test_not_closing_opened_fid ↵cgohlke2012-07-161-0/+1
| | | | (test_io.TestSavezLoad)
* BUG: genfromtxt: make comments=None work with spaces in strings.Ralf Gommers2012-07-111-0/+3
|
* BUG: make genfromtxt work with comments=None. Closes Github issue 329.martingoodson2012-07-101-3/+5
|