Skip to content

TST: VisibleDeprecationWarning causing numpy-dev failures #9879

@pllim

Description

@pllim

This just started happening, so I suspect it is due to numpy/numpy#15119 (NEP 34), causing the following failures in the numpy-dev job that is allowed to fail:

Numpy: 1.19.0.dev0+19b96a1

...

=================================== FAILURES ===================================

______________________________ test_angle_arrays _______________________________

    def test_angle_arrays():

        """

        Test arrays values with Angle objects.

        """

        # Tests incomplete

        a1 = Angle([0, 45, 90, 180, 270, 360, 720.], unit=u.degree)

        npt.assert_almost_equal([0., 45., 90., 180., 270., 360., 720.], a1.value)

    

        a2 = Angle(np.array([-90, -45, 0, 45, 90, 180, 270, 360]), unit=u.degree)

        npt.assert_almost_equal([-90, -45, 0, 45, 90, 180, 270, 360],

                                a2.value)

    

        a3 = Angle(["12 degrees", "3 hours", "5 deg", "4rad"])

        npt.assert_almost_equal([12., 45., 5., 229.18311805],

                                a3.value)

        assert a3.unit == u.degree

    

        a4 = Angle(["12 degrees", "3 hours", "5 deg", "4rad"], u.radian)

        npt.assert_almost_equal(a4.degree, a3.value)

        assert a4.unit == u.radian

    

        a5 = Angle([0, 45, 90, 180, 270, 360], unit=u.degree)

        a6 = a5.sum()

        npt.assert_almost_equal(a6.value, 945.0)

        assert a6.unit is u.degree

    

        with pytest.raises(TypeError):

            # Arrays where the elements are Angle objects are not supported -- it's

            # really tricky to do correctly, if at all, due to the possibility of

            # nesting.

>           a7 = Angle([a1, a2, a3], unit=u.degree)

astropy/coordinates/tests/test_arrays.py:48: 

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

astropy/coordinates/angles.py:108: in __new__

    return super().__new__(cls, angle, unit, dtype=dtype, copy=copy)

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'astropy.coordinates.angles.Angle'>

value = [array([  0.,  45.,  90., 180., 270., 360., 720.]), array([-90., -45.,   0.,  45.,  90., 180., 270., 360.]), array([ 12.        ,  45.        ,   5.        , 229.18311805])]

unit = Unit("deg"), dtype = None, copy = True, order = None, subok = False

ndmin = 0

    def __new__(cls, value, unit=None, dtype=None, copy=True, order=None,

                subok=False, ndmin=0):

    

        if unit is not None:

            # convert unit first, to avoid multiple string->unit conversions

            unit = Unit(unit)

    

        # optimize speed for Quantity with no dtype given, copy=False

        if isinstance(value, Quantity):

            if unit is not None and unit is not value.unit:

                value = value.to(unit)

                # the above already makes a copy (with float dtype)

                copy = False

    

            if type(value) is not cls and not (subok and

                                               isinstance(value, cls)):

                value = value.view(cls)

    

            if dtype is None:

                if not copy:

                    return value

    

                if value.dtype.kind in 'iu':

                    dtype = float

    

            return np.array(value, dtype=dtype, copy=copy, order=order,

                            subok=True, ndmin=ndmin)

    

        # Maybe str, or list/tuple of Quantity? If so, this may set value_unit.

        # To ensure array remains fast, we short-circuit it.

        value_unit = None

        if not isinstance(value, np.ndarray):

            if isinstance(value, str):

                # The first part of the regex string matches any integer/float;

                # the second parts adds possible trailing .+-, which will break

                # the float function below and ensure things like 1.2.3deg

                # will not work.

                pattern = (r'\s*[+-]?'

                           r'((\d+\.?\d*)|(\.\d+)|([nN][aA][nN])|'

                           r'([iI][nN][fF]([iI][nN][iI][tT][yY]){0,1}))'

                           r'([eE][+-]?\d+)?'

                           r'[.+-]?')

    

                v = re.match(pattern, value)

                unit_string = None

                try:

                    value = float(v.group())

    

                except Exception:

                    raise TypeError('Cannot parse "{}" as a {}. It does not '

                                    'start with a number.'

                                    .format(value, cls.__name__))

    

                unit_string = v.string[v.end():].strip()

                if unit_string:

                    value_unit = Unit(unit_string)

                    if unit is None:

                        unit = value_unit  # signal no conversion needed below.

    

            elif (isiterable(value) and len(value) > 0 and

                  all(isinstance(v, Quantity) for v in value)):

                # Convert all quantities to the same unit.

                if unit is None:

                    unit = value[0].unit

                value = [q.to_value(unit) for q in value]

                value_unit = unit  # signal below that conversion has been done

    

        if value_unit is None:

            # If the value has a `unit` attribute and if not None

            # (for Columns with uninitialized unit), treat it like a quantity.

            value_unit = getattr(value, 'unit', None)

            if value_unit is None:

                # Default to dimensionless for no (initialized) unit attribute.

                if unit is None:

                    unit = cls._default_unit

                value_unit = unit  # signal below that no conversion is needed

            else:

                try:

                    value_unit = Unit(value_unit)

                except Exception as exc:

                    raise TypeError("The unit attribute {!r} of the input could "

                                    "not be parsed as an astropy Unit, raising "

                                    "the following exception:\n{}"

                                    .format(value.unit, exc))

    

                if unit is None:

                    unit = value_unit

                elif unit is not value_unit:

                    copy = False  # copy will be made in conversion at end

    

        value = np.array(value, dtype=dtype, copy=copy, order=order,

>                        subok=False, ndmin=ndmin)

