summaryrefslogtreecommitdiff
path: root/numpy/compat
Commit message (Collapse)AuthorAgeFilesLines
* BUG: fix the method for checking local files (#23728)Hongyang Peng2023-05-092-1/+12
| | | | | | BufferedReader and BufferedWriter cannot be used to determine local files. For example, users can implement CustomFile to operate on OSS files, and then use BufferedReader(CustomFile) to achieve the buffered effect. But fileno method can do it.
* MAINT: Move _inspect and _pep440 from compat to _utilsSebastian Berg2022-11-253-680/+3
| | | | | Note that unfortunately, compat does expose _inspect as well, so the import remains (just the definition place moves).
* PERF: Remove numpy.compat._pep440 from default importsPieter Eendebak2022-08-041-1/+0
| | | | | The submoudle numpy.compat._pep440 is removed from the default import of numpy to reduce the import time. See #22061
* MAINT: Replace LooseVersion by _pep440.Charles Harris2022-02-052-0/+488
| | | | | | | | LooseVersion is provided by Python distutils, which is going away in 3.12. This PR vendors _pep440 from scipy and uses it as a replacement. Numpy distutils is not touched, replacing LooseVersion in that package was considered too risky, and numpy distutils will need to go away when Python distutils does.
* ENH: provide a convenience function to replace npy_load_module (#20395)Matti Picus2021-11-191-1/+3
| | | | | | | `load_module` is deprecated since python 3.4 and will be removed in python 3.12. Use `exec_module` instead. Provide a convenience function in `distutils.misc_utils` instead of `npy_load_module` from `compat.py3k`.
* MAINT: Remove unused imports and unreachable code (#18762)Elisha Hollander2021-07-071-4/+0
| | | * Remove unnecessary imports and minor fixes
* DOC: Add a note that one should preferably use `contextlib.nullcontext`Bas van Beek2020-12-051-0/+3
|
* MAINT: Cleanup compatibility code for pathlibEric Wieser2020-10-101-5/+4
| | | | `Path` can now never be none, and `PurePath` is not used and not in `__all__`.
* MAINT: py3k: remove os.fspath and os.PathLike backports (#17473)Wei Yang2020-10-101-51/+2
| | | | | Since we no longer support Python 3.5 and below, this code is unreachable. As with the rest of `py3k.py`, we leave behind the aliases to prevent breaking downstream code.
* Mark tests as a subpackage rather than data.Hameer Abbasi2020-05-061-1/+1
|
* Merge pull request #15011 from hmaarrfk/compat_cleanup_35Sebastian Berg2020-01-161-118/+51
|\ | | | | MAINT: cleanup compat.py3k.py
| * MAINT: cleanup compat.py3k.pyMark Harfouche2020-01-031-118/+51
| |
* | MAINT: Remove implicit inheritance from object class (#15236)Jon Dufresne2020-01-051-1/+1
|/ | | | | | | 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-034-8/+0
| | | | | As numpy is Python 3 only, these import statements are now unnecessary and don't alter runtime behavior.
* Fix typos, via a Levenshtein-style correctorBrian Wignall2019-12-191-1/+1
|
* DOC: add a more useful comment to compat.py3k.pyMark Harfouche2019-11-291-3/+9
|
* DEV: cleanup imports and some assignments (from LGTM)mattip2019-03-171-2/+1
|
* MAINT: Move pickle import to numpy.compatCharles Harris2019-02-211-3/+8
| | | | | | | The pickle module was being imported from numpy.core.numeric. It was defined there in order to use pickle5 when available in Python3 and cpickle in Python2. The numpy.compat module seems a better place for that.
* MAINT: Use list and dict comprehension when possible (#12445)Roman Yurchak2018-12-011-3/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * Use list comprehension * More list comprehension migration * Revert key copying in dict * A few more fixes * More reverts * Use dict comprehension * Fix dict comprehension * Address review comments * More review comments * Fix for empty unpacking of zip(* * Revert zip(* unpacking altogether * Fix dict copying * More simplifications
* ENH: Add support for third-party path-like objects by backporting os.fspathEric Wieser2018-10-121-3/+67
|
* MAINT: Close the file if any unexpected errors occur within memmapEric Wieser2018-09-231-1/+24
|
* MAINT: Remove all uses of run_module_suite.Charles Harris2018-04-061-5/+1
| | | | | That function is nose specific and has not worked since `__init__` files were added to the tests directories.
* TST: Add numpy/compat/testsCharles Harris2018-03-241-2/+2
| | | | | These tests were not included in the `setup.py` file and consequently not available in the installed numpy for testing.
* TST, MAINT: Add `__init__.py` files to tests directories.Charles Harris2017-08-061-0/+0
| | | | | | | | This allows pytest to run with duplicate test file names. Note that `python <path-to-test-file>` no longer works with this change, nor will a simple `pytest numpy`, because numpy is imported from the numpy repository. However, `python runtests.py` and `>>> numpy.test()` are still available.
* MAINT: Rearrange files in numpy/testing module.Charles Harris2017-07-041-1/+1
| | | | | | | | | | | | | | | | | The aim here is to separate out the nose dependent files prior to adding pytest support. This could be done by adding new files to the general numpy/testing directory, but I felt that it was to have the relevant files separated out as it makes it easier to completely remove nose dependencies when needed. Many places were accessing submodules in numpy/testing directly, and in some cases incorrectly. That presented a backwards compatibility problem. The solution adapted here is to have "dummy" files whose contents will depend on whether of not pytest is active. That way the module looks the same as before from the outside. In the case of numpy itself, direct accesses have been fixed. Having proper `__all__` lists in the submodules helped in that.
* BUG: import full module path in npy_load_moduleJonathan Helmus2016-10-121-1/+1
| | | | | | | | Use the full module path when importing importlib.machinery for use in the npy_load_module function. Just importing importlib is not sufficient in certain cases, for example Python 3.4. closes #8147
* MAINT,DOC: add to compat.py3k a function to load modules. Fix some doc for ↵bertrand2016-07-171-2/+59
| | | | f2py.compile (issue #7683)
* ENH: Add support for pathlib.Path objects to save/load functionsWendell Smith2016-04-061-1/+12
|
* DOC: Fix more typos in docs and comments.Dongjoon Hyun2016-02-251-1/+1
|
* MAINT: Include from __future__ boilerplate in some files missing it.Charles Harris2015-12-051-0/+2
| | | | | Some newer *.py files are missing the `from __future__` boilerplate that helps assure Python2 and Python3 compatibility.
* TST: pass sys.argv to run_module_suite by defaultJulian Taylor2014-09-041-1/+5
| | | | | allows passing flags like --pdb to test files also add call to files where its missing
* STY: Minor PEP8 fixes.Charles Harris2014-08-012-2/+1
|
* BUG: Fix bugs in unused code paths.Charles Harris2014-08-012-57/+30
| | | | | | | | | The `getargspec` needed to import the disassembler to support parsing tuple arguments. Since numpy never uses those, the corresponding code is deleted and an TypeError raised if such arguments are encountered. Also fix the unused formatargs function so it does not require the string module.
* FIX isfileobj accepts write-mode files under PY3Olivier Grisel2014-06-302-1/+20
|
* ENH: export py3k.integer_types from numpy.compatChristoph Gohlke2013-09-071-1/+2
|
* STY: Giant comma spacing fixup.Charles Harris2013-08-181-1/+1
| | | | | | | 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.
* 2to3: Apply unicode fixer.Charles Harris2013-04-211-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* 2to3: Apply types fixer.Charles Harris2013-04-141-1/+1
| | | | | | | | | | | | | | | | | | | | Python 3 removes the builtin types from the types module. The types fixer replaces such references with the builtin types where possible and also takes care of some special cases: types.TypeNone <- type(None) types.NotImplementedType <- type(NotImplemented) types.EllipsisType <- type(Ellipsis) The only two tricky substitutions are types.StringType <- bytes types.LongType <- int These are fixed up to support both Python 3 and Python 2 code by importing the long and bytes types from numpy.compat. Closes #3240.
* 2to3: Apply basestring fixer.Charles Harris2013-04-131-1/+4
| | | | | | | | | | | 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-1/+8
| | | | | | | | | | | | | | | | | | | 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/+1
| | | | | | | | | | | | | | | | | | | 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-064-10/+10
| | | | | | | Add `print_function` to all `from __future__ import ...` statements and use the python3 print function syntax everywhere. Closes #3078.
* 2to3: Use absolute imports.Charles Harris2013-03-283-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Merge pull request #3026 from charris/2to3-fix-printCharles Harris2013-03-014-0/+7
|\ | | | | 2to3: Put `from __future__ import division` in every python file.
| * 2to3: Put `from __future__ import division in every python file.Charles Harris2013-03-014-0/+7
| | | | | | | | | | | | | | | | 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: Apply `methodattrs` fixes.Charles Harris2013-03-011-1/+1
|/ | | | | Replaces old style `f.im_func` and `f.im_class` method attributes with `f.__func__` and `f.__class__`. Closes #3070.
* 2to3: Apply `funcattrs` fixer. Closes #3058.Charles Harris2013-02-281-4/+4
| | | | | This replaces the `b.func_xxxx` with newer `__xxxx__` attribute names For example, `f.__name__` replaces `f.func_name`
* DEP: Remove scons related files and code.Charles Harris2013-01-131-11/+0
| | | | | | | | | This removes files and code supporting scons builds. After this change numpy will only support builds using distutils or bento. The removal of scons has been discussed on the list several times and a decision has been made that scons support is no longer needed. This was originally discussed for numpy 1.7 and because the distutils and bento methods are still available we are skipping the usual deprecation period.
* BUG: Fix ticket #1990.Bryan Van de Ven2012-03-031-6/+19
| | | | | | | When an array is created from a sequence of numeric (boolean, int, float, complex) and string (bytes, str, unicode) values, the resulting array type is string, but only the string values were being used to choose the string length, leading to truncation of data.
* BUG:py3k: fix error with recarry. Patch by C. Gohlke. Closes #1843.Ralf Gommers2011-07-011-1/+1
|