Skip to content

RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. #11788

Closed

Description

@ron819

I'm running Python 3.5.2 and numpy 1.15.0

I'm seeing:

/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
  return f(*args, **kwds)
/usr/lib/python3.5/importlib/_bootstrap.py:222: RuntimeWarning: numpy.dtype size changed, may indicate binary incompatibility. Expected 96, got 88
  return f(*args, **kwds)

According to this stackoverflow question I shouldn't see this warring as it was silence since numpy 1.8

Why do I see it? and does it means anything?

Activity

  1. mattip commented on Aug 20, 2018

    @mattip
    Member

    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

  2. ron819 commented on Aug 20, 2018

    @ron819
    Author

    @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.

  3. ChrisBarker-NOAA commented on Sep 19, 2018

    @ChrisBarker-NOAA
    Contributor

    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??

  4. ChrisBarker-NOAA commented on Sep 19, 2018

    @ChrisBarker-NOAA
    Contributor

    NOTE: I'm running Cython code compiled against an older numpy -- maybe that's the issue??

  5. rgommers commented on Sep 19, 2018

    @rgommers
    Member

    You shouldn't get those. Are you clearing the warning filters somewhere? It's this one in numpy's main __init__.py:

    warnings.filterwarnings("ignore", message="numpy.dtype size changed")
    
  6. charris commented on Sep 19, 2018

    @charris
    Member

    What pytest version?

  7. ChrisBarker-NOAA commented on Sep 19, 2018

    @ChrisBarker-NOAA
    Contributor
    $ pytest --version
    This is pytest version 3.8.0
    

    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???

  8. rgommers commented on Sep 19, 2018

    @rgommers
    Member

    But why is numpy set to ignore a warning that it itself raises???

    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.

  9. rgommers commented on Sep 19, 2018

    @rgommers
    Member

    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.

  10. mattip commented on Sep 19, 2018

    @mattip
    Member

    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.

  11. charris commented on Sep 20, 2018

    @charris
    Member

    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.

  12. ChrisBarker-NOAA commented on Sep 20, 2018

    @ChrisBarker-NOAA
    Contributor

    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)

      • cython may fix this soon
    • 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 :-)

  13. 7 remaining items

  14. rgommers commented on Sep 20, 2018

    @rgommers
    Member

    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.

  15. ChrisBarker-NOAA commented on Sep 20, 2018

    @ChrisBarker-NOAA
    Contributor

    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

  16. rgommers commented on Sep 22, 2018

    @rgommers
    Member

    but the warning doesn't necessarily come from numpy -- in fact, does it ever?

    okay:) let me rephrase: the warning is caused by numpy (because it decided to increase the size of dtype).

    The core problem here is that the numpy devs and the cython devs disagree about how useful this warning is.

    cython/cython#2221 seems to be converging on a solution

  17. mattip commented on Sep 29, 2018

    @mattip
    Member

    Fixed in cython/cython#2627 and merged for the upcoming cython release.

  18. charris commented on Sep 29, 2018

    @charris
    Member

    or am I missing something?

    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.

  19. LiMengyang990726 commented on Oct 19, 2018

    @LiMengyang990726

    You shouldn't get those. Are you clearing the warning filters somewhere? It's this one in numpy's main __init__.py:

    warnings.filterwarnings("ignore", message="numpy.dtype size changed")
    

    Hi! I have added this part into my code shown as follows

    import warnings
    
    warnings.filterwarnings("ignore", message="numpy.dtype size changed")
    warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
    

    While the warning is still there, how can I eliminate it?

  20. mattip commented on Oct 19, 2018

    @mattip
    Member

    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?

  21. ebo commented on Jan 10, 2019

    @ebo

    upgrading to numpy-1.15.4 did not fix it.

    BTW, I am currently using cypython-0.29.2

  22. mattip commented on Jan 10, 2019

    @mattip
    Member

    @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.

  23. mattip commented on Jan 10, 2019

    @mattip
    Member

    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.

  24. ericaivarsson commented on Feb 4, 2019

    @ericaivarsson

    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)

  25. advhscmoe commented on Mar 6, 2021

    @advhscmoe

    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??

    I am using 1.19 and still getting it.

  26. mattip commented on Mar 6, 2021

    @mattip
    Member

    @advhscmoe please open a new issue and paste the entire traceback. This issue is closed.

  27. waisyousofi commented on Feb 7, 2022

    @waisyousofi

    I went to requirements.txt and added this changes
    numpy==1.22.0
    and worked for me.

  28. locked as resolved and limited conversation to collaborators on Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions