-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Description
I'm seeing some test failures with Numpy dev:
______________________________ 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)
../../.tox/test-dev/lib/python3.7/site-packages/astropy/coordinates/tests/test_arrays.py:48:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../.tox/test-dev/lib/python3.7/site-packages/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 DeprecationWarning: Creating an ndarray with automatic object dtype is deprecated, use dtype=object if you intended it, otherwise specify an exact dtype
../../.tox/test-dev/lib/python3.7/site-packages/astropy/units/quantity.py:381: DeprecationWarning
____________________ TestColumn.test_insert_object[Column] _____________________
DeprecationWarning: Creating an ndarray with automatic object dtype is deprecated, use dtype=object if you intended it, otherwise specify an exact dtype
The above exception was the direct cause of the following exception:
self = <astropy.table.tests.test_column.TestColumn object at 0x7fa01a6ed358>
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])
../../.tox/test-dev/lib/python3.7/site-packages/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.
../../.tox/test-dev/lib/python3.7/site-packages/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'
../../.tox/test-dev/lib/python3.7/site-packages/numpy/ma/core.py:720: AttributeError
During handling of the above exception, another exception occurred:
self = <astropy.table.tests.test_column.TestColumn object at 0x7fa01a581240>
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])
../../.tox/test-dev/lib/python3.7/site-packages/astropy/table/tests/test_column.py:373:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../.tox/test-dev/lib/python3.7/site-packages/astropy/table/column.py:1020: in _compare
result = getattr(super(), op)(other)
../../.tox/test-dev/lib/python3.7/site-packages/numpy/ma/core.py:4077: in __eq__
return self._comparison(other, operator.eq)
../../.tox/test-dev/lib/python3.7/site-packages/numpy/ma/core.py:4017: 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 DeprecationWarning: Creating an ndarray with automatic object dtype is deprecated, use dtype=object if you intended it, otherwise specify an exact dtype
../../.tox/test-dev/lib/python3.7/site-packages/numpy/ma/core.py:722: DeprecationWarning
____________________ TestBasic.test_init_from_time_objects _____________________
self = <astropy.time.tests.test_basic.TestBasic object at 0x7fa01bc76978>
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])
../../.tox/test-dev/lib/python3.7/site-packages/astropy/time/tests/test_basic.py:562:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../.tox/test-dev/lib/python3.7/site-packages/astropy/time/core.py:429: in __init__
precision, in_subfmt, out_subfmt)
../../.tox/test-dev/lib/python3.7/site-packages/astropy/time/core.py:460: 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 DeprecationWarning: Creating an ndarray with automatic object dtype is deprecated, use dtype=object if you intended it, otherwise specify an exact dtype
../../.tox/test-dev/lib/python3.7/site-packages/astropy/time/core.py:2443: DeprecationWarning
==== 4 failed, 12977 passed, 1079 skipped, 52 xfailed in 243.41s (0:04:03) =====
cc @mhvk
Reactions are currently unavailable