Skip to content

TST: Table data type comparison fails with numpy-dev #11291

Closed

Description

@pllim

These are new failures, probably from numpy-dev, which is now 1.21.dev after the release of 1.20.

One example (others are variants of such comparisons):

>       assert col.dtype == dtype_expected
E       AssertionError: assert dtype('O') == dtype('S1')
E        +  where dtype('O') = <MaskedColumn name='col0' dtype='object' length=8>\n 0\n 1\n 2\n 3\n 4\n 5\n 6\n--.dtype

Affected tests:

  • astropy/table/tests/test_masked.py::TestTableInit::test_init_from_sequence_data_numeric_untyped[shape0-S]
  • astropy/table/tests/test_masked.py::TestTableInit::test_init_from_sequence_data_numeric_untyped[shape0-U]
  • astropy/table/tests/test_masked.py::TestTableInit::test_init_from_sequence_data_numeric_untyped[shape1-S]
  • astropy/table/tests/test_masked.py::TestTableInit::test_init_from_sequence_data_numeric_untyped[shape1-U]
  • astropy/table/tests/test_masked.py::TestTableInit::test_init_from_sequence_data_numeric_untyped[shape2-S]
  • astropy/table/tests/test_masked.py::TestTableInit::test_init_from_sequence_data_numeric_untyped[shape2-U]
  • astropy/table/tests/test_pprint.py::test_html_escaping
  • docs/table/masking.rst::masking.rst

Is this a matter of updating the expected results, or is there some compatibility bug to be fixed -- @mhvk or @taldcroft ?

Activity

  1. mhvk commented on Feb 1, 2021

    @mhvk
    Contributor

    Seems like a change in behaviour that we need to account for... (or possibly warn numpy about).

  2. pllim commented on Feb 1, 2021

    @pllim
    MemberAuthor

    I don't understand... When I run the test line-by-line in an interactive Python session, I cannot reproduce the error, but it errors out if I run the test file with pytest. 🤯

  3. mhvk commented on Feb 1, 2021

    @mhvk
    Contributor

    Very weird. I tried setting up a new venv with numpy-dev and then pip install -e .[test] - I don't get any test failures...

    I do reproduce it with test-devdeps, and that one goes away if instead I install numpy's master, so I suspect this will just disappear when numpy's nightly is up to date...

  4. pllim commented on Feb 1, 2021

    @pllim
    MemberAuthor

    I got to the point where if I copy out that test function and run it outside of astropy repo, everything passes with the same numpy from night wheel! But it starts to fail if I put it inside astropy repo. I was starting to suspect that one of the test fixtures in our many conftest.py is messing with the test.

    Unfortunately, my machine couldn't build numpy from source, so I guess I'll wait and see... Thanks for checking!

  5. mhvk commented on Feb 1, 2021

    @mhvk
    Contributor

    Very weird indeed! Hopefully it will auto-fix in a week or so...

  6. pllim commented on Feb 10, 2021

    @pllim
    MemberAuthor

    Failure is still there...

  7. pllim commented on Feb 10, 2021

    @pllim
    MemberAuthor

    I think it has something to do with this warning that we are ignoring.

    ignore:numpy.ndarray size changed:RuntimeWarning

    When I un-ignore the warning, I get this:

        from astropy.table import Table, MaskedColumn
    astropy/table/__init__.py:4: in <module>
        from .column import Column, MaskedColumn, StringTruncateWarning, ColumnInfo
    astropy/table/column.py:22: in <module>
        from ._column_mixins import _ColumnGetitemShim, _MaskedColumnGetitemShim
    astropy/table/_column_mixins.pyx:46: in init astropy.table._column_mixins
        ctypedef class numpy.ndarray [object PyArrayObject]:
    E   RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility. Expected 80 from C header, got 88 from PyObject
    

    Perhaps as a result of this warning, the dtype is O instead of S or U, as expected. But I still don't understand why the test pass if I move the test code outside of astropy repo.

  8. taldcroft commented on Feb 12, 2021

    @taldcroft
    Member

    From what I understand, that warning should be benign. But honestly I have no insight beyond a quick scan of that SO thread.

  9. pllim commented on Feb 15, 2021

    @pllim
    MemberAuthor

    It should have been benign, that's why we are ignoring it.

    ignore:numpy.ndarray size changed:RuntimeWarning

    But then now we see this failure. I am stumped.

  10. taldcroft commented on Feb 16, 2021

    @taldcroft
    Member

    I haven't dug into the implications or fix, but I think this is our root cause here. When running in pytest then this warning turns into an exception and causes numpy to output an object type. I think this accounts for the different behavior seen running within pytest vs. doing diagnostics within python. Older versions of numpy don't give this warning.

    (test-devdeps) (astropy) ➜  astropy git:(master) python -Walways
    Python 3.7.9 (default, Aug 31 2020, 07:22:35) 
    [Clang 10.0.0 ] :: Anaconda, Inc. on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import numpy as np
    >>> np.ma.array(['val', np.ma.masked])
    /Users/aldcroft/git/astropy/.tox/test-devdeps/lib/python3.7/site-packages/numpy/ma/core.py:2826: FutureWarning: Promotion of numbers and bools to strings is deprecated. In the future, code such as `np.concatenate((['string'], [0]))` will raise an error, while `np.asarray(['string', 0])` will return an array with `dtype=object`.  To avoid the warning while retaining a string result use `dtype='U'` (or 'S').  To get an array of Python objects use `dtype=object`. (Warning added in NumPy 1.21)
      order=order, subok=True, ndmin=ndmin)
    masked_array(data=['val', --],
                 mask=[False,  True],
           fill_value='N/A',
                dtype='<U32')
    >>> 
    (test-devdeps) (astropy) ➜  astropy git:(master) python -Werror 
    Python 3.7.9 (default, Aug 31 2020, 07:22:35) 
    [Clang 10.0.0 ] :: Anaconda, Inc. on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import numpy as np
    >>> np.ma.array(['val', np.ma.masked])
    masked_array(data=['val', --],
                 mask=[False,  True],
           fill_value='?',
                dtype=object)
    
  11. taldcroft commented on Feb 16, 2021

    @taldcroft
    Member

    See numpy/numpy#18425. I'm marking this as upstream fix needed. If they can't fix it then we will need to do some deeper changes to Table code. I'd suggest closing #11318.

  12. mhvk commented on Feb 16, 2021

    @mhvk
    Contributor

    Nice sleuthing! Most definitely an unintended consequence of what in itself was a good fix on the numpy side.

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