test_deprecations

Tests related to deprecation warnings. Also a convenient place to document how deprecations should eventually be turned into errors.

Module Contents

class _DeprecationTestCase

Bases:object

message =
setUp(self)
tearDown(self)
assert_deprecated(self, function, num=1, ignore_others=False, function_fails=False, exceptions=(DeprecationWarning, ), args=(), kwargs={})

Test if DeprecationWarnings are given and raised.

This first checks if the function when called gives num DeprecationWarnings, after that it tries to raise these DeprecationWarnings and compares them with exceptions. The exceptions can be different for cases where this code path is simply not anticipated and the exception is replaced.

f : callable
The function to test
num : int
Number of DeprecationWarnings to expect. This should normally be 1.
ignore_other : bool
Whether warnings of the wrong type should be ignored (note that the message is not checked)
function_fails : bool
If the function would normally fail, setting this will check for warnings inside a try/except block.
exceptions : Exception or tuple of Exceptions
Exception to expect when turning the warnings into an error. The default checks for DeprecationWarnings. If exceptions is empty the function is expected to run successfull.
args : tuple
Arguments for f
kwargs : dict
Keyword arguments for f
assert_not_deprecated(self, function, args=(), kwargs={})

Test if DeprecationWarnings are given and raised.

This is just a shorthand for:

self.assert_deprecated(function, num=0, ignore_others=True,
exceptions=tuple(), args=args, kwargs=kwargs)
class TestFloatNonIntegerArgumentDeprecation

Bases:test_deprecations._DeprecationTestCase

These test that DeprecationWarning is given when you try to use non-integers as arguments to for indexing and slicing e.g. a[0.0:5] and a[0.5], or other functions like array.reshape(1., -1).

After deprecation, changes need to be done inside conversion_utils.c in PyArray_PyIntAsIntp and possibly PyArray_IntpConverter. In iterators.c the function slice_GetIndices could be removed in favor of its python equivalent and in mapping.c the function _tuple_of_integers can be simplified (if np.array([1]).__index__() is also deprecated).

As for the deprecation time-frame: via Ralf Gommers,

“Hard to put that as a version number, since we don’t know if the version after 1.8 will be 6 months or 2 years after. I’d say 2 years is reasonable.”

I interpret this to mean 2 years after the 1.8 release. Possibly giving a PendingDeprecationWarning before that (which is visible by default)

message = using a non-integer number instead of an integer will result in an error in the future
test_indexing(self)
test_valid_indexing(self)
test_slicing(self)
test_valid_slicing(self)
test_non_integer_argument_deprecations(self)
test_non_integer_sequence_multiplication(self)
test_reduce_axis_float_index(self)
class TestBooleanArgumentDeprecation

Bases:test_deprecations._DeprecationTestCase

This tests that using a boolean as integer argument/indexing is deprecated.

This should be kept in sync with TestFloatNonIntegerArgumentDeprecation and like it is handled in PyArray_PyIntAsIntp.

message = using a boolean instead of an integer will result in an error in the future
test_bool_as_int_argument(self)
class TestArrayToIndexDeprecation

Bases:test_deprecations._DeprecationTestCase

This tests that creating an an index from an array is deprecated if the array is not 0d.

This can probably be deprecated somewhat faster then the integer deprecations. The deprecation period started with NumPy 1.8. For deprecation this needs changing of array_index in number.c

message = converting an array with ndim \> 0 to an index will result in an error in the future
test_array_to_index_deprecation(self)
class TestNonIntegerArrayLike

Bases:test_deprecations._DeprecationTestCase

Tests that array likes, i.e. lists give a deprecation warning when they cannot be safely cast to an integer.

message = non integer \(and non boolean\) array-likes will not be accepted as indices in the future
test_basic(self)
test_boolean_futurewarning(self)
class TestMultipleEllipsisDeprecation

Bases:test_deprecations._DeprecationTestCase

message = an index can only have a single Ellipsis \(`...`\); replace all but one with slices \(`:`\).
test_basic(self)
class TestBooleanSubtractDeprecations

Bases:test_deprecations._DeprecationTestCase

Test deprecation of boolean -. While + and * are well defined, - is not and even a corrected form seems to have no real uses.

The deprecation process was started in NumPy 1.9.

message = numpy boolean .* \(the .* `-` operator\) is deprecated, use the bitwise
test_operator_deprecation(self)
class TestRankDeprecation

Bases:test_deprecations._DeprecationTestCase

Test that np.rank is deprecated. The function should simply be removed. The VisibleDeprecationWarning may become unnecessary.

test(self)
class TestComparisonDepreactions

Bases:test_deprecations._DeprecationTestCase

This tests the deprecation, for non-elementwise comparison logic. This used to mean that when an error occured during element-wise comparison (i.e. broadcasting) NotImplemented was returned, but also in the comparison itself, False was given instead of the error.

Also test FutureWarning for the None comparison.

message = elementwise comparison failed; this will raise the error in the future.
test_normal_types(self)
test_string(self)
test_none_comparison(self)
test_scalar_none_comparison(self)
class TestIdentityComparisonDepreactions

Bases:test_deprecations._DeprecationTestCase

This tests the equal and not_equal object ufuncs identity check deprecation. This was due to the usage of PyObject_RichCompareBool.

This tests that for example for a = np.array([np.nan], dtype=object) a == a it is warned that False and not np.nan is np.nan is returned.

Should be kept in sync with TestComparisonDepreactions and new tests added when the deprecation is over. Requires only removing of @identity@ (and blocks) from the ufunc loops.c.src of the OBJECT comparisons.

message = numpy .* will not check object identity in the future.
test_identity_equality_mismatch(self)
test_comparison_error(self)
test_bool_error(self)