-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
DEP: deprecate np.bool, np.int, np.float, np.long, np.str, np.unicode, and np.complex, which are misleading aliases for builtin types #6103
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
Conversation
For reasons which are lost in the mists of time, numpy has always re-exported a bunch of built-in types like 'int' as 'np.int', 'bool' as 'np.bool', etc. We can't possibly remove these exports anytime in the near future, because they are widely used -- people write things like np.asarray(obj, dtype=np.int) These people are confused, and would be better off writing either np.asarray(obj, dtype=int) or np.asarray(obj, dtype=np.int_) depending on what they actually want, but their code does work (and is equivalent to the 'dtype=int' version), so we can't break it. But, thanks to a new feature added in 3.5, plus some glue and sealing back for previous versions, it is finally at least possible to deprecate these attributes! This adds a dependency on the 'metamodule' package, which is a tiny pure-Python package that supports every version of Python that numpy supports. This will Just Work for pip and other sensible installation tools, but the alternative would be to just vendor our own copy of metamodule.py into the numpy/ directory instead.
This is necessary since otherwise the new deprecations for np.int and friends cause an error to be raised while nose is scanning various modules looking for tests, before it even starts running our test suite.
While you are at it ;P:
Sorry, don't mean this serious, but at least most of that seems like cludge. |
Anyway, I am +0.5. I definitely think it is right, just wondering if it is worth the hassle (or if we should spend our "piss of users" credits on other things ;)). |
Hopefully-unmistifying historical note: In early numpy days, these were aliases to the actual numpy scalar types, e.g. |
@rkern: awesome, thanks for that It's true that this deprecation will be very noisy (at least for those rare individuals who actually ask to see deprecation warnings). The tradeoff is that in my experience people who are using In any case we need to talk about this on the list, I'll make a post when I get a moment. |
It's 2015 but the Python packaging system is still terrible. An explicit dependency on a package no one has installed is not a good idea. +10 for vendoring it if needed. |
My experience is that the python packaging system for pure python packages
|
This fails the very simplest test of all:
Also note that pip isn't even installed by default on all Python versions we support, is by no means universal (buildout, conda, people who don't use any of those), can fail behind corporate firewalls, .... (I can go on). A dependency is quite simply not worth it. |
'python setup.py install' is broken anyway, though, it makes clean
|
I'm sorry, but a statement like "python setup.py install is broken anyway" makes it kind of hard to argue. That's still the canonical way you'll find in almost any install instruction. Anyway, I don't want to argue about this at all, it's a waste of time. Even if pip were perfect and everyone was using it (both very much not the case), I would be against adding a dependency to numpy for one deprecation warning. It really does not make any sense at all. |
Fair enough.
|
As a note for future reference in case this comes up again: this discussion: http://stackoverflow.com/questions/8161617/how-can-i-specify-library-versions-in-setup-py
|
I don't think I'd be a huge fan of having something like sempervirens attached onto raw numpy. If groups like Continuum or Enthought or Sourceforge or Berkeley's Social Sciences Data Laboratory want to make their own instrumented installers then of course that's allowed but I'd prefer to keep it out of the main numpy github repo. |
Let's defer that discussion until sempervirens is an actual thing, and in
|
As per discussion thread starting here: numpy#6103 (comment)
Vendored metamodule.py. |
Hmm, sent email to the list a few hours ago, but it doesn't seem to have gone through (nor have I received several emails from the last few days that are in the archives). Who is it we bug about this again? |
@rkern I think Robert usually handles this. |
I relay it to @infowolfe |
I'm by no means a beginner numpy user and I have definitely used |
I'm in the same position as @jni. I also thought that np.float is a numpy-type as it is in the numpy namespace. And I also taught that other users. Just assumed that Also, the docstring does not mention that this is the python float, not the numpy float:
I don't understand why this alias has been created in the beginning. If the alias would not exist, after a EDIT: I also had the misconseption that |
The docstring is a property of the object, not a property of the attribute, if that makes sense -- so the reason it doesn't say anything about numpy is that it's just the docstring for the regular builtin float, it has no idea that it is being referred to by this weird confusing extra name.
The alias wasn't created to make
and it was important that (a) they both keep working (for backward compatibility), and (b) they should have identical meaning (because anything else would be even more confusing). And then there was also the requirement (c) that in the latter case,
[NB: edits don't trigger email notifications, so many people may never see them] I can see why you'd think that, given that similarity to the leading-underscore-means-private convention. But what's going on here is that this is the convention that a trailing underscore is used to avoid naming conflicts -- e.g. when people have a variable that refers to an arbitrary class object in python, then you can't name the variable If you can see a way to make this clearer in the docs then we'd certainly appreciate suggestions/contributions! |
use int, float, bool instead of np.int, np.float, np.bool See numpy/numpy#6103 for rationale.
FWIW, numpy depending on or vendoring an explicitly PyPy-incompatible module is likely to be a bit annoying for us in numpypy, though I guess that the solution will be to get |
As discussed in astropy#6603 (and numpy/numpy#6103) it's unnecessary and misleading to use the Python types from the NumPy namespace. With this PR this uses the default NumPy dtype corresponding to these Python types.
I am going to close this, it is superseded by Erics work in #14882 now (although it coudl be easier to move forward with a small NEP maybe, which I wanted to write at some point, but did not do yet). In any case, I doubt that we will go the |
This isn't ready yet -- it causes hundreds of test failures due to our own internal usage of
np.bool
etc., plus it is missing new tests of its own -- but posting now as an RFC.For reasons which are lost in the mists of time, numpy has always
re-exported a bunch of built-in types like
int
asnp.int
,bool
asnp.bool
, etc. We can't possibly remove these exports anytime in thenear future, because they are widely used -- people write things like
These people are confused, and would be better off writing either
or
depending on what they actually want, but their code does work (and is
equivalent to the
dtype=int
version), so we can't break it. But,thanks to a new feature added in 3.5, plus some glue and sealing back
for previous versions, it is finally at least possible to deprecate
these attributes!
This adds a dependency on the
metamodule
package, which is a tinypure-Python package that supports every version of Python that numpy
supports. This will Just Work for pip and other sensible installation
tools, but the alternative would be to just vendor our own copy of
metamodule.py
into the numpy/ directory instead.Personally I am kinda inclined to try going with the explicit dependency route and see how far we can get, because maintaining vendored libraries is a huge pain, and because c'mon it's 2015, and because sooner or later we are probably going to want to add an external dependency or two (e.g. sempervirens) and so we might as well find out what the pain points are now. But I can see the arguments either way...