8000 MAINT: Move `RankWarning` to exceptions module (#24476) · numpy/numpy@899e735 · GitHub
[go: up one dir, main page]

Skip to content

Commit 899e735

Browse files
authored
MAINT: Move RankWarning to exceptions module (#24476)
1 parent ced21a6 commit 899e735

18 files changed

+28
-58
lines changed

doc/source/reference/routines.polynomials.poly1d.rst

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,3 @@ Arithmetic
3737
polydiv
3838
polymul
3939
polysub
40-
41-
Warnings
42-
--------
43-
.. autosummary::
44-
:toctree: generated/
45-
46-
RankWarning

numpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
take_along_axis, tile, tracemalloc_domain, trapz, tri, tril,
213213
tril_indices, tril_indices_from, typename, union1d, unique, unpackbits,
214214
unravel_index, unwrap, vander, vectorize, vsplit, trim_zeros,
215-
triu, triu_indices, triu_indices_from, isposinf, RankWarning, disp,
215+
triu, triu_indices, triu_indices_from, isposinf, disp,
216216
deprecate, deprecate_with_doc, safe_eval, recfromtxt, recfromcsv
217217
)
218218
from . import matrixlib as _mat

numpy/__init__.pyi

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3293,9 +3293,6 @@ class _CopyMode(enum.Enum):
32933293
IF_NEEDED: L[False]
32943294
NEVER: L[2]
32953295

3296-
# Warnings
3297-
class RankWarning(UserWarning): ...
3298-
32993296
_CallType = TypeVar("_CallType", bound=Callable[..., Any])
33003297

33013298
class errstate:

numpy/exceptions.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
2020
ComplexWarning Given when converting complex to real.
2121
VisibleDeprecationWarning Same as a DeprecationWarning, but more visible.
22+
RankWarning Issued when the design matrix is rank deficient.
2223
2324
Exceptions
2425
----------
@@ -69,6 +70,7 @@ class ModuleDeprecationWarning(DeprecationWarning):
6970
nose tester will let pass without making tests fail.
7071
7172
"""
73+
pass
7274

7375

7476
class VisibleDeprecationWarning(UserWarning):
@@ -79,6 +81,16 @@ class VisibleDeprecationWarning(UserWarning):
7981
the usage is most likely a user bug.
8082
8183
"""
84+
pass
85+
86+
87+
class RankWarning(RuntimeWarning):
88+
"""Matrix rank warning.
89+
90+
Issued by polynomial functions when the design matrix is rank deficient.
91+
92+
"""
93+
pass
8294

8395

8496
# Exception used in shares_memory()
@@ -91,7 +103,6 @@ class TooHardError(RuntimeError):
91103
to fail.
92104
93105
"""
94-
95106
pass
96107

97108

numpy/exceptions.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ __all__: list[str]
55
class ComplexWarning(RuntimeWarning): ...
66
class ModuleDeprecationWarning(DeprecationWarning): ...
77
class VisibleDeprecationWarning(UserWarning): ...
8+
class RankWarning(RuntimeWarning): ...
89
class TooHardError(RuntimeError): ...
910
class DTypePromotionError(TypeError): ...
1011

numpy/lib/__init__.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ from numpy.lib.polynomial import (
148148
polydiv as polydiv,
149149
polyval as polyval,
150150
polyfit as polyfit,
151-
RankWarning as RankWarning,
152151
poly1d as poly1d,
153152
)
154153

numpy/lib/polynomial.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55
__all__ = ['poly', 'roots', 'polyint', 'polyder', 'polyadd',
66
'polysub', 'polymul', 'polydiv', 'polyval', 'poly1d',
7-
'polyfit', 'RankWarning']
7+
'polyfit']
88

99
import functools
1010
import re
@@ -16,6 +16,7 @@
1616
from numpy.core import (isscalar, abs, finfo, atleast_1d, hstack, dot, array,
1717
ones)
1818
from numpy.core import overrides
19+
from numpy.exceptions import RankWarning
1920
from numpy.lib.twodim_base import diag, vander
2021
from numpy.lib.function_base import trim_zeros
2122
from numpy.lib.type_check import iscomplex, real, imag, mintypecode
@@ -26,18 +27,6 @@
2627
overrides.array_function_dispatch, module='numpy')
2728

2829

29-
@set_module('numpy')
30-
class RankWarning(UserWarning):
31-
"""
32-
Issued by `polyfit` when the Vandermonde matrix is rank deficient.
33-
34-
For more information, a way to suppress the warning, and an example of
35-
`RankWarning` being issued, see `polyfit`.
36-
37-
"""
38-
pass
39-
40-
4130
def _poly_dispatcher(seq_of_zeros):
4231
return seq_of_zeros
4332

@@ -539,7 +528,7 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False):
539528
The warnings can be turned off by
540529
541530
>>> import warnings
542-
>>> warnings.simplefilter('ignore', np.RankWarning)
531+
>>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
543532
544533
See Also
545534
--------
@@ -606,7 +595,7 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False):
606595
High-order polynomials may oscillate wildly:
607596
608597
>>> with warnings.catch_warnings():
609-
... warnings.simplefilter('ignore', np.RankWarning)
598+
... warnings.simplefilter('ignore', np.exceptions.RankWarning)
610599
... p30 = np.poly1d(np.polyfit(x, y, 30))
611600
...
612601
>>> p30(4)

numpy/lib/polynomial.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ from typing import (
99
)
1010

1111
from numpy import (
12-
RankWarning as RankWarning,
1312
poly1d as poly1d,
1413
unsignedinteger,
1514
signedinteger,

numpy/polynomial/chebyshev.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ def chebfit(x, y, deg, rcond=None, full=False, w=None):
16151615
warnings can be turned off by
16161616
16171617
>>> import warnings
1618-
>>> warnings.simplefilter('ignore', np.RankWarning)
1618+
>>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
16191619
16201620
See Also
16211621
--------

numpy/polynomial/hermite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ def hermfit(x, y, deg, rcond=None, full=False, w=None):
13411341
warnings can be turned off by
13421342
13431343
>>> import warnings
1344-
>>> warnings.simplefilter('ignore', np.RankWarning)
1344+
>>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
13451345
13461346
See Also
13471347
--------

numpy/polynomial/hermite_e.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ def hermefit(x, y, deg, rcond=None, full=False, w=None):
13321332
warnings can be turned off by
13331333
13341334
>>> import warnings
1335-
>>> warnings.simplefilter('ignore', np.RankWarning)
1335+
>>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
13361336
13371337
See Also
13381338
--------

numpy/polynomial/laguerre.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,7 @@ def lagfit(x, y, deg, rcond=None, full=False, w=None):
13381338
warnings can be turned off by
13391339
13401340
>>> import warnings
1341-
>>> warnings.simplefilter('ignore', np.RankWarning)
1341+
>>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
13421342
13431343
See Also
13441344
--------

numpy/polynomial/legendre.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ def legfit(x, y, deg, rcond=None, full=False, w=None):
13561356
warnings can be turned off by
13571357
13581358
>>> import warnings
1359-
>>> warnings.simplefilter('ignore', np.RankWarning)
1359+
>>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
13601360
13611361
See Also
13621362
--------

numpy/polynomial/polynomial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None):
12851285
be turned off by:
12861286
12871287
>>> import warnings
1288-
>>> warnings.simplefilter('ignore', np.RankWarning)
1288+
>>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
12891289
12901290
See Also
12911291
--------

numpy/polynomial/polyutils.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
This module provides: error and warning objects; a polynomial base class;
55
and some routines used in both the `polynomial` and `chebyshev` modules.
66
7-
Warning objects
8-
---------------
9-
10-
.. autosummary::
11-
:toctree: generated/
12-
13-
RankWarning raised in least-squares fit for rank-deficient matrix.
14-
157
Functions
168
---------
179
@@ -34,20 +26,12 @@
3426

3527
from numpy.core.multiarray import dragon4_positional, dragon4_scientific
3628
from numpy.core.umath import absolute
29+
from numpy.exceptions import RankWarning
3730

3831
__all__ = [
39-
'RankWarning', 'as_series', 'trimseq',
40-
'trimcoef', 'getdomain', 'mapdomain', 'mapparms',
32+
'as_series', 'trimseq', 'trimcoef', 'getdomain', 'mapdomain', 'mapparms',
4133
'format_float']
4234

43-
#
44-
# Warnings and Exceptions
45-
#
46-
47-
class RankWarning(UserWarning):
48-
"""Issued by chebfit when the design matrix is rank deficient."""
49-
pass
50-
5135
#
5236
# Helper functions to convert inputs to 1-D arrays
5337
#

numpy/polynomial/polyutils.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
__all__: list[str]
22

3-
class RankWarning(UserWarning): ...
4-
53
def trimseq(seq): ...
64
def as_series(alist, trim=...): ...
75
def trimcoef(c, tol=...): ...

numpy/polynomial/tests/test_classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from numpy.testing import (
1414
assert_almost_equal, assert_raises, assert_equal, assert_,
1515
)
16-
from numpy.polynomial.polyutils import RankWarning
16+
from numpy.exceptions import RankWarning
1717

1818
#
1919
# fixtures
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import numpy as np
21
import numpy.exceptions as ex
32

43
reveal_type(ex.ModuleDeprecationWarning()) # E: ModuleDeprecationWarning
54
reveal_type(ex.VisibleDeprecationWarning()) # E: VisibleDeprecationWarning
65
reveal_type(ex.ComplexWarning()) # E: ComplexWarning
7-
reveal_type(np.RankWarning()) # E: RankWarning
6+
reveal_type(ex.RankWarning()) # E: RankWarning
87
reveal_type(ex.TooHardError()) # E: TooHardError
98
reveal_type(ex.AxisError("test")) # E: AxisError
109
reveal_type(ex.AxisError(5, 1)) # E: AxisError

0 commit comments

Comments
 (0)
0