Repository: numpy/numpy

Issue:
Add a big scary warning to oldnumeric and numarray compat modules
As per the thread starting here:
http://mail.scipy.org/pipermail/numpy-discussion/2013-January/065111.html



Discussion:
Looks like the problem with that PR was that at numpy/testing/nosetester.py line 366, we set all deprecation warnings to "raise" when running the test suite, which causes exceptions when nose imports these old packages to search them for tests.

The easy fix would be just to add another special-case "ignore" filter to nosetester.py at around line 372; there are several there already.

I fooled around with that a bit, but I don't recall where I ended up :(

It's a problem I ran into in scipy as well that it's not easily possible to deprecate a module without raising a test failure. So probably a more generic solution is in order. Maybe a `DeprecatedModuleWarning` that's a subclass of `DeprecationWarning`? Then we let those not raise errors.

We did this in scipy:

```
@deprecate(old_name="scipy.lib.blas", new_name="scipy.linalg.blas")
def _deprecated():
    pass
try:
    _deprecated()
except DeprecationWarning as e:
    # don't fail import if DeprecationWarnings raise error -- works around
    # the situation with Numpy's test framework
    pass
```

Ugly, but well...

@pv: That breaks downstream code that wants to use -W error for other
reasons (e.g. to assert their test suite doesn't use any deprecated code)...

The DeprecatedModuleWarning trick seems like a sensible hack to me though.

On Tue, Apr 30, 2013 at 4:12 PM, Pauli Virtanen notifications@github.comwrote:

> We did this in scipy:
> 
> @deprecate(old_name="scipy.lib.blas", new_name="scipy.linalg.blas")
> def _deprecated():
>     pass
> try:
>     _deprecated()
> except DeprecationWarning as e:
>     # don't fail import if DeprecationWarnings raise error -- works around
>     # the situation with Numpy's test framework
>     pass
> 
> Ugly, but well...
> 
> —
> Reply to this email directly or view it on GitHubhttps://github.com/numpy/numpy/issues/2905#issuecomment-17251250
> .


Resolving patch:
diff --git a/numpy/__init__.py b/numpy/__init__.py
--- a/numpy/__init__.py
+++ b/numpy/__init__.py
@@ -108,6 +108,19 @@
 
 import sys
 
+
+class ModuleDeprecationWarning(DeprecationWarning):
+    """Module deprecation warning.
+
+    The nose tester turns ordinary Deprecation warnings into test failures.
+    That makes it hard to deprecate whole modules, because they get
+    imported by default. So this is a special Deprecation warning that the
+    nose tester will let pass without making tests fail.
+
+    """
+    pass
+
+
 # We first need to detect if we're being called as part of the numpy setup
 # procedure itself in a reliable manner.
 try:
@@ -138,7 +151,7 @@ def pkgload(*packages, **options):
         return loader(*packages, **options)
 
     from . import add_newdocs
-    __all__ = ['add_newdocs']
+    __all__ = ['add_newdocs', 'ModuleDeprecationWarning']
 
     pkgload.__doc__ = PackageLoader.__call__.__doc__
 
diff --git a/numpy/numarray/__init__.py b/numpy/numarray/__init__.py
--- a/numpy/numarray/__init__.py
+++ b/numpy/numarray/__init__.py
@@ -1,5 +1,8 @@
 from __future__ import division, absolute_import, print_function
 
+import warnings
+from numpy import ModuleDeprecationWarning
+
 from .util import *
 from .numerictypes import *
 from .functions import *
@@ -14,6 +17,9 @@
 from . import compat
 from . import session
 
+_msg = "The numarray module will be dropped in Numpy 1.9"
+warnings.warn(_msg, ModuleDeprecationWarning)
+
 __all__ = ['session', 'numerictypes']
 __all__ += util.__all__
 __all__ += numerictypes.__all__
diff --git a/numpy/oldnumeric/__init__.py b/numpy/oldnumeric/__init__.py
--- a/numpy/oldnumeric/__init__.py
+++ b/numpy/oldnumeric/__init__.py
@@ -3,8 +3,14 @@
 """
 from __future__ import division, absolute_import, print_function
 
+import warnings
+
 from numpy import *
 
+_msg = "The oldnumeric module will be dropped in Numpy 1.9"
+warnings.warn(_msg, ModuleDeprecationWarning)
+
+
 def _move_axis_to_0(a, axis):
     if axis == 0:
         return a


Test patch:
diff --git a/numpy/testing/nosetester.py b/numpy/testing/nosetester.py
--- a/numpy/testing/nosetester.py
+++ b/numpy/testing/nosetester.py
@@ -11,6 +11,7 @@
 import warnings
 import numpy.testing.utils
 from numpy.compat import basestring
+from numpy import ModuleDeprecationWarning
 
 def get_package_name(filepath):
     """
@@ -378,6 +379,7 @@ def test(self, label='fast', verbose=1, extra_argv=None,
         warnings.filterwarnings('ignore', message='Not importing directory')
         warnings.filterwarnings("ignore", message="numpy.dtype size changed")
         warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
+        warnings.filterwarnings("ignore", category=ModuleDeprecationWarning)
 
         try:
             from .noseclasses import NumpyTestProgram
diff --git a/numpy/testing/utils.py b/numpy/testing/utils.py
--- a/numpy/testing/utils.py
+++ b/numpy/testing/utils.py
@@ -26,8 +26,10 @@
            'assert_array_max_ulp', 'assert_warns', 'assert_no_warnings',
            'assert_allclose']
 
+
 verbose = 0
 
+
 def assert_(val, msg='') :
     """
     Assert that works in release mode.