-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: Make sure numpy globals keep identity after reload. #7853
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
There seems to be little use in reloading numpy as any changed modules that are imported into numpy would need to be reloaded first in order to see any changes. Furthermore, reloading causes problems as global classes defined in numpy/__init__.py change their identity. Hence we raise a RuntimeError when an attempt to reload numpy is made. Closes numpy#7844.
Note that if we want to preserve the reload option I think that the best thing to do is to move the relevant class definitions into a non-reloadable |
@cgohlke: you're the only one I know who has tried reloading numpy recently :-). Would merging this cause any problems for you? |
This PR might cause The original bug report came from a Pandas user, who noticed that |
@cgohlke Hmm, wonder why pandas does that, why not a simple import? Anyway, might as well move the functions to a safe space. |
b9b42ee
to
456316a
Compare
OK, should be fixed for pandas. I suspect it is a bug for pandas to call imp.import_module with its reload feature. Reloading seems to me to be generally dangerous unless packages are carefully designed to have no issues stemming from one module depending on classes defined in another that might be reloaded. OTOH, I suppose one could disallow defining classes in |
Yeah, I think pandas is doing this accidentally, and that it's a bug -- I just commented here. I think it would still be fine for numpy to error out on |
I note that numpy uses |
@njsmith I prefer making numpy non-reloadable as reloading it might not be what folks expect even if it works. If it doesn't break pandas, great. |
456316a
to
b9b42ee
Compare
I went back to the first version, raise an error. There are three versions on hand to choose from: raise and error, explicit imports, new globals file. |
LGTM. Just for due diligence, have you double-checked that it doesn't blow up Though I guess since pandas tests against numpy master, we could also just merge and let them tell us if we got it wrong :-) |
Yes, it works, at least for the sequence in the pandas issue. The numpy version is also correctly reported, so perhaps |
Let's merge and see how this does. |
heads up... this broke some edge cases for matplotlib's build process as noted in matplotlib/matplotlib#6928. I am going to see if we can do without the reload, though I figured I should let all know this happened. |
@WeatherGod Reload is evil, that's why we broke your build ;) We could fix it on our end, but it would be better to get out of the habit of using reload. EDIT: An alternative point of view: "isinstance() regarded as harmful". EDIT: A consequence of: "singletons regarded as harmful". |
Apparently we are reloading numpy in our astropy tests as well -- which we shouldn't and is hopefully easy to fix... |
Looks like this should maybe just be a |
@njsmith @WeatherGod @mhvk Looks like the reload safe alternative might be the best way to handle backwards compatibility. Raising a error certainly brings attention to the problem, but as this will be part of the 1.11.2 release it is likely that too much downstream code will be broken. Maybe make it reload safe and change this to a deprecation? |
I think I agree that it is best to try to continue to have "reload" work, at least sort-of. |
Uh oh!
There was an error while loading. Please reload this page.