E       numpy.VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

astropy/units/quantity.py:381: VisibleDeprecationWarning

____________________ TestColumn.test_insert_object[Column] _____________________

numpy.VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

The above exception was the direct cause of the following exception:

self = <astropy.table.tests.test_column.TestColumn object at 0x7f4ec1342090>

Column = <class 'astropy.table.column.Column'>

    def test_insert_object(self, Column):

        c = Column(['a', 1, None], name='a', dtype=object)

    

        # Basic insert

        c1 = c.insert(1, [100, 200])

>       assert np.all(c1 == ['a', [100, 200], 1, None])

astropy/table/tests/test_column.py:373: 

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Column name='a' dtype='object' length=4>

         a

[100, 200]

         1

      None

other = ['a', [100, 200], 1, None]

    def _compare(self, other):

        op = oper  # copy enclosed ref to allow swap below

    

        # Special case to work around #6838.  Other combinations work OK,

        # see tests.test_column.test_unicode_sandwich_compare().  In this

        # case just swap self and other.

        #

        # This is related to an issue in numpy that was addressed in np 1.13.

        # However that fix does not make this problem go away, but maybe

        # future numpy versions will do so.  NUMPY_LT_1_13 to get the

        # attention of future maintainers to check (by deleting or versioning

        # the if block below).  See #6899 discussion.

        # 2019-06-21: still needed with numpy 1.16.

        if (isinstance(self, MaskedColumn) and self.dtype.kind == 'U' and

                isinstance(other, MaskedColumn) and other.dtype.kind == 'S'):

            self, other = other, self

            op = swapped_oper

    

        if self.dtype.char == 'S':

            other = self._encode_str(other)

    

        # Now just let the regular ndarray.__eq__, etc., take over.

>       result = getattr(super(), op)(other)

E       DeprecationWarning: elementwise comparison failed; this will raise an error in the future.

astropy/table/column.py:1020: DeprecationWarning

_________________ TestColumn.test_insert_object[MaskedColumn] __________________

a = ['a', [100, 200], 1, None], subok = True

    def getdata(a, subok=True):

        """

        Return the data of a masked array as an ndarray.

    

        Return the data of `a` (if any) as an ndarray if `a` is a ``MaskedArray``,

        else return `a` as a ndarray or subclass (depending on `subok`) if not.

    

        Parameters

        ----------

        a : array_like

            Input ``MaskedArray``, alternatively a ndarray or a subclass thereof.

        subok : bool

            Whether to force the output to be a `pure` ndarray (False) or to

            return a subclass of ndarray if appropriate (True, default).

    

        See Also

        --------

        getmask : Return the mask of a masked array, or nomask.

        getmaskarray : Return the mask of a masked array, or full array of False.

    

        Examples

        --------

        >>> import numpy.ma as ma

        >>> a = ma.masked_equal([[1,2],[3,4]], 2)

        >>> a

        masked_array(

          data=[[1, --],

                [3, 4]],

          mask=[[False,  True],

                [False, False]],

          fill_value=2)

        >>> ma.getdata(a)

        array([[1, 2],

               [3, 4]])

    

        Equivalently use the ``MaskedArray`` `data` attribute.

    

        >>> a.data

        array([[1, 2],

               [3, 4]])

    

        """

        try:

