summaryrefslogtreecommitdiff
path: root/numpy/lib/_iotools.py
Commit message (Collapse)AuthorAgeFilesLines
* MAINT: Remove users of `numpy.compat.bytes`Eric Wieser2020-08-311-1/+1
| | | | Some more Python 2 cleanup.
* Update numpy/lib/_iotools.pySebastian Berg2020-05-181-1/+2
| | | Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
* BUG: Fix default fallback in genfromtxtSebastian Berg2020-05-181-3/+5
| | | | | | | | | This affected (for example?) if the `dtype=object` was used without a converter, meaning that the default one is used. And this is currently the last one, which is `string_` (and thus bytes). Closes gh-16189
* MAINT: Extract a helper function from StringConverterEric Wieser2020-05-081-26/+30
| | | | The previous logic here was very hard to follow, as loop variables were being used after the loop ended, and being conditionally overwritten.
* STY: remove some parens in iterationEric Wieser2020-05-081-3/+3
|
* MAINT: remove unused private membersEric Wieser2020-05-081-2/+0
|
* STY: Remove some weird comments from iotoolsEric Wieser2020-05-081-42/+27
| | | | Also fix the docstring indentation
* MAINT: Remove duplicated code in iotools.pyEric Wieser2020-03-311-37/+22
|
* DEP: Do not allow "abstract" dtype conversion/creationSebastian Berg2020-02-061-6/+11
| | | | | | | | | | | | | | | | | | | | | | | These dtypes do not really make sense as instances. We can (somewhat) reasonably define np.dtype(np.int64) as the default (machine endianess) int64. (Arguably, it is unclear that `np.array(arr_of_>f8, dtype="f")` should return arr_of_<f8, but that would be very noisy!) However, `np.integer` as equivalent to long, is not well defined. Similarly, `dtype=Decimal` may be neat to spell `dtype=object` when you intend to put Decimal objects into the array. But it is misleading, since there is no special meaning to it at this time. The biggest issue with it, is that `arr.astype(np.floating)` looks like it will let float32 or float128 pass, but it will force a float64 output! Arguably downcasting is a bug in this case. A related issue is `np.dtype("S")` and especially "S0". The dtype "S" does make sense for most or all places where `dtype=...` can be passed. However, it is conceptionally different from other dtypes, since it will not end up being attached to the array (unlike "S2" which would be). The dtype "S" really means the type number/DType class of String, and not a specific dtype instance.
* MAINT: Replace basestring with str.Charles Harris2020-01-231-7/+7
| | | | | | | This replaces basestring with str except in - tools/npy_tempita/ - numpy/compat/py3k.py
* 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.
* MAINT: lib: Clean up in _iotools.pyWarren Weckesser2020-01-011-45/+6
| | | | | | | * Remove the unused function _to_filehandle(). * Remove conditional imports that handled Python 2. * Remove unused imports. * Fix a few line lengths (PEP 8).
* Merge remote-tracking branch 'upstream/master' into fix-if-fieldsEric Wieser2019-08-191-9/+15
|\
| * MAINT: address several reviewer commentsTyler Reddy2018-12-141-1/+9
| |
| * TST, DOC: enable refguide_checkTyler Reddy2018-12-141-9/+7
| | | | | | | | | | | | | | | | * 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
* | BUG: Don't allow extra fields to be added in genfromtxtEric Wieser2019-08-191-6/+5
| | | | | | | | Previously passing `dtype=[], names=['a']` would append an extra field, even though `dtype=['a'], names=['b', 'c']` does not.
* | BUG: Fix crash on genfromtxt with nested empty structured arrayEric Wieser2019-08-191-1/+1
|/ | | | Previously this would fail with `ValueError: could not assign tuple of length 2 to structure with 3 fields.`, now it raises `NotImplementedError`.
* MAINT: Review F401,F841,F842 flake8 errors (unused variables and imports) ↵Roman Yurchak2018-12-061-1/+1
| | | | | | | | | | | | (#12448) * Review F401,F841,F842 flake8 errors (unused variables, imports) * Review comments * More tests in test_installed_npymath_ini * Review comments
* Use set litteralsRoman Yurchak2018-11-241-1/+1
|
* BUG: delimiter/comments in genfromtxt should be encodedAllan Haldane2018-05-301-0/+4
| | | | Fixes #11028
* MAINT: Various minor code cleanups.Charles Harris2017-11-241-2/+2
| | | | Minor cleanups of old code to reflect more modern usage.
* MAINT: Refactor some code in npyio.py.Charles Harris2017-11-211-13/+35
|
* ENH: Add encoding option to numpy text IO.Julian Taylor2017-11-211-33/+29
| | | | | | | | | | | This modifies loadtxt and genfromtxt in several ways intended to add unicode support for text files by adding an `encoding` keyword to np.load, np.genfromtxt, np.savetxt, and np.fromregex. The original treatment of the relevant files was to open them as byte files, whereas they are now opened as text files with an encoding. When read, they are decoded to unicode strings for Python3 compatibility, and when written, they are encoded as specified. For backward compatibility, the default encoding in both cases is latin1.
* MAINT: Stop using the undocumented coercion-then-downcast feature of subdtypeEric Wieser2017-08-051-1/+1
|
* MAINT: Remove asbytes where a b prefix would sufficeEric Wieser2017-03-251-13/+13
| | | | | | | | Since we only need to support python 2, we can remove any case where we just pass a single string literal and use the b prefix instead. What we can't do is transform asbytes("tests %d" % num), because %-formatting fails on bytes in python 3.x < 3.5.
* DOC: There's a name for {False, True}, and it's "bool"Eric Wieser2017-03-231-2/+3
|
* DEP: Fix escaped string characters deprecated in Python 3.6.Charles Harris2016-12-141-1/+1
| | | | | | | In Python 3.6 a number of escape sequences that were previously accepted -- for instance "\(" that was translated to "\\(" -- are deprecated. To retain the previous behavior either raw strings must be used or the backslash must be properly escaped itself.
* BUG: fix #4381: precision loss on string -> longdouble conversionAnne Archibald2015-08-281-0/+13
| | | | | | | | | | | | | | | Avoid going through python floats when converting string to longdouble. This makes it dramatically easier to produce full-precision long double numbers. Fixed are the constructor (np.longdouble("1.01")), np.fromfile, np.fromstring, np.loadtxt, and np.genfromtxt (and functions based on it). Also fixed is precision loss when using np.tofile. This also fixes #1481, poor handling of bad data in fromfile and fromstring. If the function strtod_l is not available, almost none of this will work, and many tests will fail.
* BUG: genfromtxt gave OverflorError for large integersThomas Robitaille2015-03-061-6/+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.
* DOC: Reconcile docstrings and function signatures where they disagreeRobert McGibbon2015-03-021-3/+3
| | | | | Fixed typos in docstrings were updated for functions where the parameter names in the docstring didn't match the function signature.
* MAINT: Make argument determination in NameValidator more precise.Charles Harris2015-01-231-3/+4
| | | | | | | The function was useing `'u' in case_sensitive` to detect `upper`. Make that more precise with `case_sensitive.startswith('u'). Raise ValueError if case_sensitive has unrecognized value.
* BUG: Closes #2917: numpy.lib._iotools.StringConverter.upgrade returnGarrett-R2014-11-301-2/+6
| | | | numpy.lib._iotools.StringConverter.upgrade should have a return value
* DOC: Fix typo in _iotools.py docstring.Charles Harris2014-07-311-1/+1
| | | | The error is in the StringConverter.upgrade docstring.
* STY: Make files in numpy/lib PEP8 compliant.Charles Harris2014-07-311-76/+93
| | | | The rules enforced are the same as those used for scipy.
* MAINT: Fixes for problems in numpy/lib revealed by pyflakes.Charles Harris2014-07-311-1/+1
| | | | | | 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.
* 2to3: Apply unicode fixer.Charles Harris2013-04-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | The unicode fixer strips the u from u'hi' and converts the unicode type to str. The first won't work for Python 2 and instead we replace the u prefix with the sixu function borrowed from the six compatibility package. That function calls the unicode constructor with the 'unicode_escape' encoder so that the many tests using escaped unicode characters like u'\u0900' will be handled correctly. That makes the sixu function a bit different from the asunicode function currently in numpy.compat and also provides a target that can be converted back to the u prefix when support for Python 3.2 is dropped. Python 3.3 reintroduced the u prefix for compatibility. The unicode fixer also replaces 'unicode' with 'str' as 'unicode' is no longer a builtin in Python 3. For code compatibility, 'unicode' is defined either as 'str' or 'unicode' in numpy.compat so that checks like if isinstance(x, unicode): ... will work properly for all python versions. Closes #3089.
* Merge pull request #3244 from charris/2to3-apply-zip-fixerCharles Harris2013-04-141-1/+1
|\ | | | | 2to3: Apply zip fixer.
| * 2to3: Apply zip fixer.Charles Harris2013-04-131-1/+1
| | | | | | | | | | | | | | | | | | | | 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 basestring fixer.Charles Harris2013-04-131-1/+1
|/ | | | | | | | | | | The basestring class is not defined in Python 3 and the fixer replaces it with str. In order to have a common code base we define basestring in numpy/compat/py3k.py to be str when the Python version is >= 3, otherwise basestring and import it where needed. That works for most cases, but there are a few files where the version dependent define needs to be in the file. Closes #3042.
* 2to3: Apply the `numliterals` fixer and skip the `long` fixer.Charles Harris2013-04-131-3/+3
| | | | | | | | | | | | | | | | | | | 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.
* 2to3: Apply `map` fixer.Charles Harris2013-04-101-1/+2
| | | | | | | | | | | | | | | | | | | In Python 3 `map` is an iterator while in Python 2 it returns a list. The simple fix applied by the fixer is to inclose all instances of map with `list(...)`. This is not needed in all cases, and even where appropriate list comprehensions may be preferred for their clarity. Consequently, this patch attempts to use list comprehensions where it makes sense. When the mapped function has two arguments there is another problem that can arise. In Python 3 map stops execution when the shortest argument list is exhausted, while in Python 2 it stops when the longest argument list is exhausted. Consequently the two argument case might need special care. However, we have been running Python3 converted versions of numpy since 1.5 without problems, so it is probably not something that affects us. Closes #3068
* 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 #3191 from charris/2to3-apply-imports-fixerCharles Harris2013-04-061-1/+5
|\ | | | | 2to3: Apply `imports` fixer.
| * 2to3: Apply `imports` fixer.Charles Harris2013-04-021-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Merge pull request #460 from endolith/regex_formattingCharles Harris2013-04-031-2/+3
|\ \ | |/ |/| DOC: Formatting fixes using regex
| * DOC: regex-assisted fixes of definition list formattingendolith2013-03-191-2/+3
| |
* | 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: Put `from __future__ import division in every python file.Charles Harris2013-03-011-1/+5
| | | | | | | | 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.
* BUG: genfromtxt: make comments=None work with spaces in strings.Ralf Gommers2012-07-111-3/+8
|