The following issues were found
numpy/core/tests/test_multiarray.py
3262 issues
Line: 13
Column: 1
import os
import gc
import weakref
import pytest
from contextlib import contextmanager
from numpy.compat import pickle
import pathlib
Reported by Pylint.
Line: 23
Column: 1
from decimal import Decimal
import numpy as np
import numpy.core._multiarray_tests as _multiarray_tests
from numpy.core._rational_tests import rational
from numpy.testing import (
assert_, assert_raises, assert_warns, assert_equal, assert_almost_equal,
assert_array_equal, assert_raises_regex, assert_array_almost_equal,
assert_allclose, IS_PYPY, IS_PYSTON, HAS_REFCOUNT, assert_array_less,
Reported by Pylint.
Line: 24
Column: 1
import numpy as np
import numpy.core._multiarray_tests as _multiarray_tests
from numpy.core._rational_tests import rational
from numpy.testing import (
assert_, assert_raises, assert_warns, assert_equal, assert_almost_equal,
assert_array_equal, assert_raises_regex, assert_array_almost_equal,
assert_allclose, IS_PYPY, IS_PYSTON, HAS_REFCOUNT, assert_array_less,
runstring, temppath, suppress_warnings, break_cycles,
Reported by Pylint.
Line: 59
Column: 11
size = functools.reduce(operator.mul, shape) * dtype.itemsize
buf = np.empty(size + 2*align + 1, np.uint8)
ptr = buf.__array_interface__['data'][0]
offset = ptr % align
if offset != 0:
offset = align - offset
if (ptr % (2*align)) == 0:
offset += align
Reported by Pylint.
Line: 164
Column: 9
# Test that the writeable flag can be changed for an array wrapping
# low level C-data, but not owning its data.
# Also see that this is deprecated to change from python.
from numpy.core._multiarray_tests import get_c_wrapping_array
arr_writeable = get_c_wrapping_array(True)
assert not arr_writeable.flags.owndata
assert arr_writeable.flags.writeable
view = arr_writeable[...]
Reported by Pylint.
Line: 581
Column: 13
b = np.array([b'done'])
class bad_sequence:
def __getitem__(self): pass
def __len__(self): raise RuntimeError
assert_raises(ValueError, operator.setitem, u, 0, [])
assert_raises(ValueError, operator.setitem, b, 0, [])
Reported by Pylint.
Line: 1674
Column: 26
[False],
[True]])
for _ax in [0, None]:
assert_equal(a.all(axis=_ax, where=wh_lower),
np.all(a[wh_lower[:,0],:], axis=_ax))
assert_equal(np.all(a, axis=_ax, where=wh_lower),
a[wh_lower[:,0],:].all(axis=_ax))
assert_equal(a.all(where=wh_full), True)
Reported by Pylint.
Line: 1679
Column: 22
assert_equal(np.all(a, axis=_ax, where=wh_lower),
a[wh_lower[:,0],:].all(axis=_ax))
assert_equal(a.all(where=wh_full), True)
assert_equal(np.all(a, where=wh_full), True)
assert_equal(a.all(where=False), True)
assert_equal(np.all(a, where=False), True)
def test_any_where(self):
Reported by Pylint.
Line: 1681
Column: 22
assert_equal(a.all(where=wh_full), True)
assert_equal(np.all(a, where=wh_full), True)
assert_equal(a.all(where=False), True)
assert_equal(np.all(a, where=False), True)
def test_any_where(self):
a = np.array([[True, False, True],
[False, False, False],
Reported by Pylint.
Line: 1695
Column: 26
[True],
[False]])
for _ax in [0, None]:
assert_equal(a.any(axis=_ax, where=wh_middle),
np.any(a[wh_middle[:,0],:], axis=_ax))
assert_equal(np.any(a, axis=_ax, where=wh_middle),
a[wh_middle[:,0],:].any(axis=_ax))
assert_equal(a.any(where=wh_full), False)
assert_equal(np.any(a, where=wh_full), False)
Reported by Pylint.
numpy/typing/tests/data/reveal/random.py
2183 issues
Line: 15
Column: 1
philox = np.random.Philox()
seedless_seq = np.random.bit_generator.SeedlessSeedSequence()
reveal_type(def_rng) # E: numpy.random._generator.Generator
reveal_type(mt19937) # E: numpy.random._mt19937.MT19937
reveal_type(pcg64) # E: numpy.random._pcg64.PCG64
reveal_type(sfc64) # E: numpy.random._sfc64.SFC64
reveal_type(philox) # E: numpy.random._philox.Philox
reveal_type(seed_seq) # E: numpy.random.bit_generator.SeedSequence
Reported by Pylint.
Line: 16
Column: 1
seedless_seq = np.random.bit_generator.SeedlessSeedSequence()
reveal_type(def_rng) # E: numpy.random._generator.Generator
reveal_type(mt19937) # E: numpy.random._mt19937.MT19937
reveal_type(pcg64) # E: numpy.random._pcg64.PCG64
reveal_type(sfc64) # E: numpy.random._sfc64.SFC64
reveal_type(philox) # E: numpy.random._philox.Philox
reveal_type(seed_seq) # E: numpy.random.bit_generator.SeedSequence
reveal_type(seedless_seq) # E: numpy.random.bit_generator.SeedlessSeedSequence
Reported by Pylint.
Line: 17
Column: 1
reveal_type(def_rng) # E: numpy.random._generator.Generator
reveal_type(mt19937) # E: numpy.random._mt19937.MT19937
reveal_type(pcg64) # E: numpy.random._pcg64.PCG64
reveal_type(sfc64) # E: numpy.random._sfc64.SFC64
reveal_type(philox) # E: numpy.random._philox.Philox
reveal_type(seed_seq) # E: numpy.random.bit_generator.SeedSequence
reveal_type(seedless_seq) # E: numpy.random.bit_generator.SeedlessSeedSequence
Reported by Pylint.
Line: 18
Column: 1
reveal_type(def_rng) # E: numpy.random._generator.Generator
reveal_type(mt19937) # E: numpy.random._mt19937.MT19937
reveal_type(pcg64) # E: numpy.random._pcg64.PCG64
reveal_type(sfc64) # E: numpy.random._sfc64.SFC64
reveal_type(philox) # E: numpy.random._philox.Philox
reveal_type(seed_seq) # E: numpy.random.bit_generator.SeedSequence
reveal_type(seedless_seq) # E: numpy.random.bit_generator.SeedlessSeedSequence
mt19937_jumped = mt19937.jumped()
Reported by Pylint.
Line: 19
Column: 1
reveal_type(mt19937) # E: numpy.random._mt19937.MT19937
reveal_type(pcg64) # E: numpy.random._pcg64.PCG64
reveal_type(sfc64) # E: numpy.random._sfc64.SFC64
reveal_type(philox) # E: numpy.random._philox.Philox
reveal_type(seed_seq) # E: numpy.random.bit_generator.SeedSequence
reveal_type(seedless_seq) # E: numpy.random.bit_generator.SeedlessSeedSequence
mt19937_jumped = mt19937.jumped()
mt19937_jumped3 = mt19937.jumped(3)
Reported by Pylint.
Line: 20
Column: 1
reveal_type(pcg64) # E: numpy.random._pcg64.PCG64
reveal_type(sfc64) # E: numpy.random._sfc64.SFC64
reveal_type(philox) # E: numpy.random._philox.Philox
reveal_type(seed_seq) # E: numpy.random.bit_generator.SeedSequence
reveal_type(seedless_seq) # E: numpy.random.bit_generator.SeedlessSeedSequence
mt19937_jumped = mt19937.jumped()
mt19937_jumped3 = mt19937.jumped(3)
mt19937_raw = mt19937.random_raw()
Reported by Pylint.
Line: 21
Column: 1
reveal_type(sfc64) # E: numpy.random._sfc64.SFC64
reveal_type(philox) # E: numpy.random._philox.Philox
reveal_type(seed_seq) # E: numpy.random.bit_generator.SeedSequence
reveal_type(seedless_seq) # E: numpy.random.bit_generator.SeedlessSeedSequence
mt19937_jumped = mt19937.jumped()
mt19937_jumped3 = mt19937.jumped(3)
mt19937_raw = mt19937.random_raw()
mt19937_raw_arr = mt19937.random_raw(5)
Reported by Pylint.
Line: 28
Column: 1
mt19937_raw = mt19937.random_raw()
mt19937_raw_arr = mt19937.random_raw(5)
reveal_type(mt19937_jumped) # E: numpy.random._mt19937.MT19937
reveal_type(mt19937_jumped3) # E: numpy.random._mt19937.MT19937
reveal_type(mt19937_raw) # E: int
reveal_type(mt19937_raw_arr) # E: numpy.ndarray[Any, numpy.dtype[numpy.unsignedinteger[numpy.typing._64Bit]]]
reveal_type(mt19937.lock) # E: threading.Lock
Reported by Pylint.
Line: 29
Column: 1
mt19937_raw_arr = mt19937.random_raw(5)
reveal_type(mt19937_jumped) # E: numpy.random._mt19937.MT19937
reveal_type(mt19937_jumped3) # E: numpy.random._mt19937.MT19937
reveal_type(mt19937_raw) # E: int
reveal_type(mt19937_raw_arr) # E: numpy.ndarray[Any, numpy.dtype[numpy.unsignedinteger[numpy.typing._64Bit]]]
reveal_type(mt19937.lock) # E: threading.Lock
pcg64_jumped = pcg64.jumped()
Reported by Pylint.
Line: 30
Column: 1
reveal_type(mt19937_jumped) # E: numpy.random._mt19937.MT19937
reveal_type(mt19937_jumped3) # E: numpy.random._mt19937.MT19937
reveal_type(mt19937_raw) # E: int
reveal_type(mt19937_raw_arr) # E: numpy.ndarray[Any, numpy.dtype[numpy.unsignedinteger[numpy.typing._64Bit]]]
reveal_type(mt19937.lock) # E: threading.Lock
pcg64_jumped = pcg64.jumped()
pcg64_jumped3 = pcg64.jumped(3)
Reported by Pylint.
numpy/ma/tests/test_core.py
2118 issues
Line: 1
Column: 1
# pylint: disable-msg=W0400,W0511,W0611,W0612,W0614,R0201,E1102
"""Tests suite for MaskedArray & subclassing.
:author: Pierre Gerard-Marchant
:contact: pierregm_at_uga_dot_edu
"""
__author__ = "Pierre GF Gerard-Marchant"
import sys
Reported by Pylint.
Line: 14
Column: 1
import operator
import itertools
import textwrap
import pytest
from functools import reduce
import numpy as np
Reported by Pylint.
Line: 176
Column: 38
def test_concatenate_flexible(self):
# Tests the concatenation on flexible arrays.
data = masked_array(list(zip(np.random.rand(10),
np.arange(10))),
dtype=[('a', float), ('b', int)])
test = concatenate([data[:5], data[5:]])
assert_equal_records(test, data)
Reported by Pylint.
Line: 269
Column: 13
def test_unknown_keyword_parameter(self):
with pytest.raises(TypeError, match="unexpected keyword argument"):
MaskedArray([1, 2, 3], maks=[0, 1, 0]) # `mask` is misspelled.
def test_asarray(self):
(x, y, a10, m1, m2, xm, ym, z, zm, xf) = self.d
xm.fill_value = -9999
xm._hardmask = True
Reported by Pylint.
Line: 722
Column: 25
x = array([1., 2., 3., 4., 5.])
c = array([1, 1, 1, 0, 0])
x[2] = masked
z = where(c, x, -x)
assert_equal(z, [1., 2., 0., -4., -5])
c[0] = masked
z = where(c, x, -x)
assert_equal(z, [1., 2., 0., -4., -5])
assert_(z[0] is masked)
Reported by Pylint.
Line: 725
Column: 25
z = where(c, x, -x)
assert_equal(z, [1., 2., 0., -4., -5])
c[0] = masked
z = where(c, x, -x)
assert_equal(z, [1., 2., 0., -4., -5])
assert_(z[0] is masked)
assert_(z[1] is not masked)
assert_(z[2] is masked)
Reported by Pylint.
Line: 825
Column: 41
assert_equal(a._optinfo["key"], np.exp(a)._optinfo["key"])
assert_equal(a._optinfo["key"], np.abs(a)._optinfo["key"])
assert_equal(a._optinfo["key"], array(a, copy=True)._optinfo["key"])
assert_equal(a._optinfo["key"], np.zeros_like(a)._optinfo["key"])
def test_fancy_printoptions(self):
# Test printing a masked array w/ fancy dtype.
fancydtype = np.dtype([('x', int), ('y', [('t', int), ('s', float)])])
test = array([(1, (2, 3.0)), (4, (5, 6.0))],
Reported by Pylint.
Line: 863
Column: 22
mask=[[0, 1], [1, 0]], dtype=float)
assert_equal(test, control)
assert_equal(test.dtype, control.dtype)
assert_equal(test.mask, control.mask)
# On masked array with nested structure
ndtype = [('a', int), ('b', [('ba', int), ('bb', float)])]
a = array([(1, (1, 1.1)), (2, (2, 2.2))],
mask=[(0, (1, 0)), (1, (0, 1))], dtype=ndtype)
test = flatten_structured_array(a)
Reported by Pylint.
Line: 863
Column: 22
mask=[[0, 1], [1, 0]], dtype=float)
assert_equal(test, control)
assert_equal(test.dtype, control.dtype)
assert_equal(test.mask, control.mask)
# On masked array with nested structure
ndtype = [('a', int), ('b', [('ba', int), ('bb', float)])]
a = array([(1, (1, 1.1)), (2, (2, 2.2))],
mask=[(0, (1, 0)), (1, (0, 1))], dtype=ndtype)
test = flatten_structured_array(a)
Reported by Pylint.
Line: 873
Column: 22
mask=[[0, 1, 0], [1, 0, 1]], dtype=float)
assert_equal(test, control)
assert_equal(test.dtype, control.dtype)
assert_equal(test.mask, control.mask)
# Keeping the initial shape
ndtype = [('a', int), ('b', float)]
a = np.array([[(1, 1), ], [(2, 2), ]], dtype=ndtype)
test = flatten_structured_array(a)
control = np.array([[[1., 1.], ], [[2., 2.], ]], dtype=float)
Reported by Pylint.
numpy/core/tests/test_umath.py
1558 issues
Line: 5
Column: 1
import warnings
import fnmatch
import itertools
import pytest
import sys
import os
from fractions import Fraction
from functools import reduce
Reported by Pylint.
Line: 72
Column: 25
class TestConstants:
def test_pi(self):
assert_allclose(ncu.pi, 3.141592653589793, 1e-15)
def test_e(self):
assert_allclose(ncu.e, 2.718281828459045, 1e-15)
def test_euler_gamma(self):
Reported by Pylint.
Line: 483
Column: 57
with suppress_warnings() as sup:
sup.filter(RuntimeWarning, "invalid value encountered in floor_divide")
div = np.floor_divide(fnan, fone)
assert(np.isnan(div)), "dt: %s, div: %s" % (dt, div)
div = np.floor_divide(fone, fnan)
assert(np.isnan(div)), "dt: %s, div: %s" % (dt, div)
div = np.floor_divide(fnan, fzer)
assert(np.isnan(div)), "dt: %s, div: %s" % (dt, div)
# verify 1.0//0.0 computations return inf
Reported by Pylint.
Line: 485
Column: 57
div = np.floor_divide(fnan, fone)
assert(np.isnan(div)), "dt: %s, div: %s" % (dt, div)
div = np.floor_divide(fone, fnan)
assert(np.isnan(div)), "dt: %s, div: %s" % (dt, div)
div = np.floor_divide(fnan, fzer)
assert(np.isnan(div)), "dt: %s, div: %s" % (dt, div)
# verify 1.0//0.0 computations return inf
with np.errstate(divide='ignore'):
z = np.floor_divide(y, x)
Reported by Pylint.
Line: 487
Column: 57
div = np.floor_divide(fone, fnan)
assert(np.isnan(div)), "dt: %s, div: %s" % (dt, div)
div = np.floor_divide(fnan, fzer)
assert(np.isnan(div)), "dt: %s, div: %s" % (dt, div)
# verify 1.0//0.0 computations return inf
with np.errstate(divide='ignore'):
z = np.floor_divide(y, x)
assert_(np.isinf(z).all())
Reported by Pylint.
Line: 732
Column: 44
y **= 2
assert_equal(y, [1., 4., 9.])
assert_almost_equal(x**(-1), [1., 0.5, 1./3])
assert_almost_equal(x**(0.5), [1., ncu.sqrt(2), ncu.sqrt(3)])
for out, inp, msg in _gen_alignment_data(dtype=np.float32,
type='unary',
max_size=11):
exp = [ncu.sqrt(i) for i in inp]
Reported by Pylint.
Line: 732
Column: 57
y **= 2
assert_equal(y, [1., 4., 9.])
assert_almost_equal(x**(-1), [1., 0.5, 1./3])
assert_almost_equal(x**(0.5), [1., ncu.sqrt(2), ncu.sqrt(3)])
for out, inp, msg in _gen_alignment_data(dtype=np.float32,
type='unary',
max_size=11):
exp = [ncu.sqrt(i) for i in inp]
Reported by Pylint.
Line: 737
Column: 20
for out, inp, msg in _gen_alignment_data(dtype=np.float32,
type='unary',
max_size=11):
exp = [ncu.sqrt(i) for i in inp]
assert_almost_equal(inp**(0.5), exp, err_msg=msg)
np.sqrt(inp, out=out)
assert_equal(out, exp, err_msg=msg)
for out, inp, msg in _gen_alignment_data(dtype=np.float64,
Reported by Pylint.
Line: 745
Column: 20
for out, inp, msg in _gen_alignment_data(dtype=np.float64,
type='unary',
max_size=7):
exp = [ncu.sqrt(i) for i in inp]
assert_almost_equal(inp**(0.5), exp, err_msg=msg)
np.sqrt(inp, out=out)
assert_equal(out, exp, err_msg=msg)
def test_power_complex(self):
Reported by Pylint.
Line: 761
Column: 40
assert_almost_equal(x**(-2), [1/(1+2j)**2, 1/(2+3j)**2, 1/(3+4j)**2])
assert_almost_equal(x**(-3), [(-11+2j)/125, (-46-9j)/2197,
(-117-44j)/15625])
assert_almost_equal(x**(0.5), [ncu.sqrt(1+2j), ncu.sqrt(2+3j),
ncu.sqrt(3+4j)])
norm = 1./((x**14)[0])
assert_almost_equal(x**14 * norm,
[i * norm for i in [-76443+16124j, 23161315+58317492j,
5583548873 + 2465133864j]])
Reported by Pylint.
numpy/core/tests/test_numeric.py
1449 issues
Line: 5
Column: 1
import warnings
import itertools
import platform
import pytest
import math
from decimal import Decimal
import numpy as np
from numpy.core import umath
Reported by Pylint.
Line: 17
Column: 1
assert_array_equal, assert_almost_equal, assert_array_almost_equal,
assert_warns, assert_array_max_ulp, HAS_REFCOUNT
)
from numpy.core._rational_tests import rational
from hypothesis import assume, given, strategies as st
from hypothesis.extra import numpy as hynp
Reported by Pylint.
Line: 19
Column: 1
)
from numpy.core._rational_tests import rational
from hypothesis import assume, given, strategies as st
from hypothesis.extra import numpy as hynp
class TestResize:
def test_copies(self):
Reported by Pylint.
Line: 20
Column: 1
from numpy.core._rational_tests import rational
from hypothesis import assume, given, strategies as st
from hypothesis.extra import numpy as hynp
class TestResize:
def test_copies(self):
A = np.array([[1, 2], [3, 4]])
Reported by Pylint.
Line: 1041
Column: 5
[[np.dtype("V6"), np.dtype("V10")],
[np.dtype([("name1", "i8")]), np.dtype([("name2", "i8")])],
[np.dtype("i8,i8"), np.dtype("i4,i4")],
])
def test_invalid_void_promotion(self, dtype1, dtype2):
# Mainly test structured void promotion, which currently allows
# byte-swapping, but nothing else:
with pytest.raises(TypeError):
np.promote_types(dtype1, dtype2)
Reported by Pylint.
Line: 1052
Column: 5
[[np.dtype("V10"), np.dtype("V10")],
[np.dtype([("name1", "<i8")]), np.dtype([("name1", ">i8")])],
[np.dtype("i8,i8"), np.dtype("i8,>i8")],
])
def test_valid_void_promotion(self, dtype1, dtype2):
assert np.promote_types(dtype1, dtype2) is dtype1
def test_can_cast(self):
assert_(np.can_cast(np.int32, np.int64))
Reported by Pylint.
Line: 1428
Column: 15
size = (5, 5, 5, 5)
msg = "Mismatch for axis: %s"
rng = np.random.RandomState(1234)
m = rng.randint(-100, 100, size=size)
n = m.astype(object)
for length in range(len(axis)):
for combo in combinations(axis, length):
Reported by Pylint.
Line: 1549
Column: 15
dt = np.dtype([("", dt)])
dt = np.dtype([("", dt)] * 2)
# The array should be large enough to likely run into threading issues
arr = np.random.uniform(size=(5000, 4)).view(dt)[:, 0]
def func(arr):
arr.nonzero()
tpe = ThreadPoolExecutor(max_workers=8)
futures = [tpe.submit(func, arr) for _ in range(10)]
Reported by Pylint.
Line: 3172
Column: 13
class TestMoveaxis:
def test_move_to_end(self):
x = np.random.randn(5, 6, 7)
for source, expected in [(0, (6, 7, 5)),
(1, (5, 7, 6)),
(2, (5, 6, 7)),
(-1, (5, 6, 7))]:
actual = np.moveaxis(x, source, -1).shape
Reported by Pylint.
Line: 3181
Column: 13
assert_(actual, expected)
def test_move_new_position(self):
x = np.random.randn(1, 2, 3, 4)
for source, destination, expected in [
(0, 1, (2, 1, 3, 4)),
(1, 2, (1, 3, 2, 4)),
(1, -1, (1, 3, 4, 2)),
]:
Reported by Pylint.
numpy/lib/tests/test_function_base.py
1432 issues
Line: 7
Column: 1
import decimal
from fractions import Fraction
import math
import pytest
import hypothesis
from hypothesis.extra.numpy import arrays
import hypothesis.strategies as st
Reported by Pylint.
Line: 8
Column: 1
from fractions import Fraction
import math
import pytest
import hypothesis
from hypothesis.extra.numpy import arrays
import hypothesis.strategies as st
import numpy as np
Reported by Pylint.
Line: 9
Column: 1
import math
import pytest
import hypothesis
from hypothesis.extra.numpy import arrays
import hypothesis.strategies as st
import numpy as np
from numpy import ma
Reported by Pylint.
Line: 10
Column: 1
import pytest
import hypothesis
from hypothesis.extra.numpy import arrays
import hypothesis.strategies as st
import numpy as np
from numpy import ma
from numpy.testing import (
Reported by Pylint.
Line: 592
Column: 22
assert_equal(b.ptp(axis=0), [5.0, 7.0, 7.0])
assert_equal(b.ptp(axis=-1), [6.0, 6.0, 6.0])
assert_equal(b.ptp(axis=0, keepdims=True), [[5.0, 7.0, 7.0]])
assert_equal(b.ptp(axis=(0,1), keepdims=True), [[8.0]])
class TestCumsum:
Reported by Pylint.
Line: 593
Column: 22
assert_equal(b.ptp(axis=-1), [6.0, 6.0, 6.0])
assert_equal(b.ptp(axis=0, keepdims=True), [[5.0, 7.0, 7.0]])
assert_equal(b.ptp(axis=(0,1), keepdims=True), [[8.0]])
class TestCumsum:
def test_basic(self):
Reported by Pylint.
Line: 980
Column: 9
assert_(np.all(num_error < 0.03) == True)
# test with unevenly spaced
np.random.seed(0)
x = np.sort(np.random.random(10))
y = 2 * x ** 3 + 4 * x ** 2 + 2 * x
analytical = 6 * x ** 2 + 8 * x + 2
num_error = np.abs((np.gradient(y, x, edge_order=2) / analytical) - 1)
assert_(np.all(num_error < 0.03) == True)
Reported by Pylint.
Line: 981
Column: 21
# test with unevenly spaced
np.random.seed(0)
x = np.sort(np.random.random(10))
y = 2 * x ** 3 + 4 * x ** 2 + 2 * x
analytical = 6 * x ** 2 + 8 * x + 2
num_error = np.abs((np.gradient(y, x, edge_order=2) / analytical) - 1)
assert_(np.all(num_error < 0.03) == True)
Reported by Pylint.
Line: 3050
Column: 13
assert_equal(b, np.array([2.5]))
def test_extended_axis(self):
o = np.random.normal(size=(71, 23))
x = np.dstack([o] * 10)
assert_equal(np.percentile(x, 30, axis=(0, 1)), np.percentile(o, 30))
x = np.moveaxis(x, -1, 0)
assert_equal(np.percentile(x, 30, axis=(-2, -1)), np.percentile(o, 30))
x = x.swapaxes(0, 1).copy()
Reported by Pylint.
Line: 3065
Column: 9
np.percentile(x, [25, 60], axis=0))
d = np.arange(3 * 5 * 7 * 11).reshape((3, 5, 7, 11))
np.random.shuffle(d.ravel())
assert_equal(np.percentile(d, 25, axis=(0, 1, 2))[0],
np.percentile(d[:,:,:, 0].flatten(), 25))
assert_equal(np.percentile(d, [10, 90], axis=(0, 1, 3))[:, 1],
np.percentile(d[:,:, 1,:].flatten(), [10, 90]))
assert_equal(np.percentile(d, 25, axis=(3, 1, -4))[2],
Reported by Pylint.
numpy/core/tests/test_regression.py
1194 issues
Line: 5
Column: 1
import sys
import gc
import tempfile
import pytest
from os import path
from io import BytesIO
from itertools import chain
import numpy as np
Reported by Pylint.
Line: 201
Column: 13
def test_mem_dot(self):
# Ticket #106
x = np.random.randn(0, 1)
y = np.random.randn(10, 1)
# Dummy array to detect bad memory access:
_z = np.ones(10)
_dummy = np.empty((0, 10))
z = np.lib.stride_tricks.as_strided(_z, _dummy.shape, _dummy.strides)
Reported by Pylint.
Line: 202
Column: 13
def test_mem_dot(self):
# Ticket #106
x = np.random.randn(0, 1)
y = np.random.randn(10, 1)
# Dummy array to detect bad memory access:
_z = np.ones(10)
_dummy = np.empty((0, 10))
z = np.lib.stride_tricks.as_strided(_z, _dummy.shape, _dummy.strides)
np.dot(x, np.transpose(y), out=z)
Reported by Pylint.
Line: 259
Column: 13
def test_argmax(self):
# Ticket #119
a = np.random.normal(0, 1, (4, 5, 6, 7, 8))
for i in range(a.ndim):
a.argmax(i) # Should succeed
def test_mem_divmod(self):
# Ticket #126
Reported by Pylint.
Line: 311
Column: 22
def test_tobytes_FORTRANORDER_discontiguous(self):
# Fix in r2836
# Create non-contiguous Fortran ordered array
x = np.array(np.random.rand(3, 3), order='F')[:, :2]
assert_array_almost_equal(x.ravel(), np.frombuffer(x.tobytes()))
def test_flat_assignment(self):
# Correct behaviour of ticket #194
x = np.empty((3, 1))
Reported by Pylint.
Line: 536
Column: 19
funcs2 = ['compress', 'take', 'repeat']
for func in funcs1:
arr = np.random.rand(8, 7)
arr2 = arr.copy()
if isinstance(func, tuple):
func_meth = func[1]
func = func[0]
else:
Reported by Pylint.
Line: 554
Column: 20
assert_(abs(res1-res2).max() < 1e-8, func)
for func in funcs2:
arr1 = np.random.rand(8, 7)
arr2 = np.random.rand(8, 7)
res1 = None
if func == 'compress':
arr1 = arr1.ravel()
res1 = getattr(arr2, func)(arr1)
Reported by Pylint.
Line: 555
Column: 20
for func in funcs2:
arr1 = np.random.rand(8, 7)
arr2 = np.random.rand(8, 7)
res1 = None
if func == 'compress':
arr1 = arr1.ravel()
res1 = getattr(arr2, func)(arr1)
else:
Reported by Pylint.
Line: 663
Column: 25
# Cannot test if NPY_RELAXED_STRIDES_CHECKING changes the strides.
# With NPY_RELAXED_STRIDES_CHECKING the test becomes superfluous.
@pytest.mark.skipif(np.ones(1).strides[0] == np.iinfo(np.intp).max,
reason="Using relaxed stride checking")
def test_reshape_trailing_ones_strides(self):
# GitHub issue gh-2949, bad strides for trailing ones of new shape
a = np.zeros(12, dtype=np.int32)[::2] # not contiguous
strides_c = (16, 8, 8, 8)
Reported by Pylint.
Line: 704
Column: 9
# Ticket #374
a = np.arange(5).reshape((5, 1))
b = a.copy()
np.random.shuffle(b)
assert_equal(np.sort(b, axis=0), a)
def test_refcount_vdot(self):
# Changeset #3443
_assert_valid_refcount(np.vdot)
Reported by Pylint.
numpy/f2py/crackfortran.py
868 issues
Line: 150
Column: 1
import copy
import platform
from . import __version__
# The environment provided by auxfuncs.py is needed for some calls to eval.
# As the needed functions cannot be determined by static inspection of the
# code, it is safest to use import * pending a major refactoring of f2py.
from .auxfuncs import *
Reported by Pylint.
Line: 155
Column: 1
# The environment provided by auxfuncs.py is needed for some calls to eval.
# As the needed functions cannot be determined by static inspection of the
# code, it is safest to use import * pending a major refactoring of f2py.
from .auxfuncs import *
f2py_version = __version__.version
# Global flags:
Reported by Pylint.
Line: 266
Column: 9
def rmbadname1(name):
if name in badnames:
errmess('rmbadname1: Replacing "%s" with "%s".\n' %
(name, badnames[name]))
return badnames[name]
return name
Reported by Pylint.
Line: 278
Column: 9
def undo_rmbadname1(name):
if name in invbadnames:
errmess('undo_rmbadname1: Replacing "%s" with "%s".\n'
% (name, invbadnames[name]))
return invbadnames[name]
return name
Reported by Pylint.
Line: 329
Column: 39
# Read fortran (77,90) code
def readfortrancode(ffile, dowithline=show, istop=1):
"""
Read fortran codes from files and
1) Get rid of comments, line continuations, and empty lines; lower cases.
2) Call dowithline(line) on every line.
3) Recursively call itself when statement \"include '<filename>'\" is met.
Reported by Pylint.
Line: 468
Column: 25
while True:
lc = fin.readline()
if not lc:
errmess(
'Unexpected end of file when reading multiline\n')
break
l = l + lc
if mline_mark.match(lc):
break
Reported by Pylint.
Line: 879
Column: 13
elif k == 'note':
pass
elif k in ['intent', 'check', 'dimension', 'optional', 'required']:
errmess('appenddecl: "%s" not implemented.\n' % k)
else:
raise Exception('appenddecl: Unknown variable definition key:' +
str(k))
return decl
Reported by Pylint.
Line: 1172
Column: 29
' to %s arguments\n' % (k, groupcache[groupcounter]['name']))
groupcache[groupcounter]['args'].append(k)
else:
errmess(
'analyzeline: intent(callback) %s is ignored' % (k))
else:
errmess('analyzeline: intent(callback) %s is already'
' in argument list' % (k))
if case in ['optional', 'required', 'public', 'external', 'private', 'intrinsic']:
Reported by Pylint.
Line: 1175
Column: 25
errmess(
'analyzeline: intent(callback) %s is ignored' % (k))
else:
errmess('analyzeline: intent(callback) %s is already'
' in argument list' % (k))
if case in ['optional', 'required', 'public', 'external', 'private', 'intrinsic']:
ap = case
if 'attrspec' in edecl[k]:
edecl[k]['attrspec'].append(ap)
Reported by Pylint.
Line: 1228
Column: 17
try:
v = eval(initexpr, {}, params)
except (SyntaxError, NameError, TypeError) as msg:
errmess('analyzeline: Failed to evaluate %r. Ignoring: %s\n'
% (initexpr, msg))
continue
edecl[k]['='] = repr(v)
if 'attrspec' in edecl[k]:
edecl[k]['attrspec'].append('parameter')
Reported by Pylint.
numpy/linalg/tests/test_linalg.py
866 issues
Line: 11
Column: 1
import traceback
import textwrap
import subprocess
import pytest
import numpy as np
from numpy import array, single, double, csingle, cdouble, dot, identity, matmul
from numpy.core import swapaxes
from numpy import multiply, atleast_2d, inf, asarray
Reported by Pylint.
Line: 38
Column: 1
old_assert_almost_equal = assert_almost_equal
def assert_almost_equal(a, b, single_decimal=6, double_decimal=12, **kw):
if asarray(a).dtype.type in (single, csingle):
decimal = single_decimal
else:
decimal = double_decimal
old_assert_almost_equal(a, b, decimal=decimal, **kw)
Reported by Pylint.
Line: 108
Column: 1
# Base test cases
#
np.random.seed(1234)
CASES = []
# square test cases
CASES += apply_tag('square', [
Reported by Pylint.
Line: 137
Column: 16
np.empty((0,), dtype=double),
tags={'size-0'}),
LinalgCase("8x8",
np.random.rand(8, 8),
np.random.rand(8)),
LinalgCase("1x1",
np.random.rand(1, 1),
np.random.rand(1)),
LinalgCase("nonarray",
Reported by Pylint.
Line: 138
Column: 16
tags={'size-0'}),
LinalgCase("8x8",
np.random.rand(8, 8),
np.random.rand(8)),
LinalgCase("1x1",
np.random.rand(1, 1),
np.random.rand(1)),
LinalgCase("nonarray",
[[1, 2], [3, 4]],
Reported by Pylint.
Line: 140
Column: 16
np.random.rand(8, 8),
np.random.rand(8)),
LinalgCase("1x1",
np.random.rand(1, 1),
np.random.rand(1)),
LinalgCase("nonarray",
[[1, 2], [3, 4]],
[2, 1]),
])
Reported by Pylint.
Line: 141
Column: 16
np.random.rand(8)),
LinalgCase("1x1",
np.random.rand(1, 1),
np.random.rand(1)),
LinalgCase("nonarray",
[[1, 2], [3, 4]],
[2, 1]),
])
Reported by Pylint.
Line: 186
Column: 16
[[1. + 1j, 2. + 2j], [3. - 3j, 4. - 9j], [5. - 4j, 6. + 8j]], dtype=cdouble),
array([[2. + 1j, 1. + 2j], [1 - 1j, 2 - 2j], [1 - 1j, 2 - 2j]], dtype=cdouble)),
LinalgCase("8x11",
np.random.rand(8, 11),
np.random.rand(8)),
LinalgCase("1x5",
np.random.rand(1, 5),
np.random.rand(1)),
LinalgCase("5x1",
Reported by Pylint.
Line: 187
Column: 16
array([[2. + 1j, 1. + 2j], [1 - 1j, 2 - 2j], [1 - 1j, 2 - 2j]], dtype=cdouble)),
LinalgCase("8x11",
np.random.rand(8, 11),
np.random.rand(8)),
LinalgCase("1x5",
np.random.rand(1, 5),
np.random.rand(1)),
LinalgCase("5x1",
np.random.rand(5, 1),
Reported by Pylint.
Line: 189
Column: 16
np.random.rand(8, 11),
np.random.rand(8)),
LinalgCase("1x5",
np.random.rand(1, 5),
np.random.rand(1)),
LinalgCase("5x1",
np.random.rand(5, 1),
np.random.rand(5)),
LinalgCase("0x4",
Reported by Pylint.
numpy/ma/tests/test_old_ma.py
838 issues
Line: 408
Column: 25
x = array([1., 2., 3., 4., 5.])
c = array([1, 1, 1, 0, 0])
x[2] = masked
z = where(c, x, -x)
assert_(eq(z, [1., 2., 0., -4., -5]))
c[0] = masked
z = where(c, x, -x)
assert_(eq(z, [1., 2., 0., -4., -5]))
assert_(z[0] is masked)
Reported by Pylint.
Line: 411
Column: 25
z = where(c, x, -x)
assert_(eq(z, [1., 2., 0., -4., -5]))
c[0] = masked
z = where(c, x, -x)
assert_(eq(z, [1., 2., 0., -4., -5]))
assert_(z[0] is masked)
assert_(z[1] is not masked)
assert_(z[2] is masked)
assert_(eq(masked_where(greater(x, 2), x), masked_greater(x, 2)))
Reported by Pylint.
Line: 426
Column: 20
assert_(eq(masked_where(not_equal(x, 2), x), masked_not_equal(x, 2)))
assert_(eq(masked_inside(list(range(5)), 1, 3), [0, 199, 199, 199, 4]))
assert_(eq(masked_outside(list(range(5)), 1, 3), [199, 1, 2, 3, 199]))
assert_(eq(masked_inside(array(list(range(5)),
mask=[1, 0, 0, 0, 0]), 1, 3).mask,
[1, 1, 1, 1, 0]))
assert_(eq(masked_outside(array(list(range(5)),
mask=[0, 1, 0, 0, 0]), 1, 3).mask,
[1, 1, 0, 0, 1]))
Reported by Pylint.
Line: 429
Column: 20
assert_(eq(masked_inside(array(list(range(5)),
mask=[1, 0, 0, 0, 0]), 1, 3).mask,
[1, 1, 1, 1, 0]))
assert_(eq(masked_outside(array(list(range(5)),
mask=[0, 1, 0, 0, 0]), 1, 3).mask,
[1, 1, 0, 0, 1]))
assert_(eq(masked_equal(array(list(range(5)),
mask=[1, 0, 0, 0, 0]), 2).mask,
[1, 0, 1, 0, 0]))
Reported by Pylint.
Line: 432
Column: 20
assert_(eq(masked_outside(array(list(range(5)),
mask=[0, 1, 0, 0, 0]), 1, 3).mask,
[1, 1, 0, 0, 1]))
assert_(eq(masked_equal(array(list(range(5)),
mask=[1, 0, 0, 0, 0]), 2).mask,
[1, 0, 1, 0, 0]))
assert_(eq(masked_not_equal(array([2, 2, 1, 2, 1],
mask=[1, 0, 0, 0, 0]), 2).mask,
[1, 0, 1, 0, 1]))
Reported by Pylint.
Line: 435
Column: 20
assert_(eq(masked_equal(array(list(range(5)),
mask=[1, 0, 0, 0, 0]), 2).mask,
[1, 0, 1, 0, 0]))
assert_(eq(masked_not_equal(array([2, 2, 1, 2, 1],
mask=[1, 0, 0, 0, 0]), 2).mask,
[1, 0, 1, 0, 1]))
assert_(eq(masked_where([1, 1, 0, 0, 0], [1, 2, 3, 4, 5]),
[99, 99, 3, 4, 5]))
atest = ones((10, 10, 10), dtype=np.float32)
Reported by Pylint.
Line: 444
Column: 24
btest = zeros(atest.shape, MaskType)
ctest = masked_where(btest, atest)
assert_(eq(atest, ctest))
z = choose(c, (-x, x))
assert_(eq(z, [1., 2., 0., -4., -5]))
assert_(z[0] is masked)
assert_(z[1] is not masked)
assert_(z[2] is masked)
x = arange(6)
Reported by Pylint.
Line: 658
Column: 18
with np.errstate(divide='ignore'):
assert_((1 / array(0)).mask)
assert_((1 + xm).mask)
assert_((-xm).mask)
assert_((-xm).mask)
assert_(maximum(xm, xm).mask)
assert_(minimum(xm, xm).mask)
assert_(xm.filled().dtype is xm._data.dtype)
x = array(0, mask=0)
Reported by Pylint.
Line: 659
Column: 18
assert_((1 / array(0)).mask)
assert_((1 + xm).mask)
assert_((-xm).mask)
assert_((-xm).mask)
assert_(maximum(xm, xm).mask)
assert_(minimum(xm, xm).mask)
assert_(xm.filled().dtype is xm._data.dtype)
x = array(0, mask=0)
assert_(x.filled() == x._data)
Reported by Pylint.
Line: 752
Column: 21
def test_reduce(self):
a = self.d[0]
assert_(not alltrue(a, axis=0))
assert_(sometrue(a, axis=0))
assert_equal(sum(a[:3], axis=0), 0)
assert_equal(product(a, axis=0), 0)
def test_minmax(self):
Reported by Pylint.