>           data = a._data

E           AttributeError: 'list' object has no attribute '_data'

/home/travis/miniconda/envs/test/lib/python3.7/site-packages/numpy/ma/core.py:714: AttributeError

During handling of the above exception, another exception occurred:

self = <astropy.table.tests.test_column.TestColumn object at 0x7f4ec128c550>

Column = <class 'astropy.table.column.MaskedColumn'>

    def test_insert_object(self, Column):

        c = Column(['a', 1, None], name='a', dtype=object)

    

        # Basic insert

        c1 = c.insert(1, [100, 200])

>       assert np.all(c1 == ['a', [100, 200], 1, None])

astropy/table/tests/test_column.py:373: 

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

astropy/table/column.py:1020: in _compare

    result = getattr(super(), op)(other)

/home/travis/miniconda/envs/test/lib/python3.7/site-packages/numpy/ma/core.py:4071: in __eq__

    return self._comparison(other, operator.eq)

/home/travis/miniconda/envs/test/lib/python3.7/site-packages/numpy/ma/core.py:4011: in _comparison

    odata = getdata(other)

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = ['a', [100, 200], 1, None], subok = True

    def getdata(a, subok=True):

        """

        Return the data of a masked array as an ndarray.

    

        Return the data of `a` (if any) as an ndarray if `a` is a ``MaskedArray``,

        else return `a` as a ndarray or subclass (depending on `subok`) if not.

    

        Parameters

        ----------

        a : array_like

            Input ``MaskedArray``, alternatively a ndarray or a subclass thereof.

        subok : bool

            Whether to force the output to be a `pure` ndarray (False) or to

            return a subclass of ndarray if appropriate (True, default).

    

        See Also

        --------

        getmask : Return the mask of a masked array, or nomask.

        getmaskarray : Return the mask of a masked array, or full array of False.

    

        Examples

        --------

        >>> import numpy.ma as ma

        >>> a = ma.masked_equal([[1,2],[3,4]], 2)

        >>> a

        masked_array(

          data=[[1, --],

                [3, 4]],

          mask=[[False,  True],

                [False, False]],

          fill_value=2)

        >>> ma.getdata(a)

        array([[1, 2],

               [3, 4]])

    

        Equivalently use the ``MaskedArray`` `data` attribute.

    

        >>> a.data

        array([[1, 2],

               [3, 4]])

    

        """

        try:

            data = a._data

        except AttributeError:

>           data = np.array(a, copy=False, subok=subok)

E           numpy.VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

/home/travis/miniconda/envs/test/lib/python3.7/site-packages/numpy/ma/core.py:716: VisibleDeprecationWarning

____________________ TestBasic.test_init_from_time_objects _____________________

self = <astropy.time.tests.test_basic.TestBasic object at 0x7f4ec071d150>

    def test_init_from_time_objects(self):

        """Initialize from one or more Time objects"""

        t1 = Time('2007:001', scale='tai')

        t2 = Time(['2007-01-02', '2007-01-03'], scale='utc')

        # Init from a list of Time objects without an explicit scale

>       t3 = Time([t1, t2])

astropy/time/tests/test_basic.py:563: 

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

astropy/time/core.py:430: in __init__

    precision, in_subfmt, out_subfmt)

astropy/time/core.py:461: in _init_from_vals

    val = _make_array(val, copy)

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

val = [<Time object: scale='tai' format='yday' value=2007:001:00:00:00.000>, <Time object: scale='utc' format='iso' value=['2007-01-02 00:00:00.000' '2007-01-03 00:00:00.000']>]

copy = False

    def _make_array(val, copy=False):

        """

        Take ``val`` and convert/reshape to an array.  If ``copy`` is `True`

        then copy input values.

    

        Returns

        -------

        val : ndarray

            Array version of ``val``.

        """

>       val = np.array(val, copy=copy, subok=True)

E       numpy.VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray

astropy/time/core.py:2452: VisibleDeprecationWarning

===== 4 failed, 14417 passed, 129 skipped, 94 xfailed in 350.50s (0:05:50) =====

Example log: https://travis-ci.org/astropy/astropy/jobs/640083330

@mhvk , any advice?

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