You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. #11788
It is a harmless. You can either ignore it or go back to 1.14.5. Will be fixed in the upcoming 1.15.1
Duplicate of #11628. Leave this one open until 1.15.1 is released
Reacted by Zirui Wang, Jack Moody, mathurinm, Matan Addam, HitLuca, Heaven, NohHaeChan, Duc Hoang, Barack Bao, Zekun ZHANG and 7 more
Reacted by Heaven, NohHaeChan, SankiKim and Olav Vahtras
@mattip Maybe it's best to edit the stackoverflow question with details about the issue with 1.15 if it would appear there this topic would have not been created. The question there is the first search result of google regarding the error.
Anyway, this is definitely fixed in 1.15.1, so closing. If you find it's a pytest change rather than something in your own code and do think it's something numpy should fix, please open a new issue.
Matti, that isn't the problem with this warning, what is happening is that the C struct has been changed across numpy versions. That is back compatible if the new members are added to the end of the structure, because extension module compiled again earlier numpy versions will never access them. However, cython will complain if numpy reports a structure size different than it was for the numpy that the code was generated against. See #5343 for that added member.
As for the technical details: Cython is checking that the size of certain structs match between how the extension was complied and what is used at runtime by numpy. If the struct has been expanded since the extension was built (or since the cython numpy.pxd was written??) then it will give a warning. But, in fact, it is not dangerous, as long as the struct is larger, rather than smaller that it used to be.
cython is also (or is this the cause) still using a oder, deprecated numpy API (which leads to a bunch of warnings at compile time) -- updating that is under discussion.
Solutions:
ignore the warnings, and hope that Cython updates fix them in the future.
Adjust your pytest configuration to suppress these warnings.
NOTE: that PEP 565 recommends that test runners do not suppress warnings:
Frankly, it's a cython issue -- it's raising a warning that it shouldn't.
Well, it's debatable. The Cython devs are saying that the check and warning are useful to them sometimes. It's just never useful for numpy. They really should give us a better option to disable it though.
I think pytest is doing the right thing -- there is a warning raised, it should be up to the test framework, and the user to determine what warnings they want see.
I don't think that's right. Packages should certainly be able to decide which of the warnings that come from their own code or from code below them in the stack should be suppressed.
Say we have a user that writes some code that uses, e.g., seaborn. We then have a stack (just an example, could be incorrect in the details) seaborn -> pandas -> numpy. The warning comes from cython-generated code within numpy. Expecting the user to see, understand or decide on warnings that come from numpy or even lower in the stack makes very little sense. If numpy or pandas devs decide that a warning from numpy is never relevant, there is zero reason to let a seaborn user see it. In summary: pytest is wrong here.
I think there is no good answer with Python's warning system. For example:
" If numpy or pandas devs decide that a warning from numpy is never relevant, there is zero reason to let a seaborn user see it. "
absolutely -- but the warning doesn't necessarily come from numpy -- in fact, does it ever? numpy used some cython code (yes?) -- but then it gets compiled all together -- so there would never be a numpy version mis-match, would there?
In my case, I'm getting the warning when I run the tests on my "gridded" package, which is pure-python, but depends on (also mine) cell_tree2d package, which is written in cython, and depends on numpy.
So should the numpy project be able to dictate what warnings are seen from my code? In this case, it's all pretty numpy-focused, but doesn't seem like a good policy to build into Python or pytest.
The core problem here is that the numpy devs and the cython devs disagree about how useful this warning is. But if it's useful for Cython developers (and i can sure see how it could be), it seems to me that it should be something that can be turned on and off at cython-compile time.
Late response here, but pytest.ini makes warnings errors and currently overrides the init file, which is why the filters need to be in both in order to operate with, or without, the pytest.ini file. I think the proposed change will give the init file priority, or at least enable the test runners to disable/enable warnings on the command line, which I think is a good thing.
Assuming "your code" is something you are compiling with cython; Cython 0.29, released only recently, should not generate this warning. Can you try upgrading?
@ebo This issue is closed. Please open a new one with details about how you are obtaining the packages and the exact error message you are getting. Chances are it is a problem not with NumPy itself rather with something interacting with NumPy, and we need to know what that something is.
Note that the message changed in Cython 0.29, it should now print size changed, may indicate binary incompatibility. Expected %zd from C header, got %zd from PyObject. If your warning is not formatted like this you are using C files generated from an older version of Cython.
Hi, I got the warning after importing the following packages:
import json
import matplotlib.pyplot as plt
import pandas as pd
Maybe this helps in figuring out where the issue is caused. My warning is:
/usr/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
Activity
mattip commentedon Aug 20, 2018
It is a harmless. You can either ignore it or go back to 1.14.5. Will be fixed in the upcoming 1.15.1
Duplicate of #11628. Leave this one open until 1.15.1 is released
ron819 commentedon Aug 20, 2018
@mattip Maybe it's best to edit the stackoverflow question with details about the issue with 1.15 if it would appear there this topic would have not been created. The question there is the first search result of google regarding the error.
ChrisBarker-NOAA commentedon Sep 19, 2018
I'm running 1.15.1, and getting the error still :-(
I'm running 1.1.5.1 fron conda-forge on OS-X, with python2.7, if that's relevant.
I'm also making heavy use of Cython -- maybe it's .pyd files are out of date??
ChrisBarker-NOAA commentedon Sep 19, 2018
NOTE: I'm running Cython code compiled against an older numpy -- maybe that's the issue??
rgommers commentedon Sep 19, 2018
You shouldn't get those. Are you clearing the warning filters somewhere? It's this one in numpy's main
__init__.py:charris commentedon Sep 19, 2018
What pytest version?
ChrisBarker-NOAA commentedon Sep 19, 2018
I have noticed a lot more warnings in other contexts as well -- so maybe pytest changed its defaults.
But should numpy be putting out this warning at all?
@rgommers -- I'm not doing anything (myself) about warnings -- but maybe pytest is?
But why is numpy set to ignore a warning that it itself raises???
rgommers commentedon Sep 19, 2018
Long story, the warning comes from Cython and the Cython devs don't want to turn it off. Hence we filter it in
__init__.py.Your warning filters get reset somewhere, that must be the cause. Maybe a new pytest release.
rgommers commentedon Sep 19, 2018
Anyway, this is definitely fixed in 1.15.1, so closing. If you find it's a
pytestchange rather than something in your own code and do think it's something numpy should fix, please open a new issue.mattip commentedon Sep 19, 2018
For the "why" - see cython/cython#2498. From the positive feedback to a possible solution in this comment, there is hope it might get solved.
charris commentedon Sep 20, 2018
Matti, that isn't the problem with this warning, what is happening is that the C struct has been changed across numpy versions. That is back compatible if the new members are added to the end of the structure, because extension module compiled again earlier numpy versions will never access them. However, cython will complain if numpy reports a structure size different than it was for the numpy that the code was generated against. See #5343 for that added member.
ChrisBarker-NOAA commentedon Sep 20, 2018
For clarity for future readers, and to make sure I understand the issue, here's a summary:
let's see if I have this right
Problem:
The warnings are not created by numpy, but by cython (see above for the link to the issue)
numpy has addressed this by suppressing the warning it its configuration, so most folks won't see it.
pytest has (fairly recently) updated its handling of warnings -- so newer pytest versions will override numpy's suppression of the warning, so you will see it again. (https://docs.pytest.org/en/latest/warnings.html)
As for the technical details: Cython is checking that the size of certain structs match between how the extension was complied and what is used at runtime by numpy. If the struct has been expanded since the extension was built (or since the cython numpy.pxd was written??) then it will give a warning. But, in fact, it is not dangerous, as long as the struct is larger, rather than smaller that it used to be.
cython is also (or is this the cause) still using a oder, deprecated numpy API (which leads to a bunch of warnings at compile time) -- updating that is under discussion.
Solutions:
ignore the warnings, and hope that Cython updates fix them in the future.
Adjust your pytest configuration to suppress these warnings.
NOTE: that PEP 565 recommends that test runners do not suppress warnings:
https://www.python.org/dev/peps/pep-0565/#recommended-filter-settings-for-test-runners
-- makes some sense, there is a lot that you don't want to see at runtime that you probably should see when you run your tests -- at least by default.
Final note: if anyone with good pytest and warnings foo can post a way to suppress this particular warning, that would be much appreciated :-)
7 remaining items
rgommers commentedon Sep 20, 2018
Well, it's debatable. The Cython devs are saying that the check and warning are useful to them sometimes. It's just never useful for numpy. They really should give us a better option to disable it though.
I don't think that's right. Packages should certainly be able to decide which of the warnings that come from their own code or from code below them in the stack should be suppressed.
Say we have a user that writes some code that uses, e.g.,
seaborn. We then have a stack (just an example, could be incorrect in the details)seaborn->pandas->numpy. The warning comes fromcython-generated code withinnumpy. Expecting the user to see, understand or decide on warnings that come fromnumpyor even lower in the stack makes very little sense. Ifnumpyorpandasdevs decide that a warning fromnumpyis never relevant, there is zero reason to let aseabornuser see it. In summary:pytestis wrong here.ChrisBarker-NOAA commentedon Sep 20, 2018
I think there is no good answer with Python's warning system. For example:
" If numpy or pandas devs decide that a warning from numpy is never relevant, there is zero reason to let a seaborn user see it. "
absolutely -- but the warning doesn't necessarily come from numpy -- in fact, does it ever? numpy used some cython code (yes?) -- but then it gets compiled all together -- so there would never be a numpy version mis-match, would there?
In my case, I'm getting the warning when I run the tests on my "gridded" package, which is pure-python, but depends on (also mine) cell_tree2d package, which is written in cython, and depends on numpy.
So should the numpy project be able to dictate what warnings are seen from my code? In this case, it's all pretty numpy-focused, but doesn't seem like a good policy to build into Python or pytest.
The core problem here is that the numpy devs and the cython devs disagree about how useful this warning is. But if it's useful for Cython developers (and i can sure see how it could be), it seems to me that it should be something that can be turned on and off at cython-compile time.
-CHB
rgommers commentedon Sep 22, 2018
okay:) let me rephrase: the warning is caused by numpy (because it decided to increase the size of
dtype).cython/cython#2221 seems to be converging on a solution
mattip commentedon Sep 29, 2018
Fixed in cython/cython#2627 and merged for the upcoming cython release.
charris commentedon Sep 29, 2018
Late response here, but
pytest.inimakes warnings errors and currently overrides the init file, which is why the filters need to be in both in order to operate with, or without, thepytest.inifile. I think the proposed change will give the init file priority, or at least enable the test runners to disable/enable warnings on the command line, which I think is a good thing.LiMengyang990726 commentedon Oct 19, 2018
Hi! I have added this part into my code shown as follows
While the warning is still there, how can I eliminate it?
mattip commentedon Oct 19, 2018
Assuming "your code" is something you are compiling with cython; Cython 0.29, released only recently, should not generate this warning. Can you try upgrading?
ebo commentedon Jan 10, 2019
upgrading to numpy-1.15.4 did not fix it.
BTW, I am currently using cypython-0.29.2
mattip commentedon Jan 10, 2019
@ebo This issue is closed. Please open a new one with details about how you are obtaining the packages and the exact error message you are getting. Chances are it is a problem not with NumPy itself rather with something interacting with NumPy, and we need to know what that something is.
mattip commentedon Jan 10, 2019
Note that the message changed in Cython 0.29, it should now print
size changed, may indicate binary incompatibility. Expected %zd from C header, got %zd from PyObject. If your warning is not formatted like this you are using C files generated from an older version of Cython.ericaivarsson commentedon Feb 4, 2019
Hi, I got the warning after importing the following packages:
import json
import matplotlib.pyplot as plt
import pandas as pd
Maybe this helps in figuring out where the issue is caused. My warning is:
/usr/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
return f(*args, **kwds)
advhscmoe commentedon Mar 6, 2021
I am using 1.19 and still getting it.
mattip commentedon Mar 6, 2021
@advhscmoe please open a new issue and paste the entire traceback. This issue is closed.
waisyousofi commentedon Feb 7, 2022
I went to requirements.txt and added this changes
numpy==1.22.0
and worked for me.