8000 API: Fix RankWarning typing test · numpy/numpy@775b5dd · GitHub
[go: up one dir, main page]

Skip to content

Commit 775b5dd

Browse files
committed
API: Fix RankWarning typing test
1 parent c55bee6 commit 775b5dd

File tree

12 files changed

+23
-23
lines changed

12 files changed

+23
-23
lines changed

numpy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ def __getattr__(attr):
231231
return testing
232232

233233
raise AttributeError("module {!r} has no attribute "
234-
"{!r}".format(__name__, attr))
235-
234+
"{!r}".format(__name__, attr))
235+
236236
def __dir__():
237237
public_symbols = globals().keys() | {'testing'}
238238
public_symbols -= {"core", "matrixlib"}

numpy/core/tests/test_indexing.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99
from numpy.core._multiarray_tests import array_indexing
1010
from itertools import product
11-
from numpy.exceptions import ComplexWarning
11+
from numpy.exceptions import ComplexWarning, VisibleDeprecationWarning
1212
from numpy.testing import (
1313
assert_, assert_equal, assert_raises, assert_raises_regex,
1414
assert_array_equal, assert_warns, HAS_REFCOUNT, IS_WASM
@@ -1200,9 +1200,7 @@ def test_multidim(self):
12001200
# This is so that np.array(True) is not accepted in a full integer
12011201
# index, when running the file separately.
12021202
warnings.filterwarnings('error', '', DeprecationWarning)
1203-
warnings.filterwarnings(
1204-
'error', '', np.exceptions.VisibleDeprecationWarning
1205-
)
1203+
warnings.filterwarnings('error', '', VisibleDeprecationWarning)
12061204

12071205
def isskip(idx):
12081206
return isinstance(idx, str) and idx == "skip"

numpy/core/tests/test_regression.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pickle
1010

1111
import numpy as np
12-
from numpy.exceptions import AxisError
12+
from numpy.exceptions import AxisError, ComplexWarning
1313
from numpy.testing import (
1414
assert_, assert_equal, IS_PYPY, assert_almost_equal,
1515
assert_array_equal, assert_array_almost_equal, assert_raises,
@@ -1629,9 +1629,9 @@ def test_fromfile_tofile_seeks(self):
16291629
def test_complex_scalar_warning(self):
16301630
for tp in [np.csingle, np.cdouble, np.clongdouble]:
16311631
x = tp(1+2j)
1632-
assert_warns(np.exceptions.ComplexWarning, float, x)
1632+
assert_warns(ComplexWarning, float, x)
16331633
with suppress_warnings() as sup:
1634-
sup.filter(np.exceptions.ComplexWarning)
1634+
sup.filter(ComplexWarning)
16351635
assert_equal(float(x), float(x.real))
16361636

16371637
def test_complex_scalar_complex_cast(self):

numpy/core/tests/test_scalarmath.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from hypothesis.extra import numpy as hynp
1212

1313
import numpy as np
14+
from numpy.exceptions import ComplexWarning
1415
from numpy.testing import (
1516
assert_, assert_equal, assert_raises, assert_almost_equal,
1617
assert_array_equal, IS_PYPY, suppress_warnings, _gen_alignment_data,
@@ -511,7 +512,7 @@ def test_int_from_infinite_longdouble(self):
511512
x = np.longdouble(np.inf)
512513
assert_raises(OverflowError, int, x)
513514
with suppress_warnings() as sup:
514-
sup.record(np.exceptions.ComplexWarning)
515+
sup.record(ComplexWarning)
515516
x = np.clongdouble(np.inf)
516517
assert_raises(OverflowError, int, x)
517518
assert_equal(len(sup.log), 1)
@@ -521,7 +522,7 @@ def test_int_from_infinite_longdouble___int__(self):
521522
x = np.longdouble(np.inf)
522523
assert_raises(OverflowError, x.__int__)
523524
with suppress_warnings() as sup:
524-
sup.record(np.exceptions.ComplexWarning)
525+
sup.record(ComplexWarning)
525526
x = np.clongdouble(np.inf)
526527
assert_raises(OverflowError, x.__int__)
527528
assert_equal(len(sup.log), 1)

numpy/lib/polynomial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False):
539539
The warnings can be turned off by
540540
541541
>>> import warnings
542-
>>> warnings.simplefilter('ignore', np.exceptions.RankWarning)
542+
>>> warnings.simplefilter('ignore', np.RankWarning)
543543
544544
See Also
545545
--------
@@ -606,7 +606,7 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False):
606606
High-order polynomials may oscillate wildly:
607607
608608
>>> with warnings.catch_warnings():
609-
... warnings.simplefilter('ignore', np.exceptions.RankWarning)
609+
... warnings.simplefilter('ignore', np.RankWarning)
610610
... p30 = np.poly1d(np.polyfit(x, y, 30))
611611
...
612612
>>> p30(4)

numpy/lib/tests/test_nanfunctions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import numpy as np
66
from numpy.core.numeric import normalize_axis_tuple
7-
from numpy.exceptions import AxisError
7+
from numpy.exceptions import AxisError, ComplexWarning
88
from numpy.lib.nanfunctions import _nan_mask, _replace_nan
99
from numpy.testing import (
1010
assert_, assert_equal, assert_almost_equal, assert_raises,
@@ -473,7 +473,7 @@ def test_dtype_from_dtype(self):
473473
with suppress_warnings() as sup:
474474
if nf in {np.nanstd, np.nanvar} and c in 'FDG':
475475
# Giving the warning is a small bug, see gh-8000
476-
sup.filter(np.exceptions.ComplexWarning)
476+
sup.filter(ComplexWarning)
477477
tgt = rf(mat, dtype=np.dtype(c), axis=1).dtype.type
478478
res = nf(mat, dtype=np.dtype(c), axis=1).dtype.type
479479
assert_(res is tgt)
@@ -490,7 +490,7 @@ def test_dtype_from_char(self):
490490
with suppress_warnings() as sup:
491491
if nf in {np.nanstd, np.nanvar} and c in 'FDG':
492492
# Giving the warning is a small bug, see gh-8000
493-
sup.filter(np.exceptions.ComplexWarning)
493+
sup.filter(ComplexWarning)
494494
tgt = rf(mat, dtype=c, axis=1).dtype.type
495495
res = nf(mat, dtype=c, axis=1).dtype.type
496496
assert_(res is tgt)
@@ -710,7 +710,7 @@ def test_ddof_too_big(self):
710710
for ddof in range(5):
711711
with suppress_warnings() as sup:
712712
sup.record(RuntimeWarning)
713-
sup.filter(np.exceptions.ComplexWarning)
713+
sup.filter(ComplexWarning)
714714
tgt = [ddof >= d for d in dsize]
715715
res = nf(_ndat, axis=1, ddof=ddof)
716716
assert_equal(np.isnan(res), tgt)

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.exceptions.RankWarning)
1618+
>>> warnings.simplefilter('ignore', np.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.exceptions.RankWarning)
1344+
>>> warnings.simplefilter('ignore', np.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.exceptions.RankWarning)
1335+
>>> warnings.simplefilter('ignore', np.RankWarning)
13361336
13371337
See Also
13381338
--------

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.exceptions.RankWarning)
1359+
>>> warnings.simplefilter('ignore', np.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.exceptions.RankWarning)
1288+
>>> warnings.simplefilter('ignore', np.RankWarning)
12891289
12901290
See Also
12911291
--------
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import numpy as np
12
import numpy.exceptions as ex
23

34
reveal_type(ex.ModuleDeprecationWarning()) # E: ModuleDeprecationWarning
45
reveal_type(ex.VisibleDeprecationWarning()) # E: VisibleDeprecationWarning
56
reveal_type(ex.ComplexWarning()) # E: ComplexWarning
6-
reveal_type(ex.RankWarning()) # E: RankWarning
7+
reveal_type(np.RankWarning()) # E: RankWarning
78
reveal_type(ex.TooHardError()) # E: TooHardError
89
reveal_type(ex.AxisError("test")) # E: AxisError
910
reveal_type(ex.AxisError(5, 1)) # E: AxisError

0 commit comments

Comments
 (0)
0