-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Numpy pre-release accommodations #700
Conversation
For
The neater fix, for |
For the trackvis reader, we could probably avoid nearly all the memory inflation by using the |
This suggestion would help - we could depend on |
nibabel/info.py
Outdated
@@ -209,4 +209,5 @@ def cmp_pkg_version(version_str, pkg_version_str=__version__): | |||
ISRELEASE = _version_extra == '' | |||
VERSION = __version__ | |||
PROVIDES = ["nibabel", 'nisext'] | |||
REQUIRES = ["numpy (>=%s)" % NUMPY_MIN_VERSION] | |||
REQUIRES = ["numpy (>=%s)" % NUMPY_MIN_VERSION, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need to use the bz2file.BZ2File
object instead of the the bz2.BZ2File
object, in openers
, for Python 2. Maybe:
import sys
if sys.version_info[0] < 3:
from bz2file import BZ2File
else:
from bz2 import BZ2File
and so on, maybe importing from here for other uses of BZ2File
. I can't think immediately of a test for saving memory here, can you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in to avoid an early import? pkgutil.find_loader()
is a Python 2/3-safe way to see if a module can be imported without actually importing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, sorry, the bz2file
package provides an alternative BZ2File
implementation, it does not replace the implementation in the bz2
package. If you check, I think you'll find that bz2.BZ2File
still doesn't have readinto
after you've installed bz2file
, but bz2file.BZ2File
does have readinto
(on Python 2.7).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, reparsed. Yeah, I still need to make that change. On the whole, this PR just isn't ready. To get tests working again, I still need to figure out why we can't use version selectors in install_requires
. I suspect it's a distutils
or setuptools
problem.
``` /Users/arokem/.virtualenvs/afq/lib/python3.7/site-packages/nibabel/streamlines/trk.py:562: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead header_rec = np.fromstring(string=header_str, dtype=header_2_dtype) ```
This is because newer numpy doesn't allow to change the writeable flag.
633eef8
to
62b8cc9
Compare
Codecov Report
@@ Coverage Diff @@
## master #700 +/- ##
==========================================
- Coverage 88.88% 88.86% -0.02%
==========================================
Files 93 93
Lines 11449 11455 +6
Branches 1892 1894 +2
==========================================
+ Hits 10176 10180 +4
- Misses 933 934 +1
- Partials 340 341 +1
Continue to review full report at Codecov.
|
@arokem I ended up needing your (Moved here from the edited top post, since I'm not sure if adding a handle in an edit notifies people.) |
@matthew-brett This one is ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great - thanks - just a couple of comments.
nibabel/streamlines/trk.py
Outdated
header_str = f.read(header_2_dtype.itemsize) | ||
header_rec = np.fromstring(string=header_str, dtype=header_2_dtype) | ||
|
||
# Read the header into a bytearray. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth a comment explaining use of readinto
.
nisext/sexts.py
Outdated
@@ -191,7 +191,6 @@ def version_getter(pkg_name): | |||
optional, | |||
dependency) | |||
return | |||
_add_append_key(setuptools_args, 'install_requires', dependency) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's just possible someone else is using nisext
. Any way to avoid the API change?
@matthew-brett Any more comments? |
@matthew-brett Going to merge this and start the 2.3.2 process. If you have further concerns, can you open a PR with a suggested fix? |
Good call - looks fine to me. |
This has turned into something of an omnibus PR, which does the following things:
setuptools
and take advantage of conditional dependenciesbz2file
for Python 2.7 onlyOpener.readinto
method (via RF: Circumvents a deprecation warning fromnp.fromstring
#702)bytearray
andfilelike.readinto
in numerous places to preserve zero-copy construction of numpy arraysnumpy.fromstring
(via RF: Circumvents a deprecation warning fromnp.fromstring
#702)Closes #702.
Original
It looks like we've been taking advantage of numpy letting us declare a memory block writeable even when the underlying object is ostensibly immutable. This has allowed us to avoid copies for objects that we knew wouldn't be accessed through their original interfaces, but they decided this was a bug and closed this loophole in numpy/numpy#11739.
Don't know what else to do but make the copies they think we should be making, but perhaps others have more numpy arcana to share.
Fixes #697.