The following issues were found

numpy/core/tests/test_simd.py
189 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              # NOTE: Please avoid the use of numpy.testing since NPYV intrinsics
# may be involved in their functionality.
import pytest, math, re
import itertools
from numpy.core._simd import targets
from numpy.core._multiarray_umath import __cpu_baseline__

class _Test_Utility:
    # submodule of the desired SIMD extension, e.g. targets["AVX512F"]

            

Reported by Pylint.

Unable to import 'numpy.core._simd'
Error

Line: 5 Column: 1

              # may be involved in their functionality.
import pytest, math, re
import itertools
from numpy.core._simd import targets
from numpy.core._multiarray_umath import __cpu_baseline__

class _Test_Utility:
    # submodule of the desired SIMD extension, e.g. targets["AVX512F"]
    npyv = None

            

Reported by Pylint.

Unable to import 'numpy.core._multiarray_umath'
Error

Line: 6 Column: 1

              import pytest, math, re
import itertools
from numpy.core._simd import targets
from numpy.core._multiarray_umath import __cpu_baseline__

class _Test_Utility:
    # submodule of the desired SIMD extension, e.g. targets["AVX512F"]
    npyv = None
    # the current data type suffix e.g. 's8'

            

Reported by Pylint.

Value 'self.sfx' is unsubscriptable
Error

Line: 39 Column: 16

                      return list(rng)

    def _is_unsigned(self):
        return self.sfx[0] == 'u'

    def _is_signed(self):
        return self.sfx[0] == 's'

    def _is_fp(self):

            

Reported by Pylint.

Value 'self.sfx' is unsubscriptable
Error

Line: 42 Column: 16

                      return self.sfx[0] == 'u'

    def _is_signed(self):
        return self.sfx[0] == 's'

    def _is_fp(self):
        return self.sfx[0] == 'f'

    def _scalar_size(self):

            

Reported by Pylint.

Value 'self.sfx' is unsubscriptable
Error

Line: 45 Column: 16

                      return self.sfx[0] == 's'

    def _is_fp(self):
        return self.sfx[0] == 'f'

    def _scalar_size(self):
        return int(self.sfx[1:])

    def _int_clip(self, seq):

            

Reported by Pylint.

Value 'self.sfx' is unsubscriptable
Error

Line: 48 Column: 20

                      return self.sfx[0] == 'f'

    def _scalar_size(self):
        return int(self.sfx[1:])

    def _int_clip(self, seq):
        if self._is_fp():
            return seq
        max_int = self._int_max()

            

Reported by Pylint.

Value 'self.sfx' is unsubscriptable
Error

Line: 73 Column: 53

                      return -(self._int_max() + 1)

    def _true_mask(self):
        max_unsig = getattr(self.npyv, "setall_u" + self.sfx[1:])(-1)
        return max_unsig[0]

    def _to_unsigned(self, vector):
        if isinstance(vector, (list, tuple)):
            return getattr(self.npyv, "load_u" + self.sfx[1:])(vector)

            

Reported by Pylint.

Value 'self.sfx' is unsubscriptable
Error

Line: 78 Column: 50

              
    def _to_unsigned(self, vector):
        if isinstance(vector, (list, tuple)):
            return getattr(self.npyv, "load_u" + self.sfx[1:])(vector)
        else:
            sfx = vector.__name__.replace("npyv_", "")
            if sfx[0] == "b":
                cvt_intrin = "cvt_u{0}_b{0}"
            else:

            

Reported by Pylint.

Value 'self.sfx' is unsubscriptable
Error

Line: 112 Column: 50

                  To test all boolean vector types at once
    """
    def _data(self, start=None, count=None, reverse=False):
        nlanes = getattr(self.npyv, "nlanes_u" + self.sfx[1:])
        true_mask = self._true_mask()
        rng = range(nlanes)
        if reverse:
            rng = reversed(rng)
        return [true_mask if x % 2 else 0 for x in rng]

            

Reported by Pylint.

numpy/polynomial/tests/test_chebyshev.py
189 issues
Module 'numpy.random' has no 'random' member
Error

Line: 131 Column: 9

                  c3d = np.einsum('i,j,k->ijk', c1d, c1d, c1d)

    # some random values in [-1, 1)
    x = np.random.random((3, 5))*2 - 1
    y = polyval(x, [1., 2., 3.])

    def test_chebval(self):
        #check empty input
        assert_equal(cheb.chebval([], [1]).size, 0)

            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 305 Column: 15

              
    def test_chebint_axis(self):
        # check that axis keyword works
        c2d = np.random.random((3, 4))

        tgt = np.vstack([cheb.chebint(c) for c in c2d.T]).T
        res = cheb.chebint(c2d, axis=0)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 349 Column: 15

              
    def test_chebder_axis(self):
        # check that axis keyword works
        c2d = np.random.random((3, 4))

        tgt = np.vstack([cheb.chebder(c) for c in c2d.T]).T
        res = cheb.chebder(c2d, axis=0)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 362 Column: 9

              
class TestVander:
    # some random values in [-1, 1)
    x = np.random.random((3, 5))*2 - 1

    def test_chebvander(self):
        # check for 1d x
        x = np.arange(3)
        v = cheb.chebvander(x, 3)

            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 384 Column: 13

                  def test_chebvander2d(self):
        # also tests chebval2d for non-square coefficient array
        x1, x2, x3 = self.x
        c = np.random.random((2, 3))
        van = cheb.chebvander2d(x1, x2, [1, 2])
        tgt = cheb.chebval2d(x1, x2, c)
        res = np.dot(van, c.flat)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 397 Column: 13

                  def test_chebvander3d(self):
        # also tests chebval3d for non-square coefficient array
        x1, x2, x3 = self.x
        c = np.random.random((2, 3, 4))
        van = cheb.chebvander3d(x1, x2, x3, [1, 2, 3])
        tgt = cheb.chebval3d(x1, x2, x3, c)
        res = np.dot(van, c.flat)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Access to a protected member _cseries_to_zseries of a client class
Error

Line: 37 Column: 19

                      for i in range(5):
            inp = np.array([2] + [1]*i, np.double)
            tgt = np.array([.5]*i + [2] + [.5]*i, np.double)
            res = cheb._cseries_to_zseries(inp)
            assert_equal(res, tgt)

    def test__zseries_to_cseries(self):
        for i in range(5):
            inp = np.array([.5]*i + [2] + [.5]*i, np.double)

            

Reported by Pylint.

Access to a protected member _zseries_to_cseries of a client class
Error

Line: 44 Column: 19

                      for i in range(5):
            inp = np.array([.5]*i + [2] + [.5]*i, np.double)
            tgt = np.array([2] + [1]*i, np.double)
            res = cheb._zseries_to_cseries(inp)
            assert_equal(res, tgt)


class TestConstants:


            

Reported by Pylint.

Unused variable 'x3'
Error

Line: 156 Column: 17

                          assert_equal(cheb.chebval(x, [1, 0, 0]).shape, dims)

    def test_chebval2d(self):
        x1, x2, x3 = self.x
        y1, y2, y3 = self.y

        #test exceptions
        assert_raises(ValueError, cheb.chebval2d, x1, x2[:2], self.c2d)


            

Reported by Pylint.

Unused variable 'y3'
Error

Line: 157 Column: 17

              
    def test_chebval2d(self):
        x1, x2, x3 = self.x
        y1, y2, y3 = self.y

        #test exceptions
        assert_raises(ValueError, cheb.chebval2d, x1, x2[:2], self.c2d)

        #test values

            

Reported by Pylint.

numpy/lib/tests/test_index_tricks.py
189 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

import numpy as np
from numpy.testing import (
    assert_, assert_equal, assert_array_equal, assert_almost_equal,
    assert_array_almost_equal, assert_raises, assert_raises_regex,
    assert_warns
    )
from numpy.lib.index_tricks import (

            

Reported by Pylint.

Unexpected keyword argument 'hape' in function call
Error

Line: 27 Column: 13

                      # test that an invalid second keyword argument
        # is properly handled, including the old name `dims`.
        with assert_raises(TypeError):
            np.unravel_index(indices=2, hape=(2, 2))

        with assert_raises(TypeError):
            np.unravel_index(2, hape=(2, 2))

        with assert_raises(TypeError):

            

Reported by Pylint.

No value for argument 'shape' in function call
Error

Line: 27 Column: 13

                      # test that an invalid second keyword argument
        # is properly handled, including the old name `dims`.
        with assert_raises(TypeError):
            np.unravel_index(indices=2, hape=(2, 2))

        with assert_raises(TypeError):
            np.unravel_index(2, hape=(2, 2))

        with assert_raises(TypeError):

            

Reported by Pylint.

No value for argument 'shape' in function call
Error

Line: 30 Column: 13

                          np.unravel_index(indices=2, hape=(2, 2))

        with assert_raises(TypeError):
            np.unravel_index(2, hape=(2, 2))

        with assert_raises(TypeError):
            np.unravel_index(254, ims=(17, 94))

        with assert_raises(TypeError):

            

Reported by Pylint.

Unexpected keyword argument 'hape' in function call
Error

Line: 30 Column: 13

                          np.unravel_index(indices=2, hape=(2, 2))

        with assert_raises(TypeError):
            np.unravel_index(2, hape=(2, 2))

        with assert_raises(TypeError):
            np.unravel_index(254, ims=(17, 94))

        with assert_raises(TypeError):

            

Reported by Pylint.

Unexpected keyword argument 'ims' in function call
Error

Line: 33 Column: 13

                          np.unravel_index(2, hape=(2, 2))

        with assert_raises(TypeError):
            np.unravel_index(254, ims=(17, 94))

        with assert_raises(TypeError):
            np.unravel_index(254, dims=(17, 94))

        assert_equal(np.ravel_multi_index((1, 0), (2, 2)), 2)

            

Reported by Pylint.

No value for argument 'shape' in function call
Error

Line: 33 Column: 13

                          np.unravel_index(2, hape=(2, 2))

        with assert_raises(TypeError):
            np.unravel_index(254, ims=(17, 94))

        with assert_raises(TypeError):
            np.unravel_index(254, dims=(17, 94))

        assert_equal(np.ravel_multi_index((1, 0), (2, 2)), 2)

            

Reported by Pylint.

No value for argument 'shape' in function call
Error

Line: 36 Column: 13

                          np.unravel_index(254, ims=(17, 94))

        with assert_raises(TypeError):
            np.unravel_index(254, dims=(17, 94))

        assert_equal(np.ravel_multi_index((1, 0), (2, 2)), 2)
        assert_equal(np.unravel_index(254, (17, 94)), (2, 66))
        assert_equal(np.ravel_multi_index((2, 66), (17, 94)), 254)
        assert_raises(ValueError, np.unravel_index, -1, (2, 2))

            

Reported by Pylint.

Unexpected keyword argument 'dims' in function call
Error

Line: 36 Column: 13

                          np.unravel_index(254, ims=(17, 94))

        with assert_raises(TypeError):
            np.unravel_index(254, dims=(17, 94))

        assert_equal(np.ravel_multi_index((1, 0), (2, 2)), 2)
        assert_equal(np.unravel_index(254, (17, 94)), (2, 66))
        assert_equal(np.ravel_multi_index((2, 66), (17, 94)), 254)
        assert_raises(ValueError, np.unravel_index, -1, (2, 2))

            

Reported by Pylint.

Module 'numpy.random' has no 'rand' member
Error

Line: 294 Column: 13

                      assert_(g.shape == (100,))

    def test_2d(self):
        b = np.random.rand(5, 5)
        c = np.random.rand(5, 5)
        d = r_['1', b, c]  # append columns
        assert_(d.shape == (5, 10))
        assert_array_equal(d[:, :5], b)
        assert_array_equal(d[:, 5:], c)

            

Reported by Pylint.

numpy/core/tests/test_records.py
187 issues
Unable to import 'pytest'
Error

Line: 6 Column: 1

              from io import BytesIO
from os import path
from pathlib import Path
import pytest

import numpy as np
from numpy.testing import (
    assert_, assert_equal, assert_array_equal, assert_array_almost_equal,
    assert_raises, temppath,

            

Reported by Pylint.

Instance of 'ndarray' has no 'foo' member
Error

Line: 278 Column: 22

                      a = np.array([('abc ', 1), ('abc', 2)],
                     dtype=[('foo', 'S4'), ('bar', int)])
        a = a.view(np.recarray)
        assert_equal(a.foo[0] == a.foo[1], False)

    def test_recarray_returntypes(self):
        qux_fields = {'C': (np.dtype('S5'), 0), 'D': (np.dtype('S5'), 6)}
        a = np.rec.array([('abc ', (1,1), 1, ('abcde', 'fgehi')),
                          ('abc', (2,3), 1, ('abcde', 'jklmn'))],

            

Reported by Pylint.

Instance of 'ndarray' has no 'foo' member
Error

Line: 278 Column: 34

                      a = np.array([('abc ', 1), ('abc', 2)],
                     dtype=[('foo', 'S4'), ('bar', int)])
        a = a.view(np.recarray)
        assert_equal(a.foo[0] == a.foo[1], False)

    def test_recarray_returntypes(self):
        qux_fields = {'C': (np.dtype('S5'), 0), 'D': (np.dtype('S5'), 6)}
        a = np.rec.array([('abc ', (1,1), 1, ('abcde', 'fgehi')),
                          ('abc', (2,3), 1, ('abcde', 'jklmn'))],

            

Reported by Pylint.

Module 'numpy.random' has no 'seed' member
Error

Line: 328 Column: 13

                  def test_tofile_fromfile(self):
        with temppath(suffix='.bin') as path:
            path = Path(path)
            np.random.seed(123)
            a = np.random.rand(10).astype('f8,i4,a5')
            a[5] = (0.5,10,'abcde')
            with path.open("wb") as fd:
                a.tofile(fd)
            x = np.core.records.fromfile(path,

            

Reported by Pylint.

Module 'numpy.random' has no 'rand' member
Error

Line: 329 Column: 17

                      with temppath(suffix='.bin') as path:
            path = Path(path)
            np.random.seed(123)
            a = np.random.rand(10).astype('f8,i4,a5')
            a[5] = (0.5,10,'abcde')
            with path.open("wb") as fd:
                a.tofile(fd)
            x = np.core.records.fromfile(path,
                                         formats='f8,i4,a5',

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 102 Column: 13

              
        mine = np.rec.fromarrays([a, b, c], names='date,data1,data2')
        for i in range(len(a)):
            assert_((mine.date[i] == list(range(1, 10))))
            assert_((mine.data1[i] == 0.0))
            assert_((mine.data2[i] == 0.0))

    def test_recarray_repr(self):
        a = np.array([(1, 0.1), (2, 0.2)],

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 103 Column: 13

                      mine = np.rec.fromarrays([a, b, c], names='date,data1,data2')
        for i in range(len(a)):
            assert_((mine.date[i] == list(range(1, 10))))
            assert_((mine.data1[i] == 0.0))
            assert_((mine.data2[i] == 0.0))

    def test_recarray_repr(self):
        a = np.array([(1, 0.1), (2, 0.2)],
                     dtype=[('foo', '<i4'), ('bar', '<f8')])

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 104 Column: 13

                      for i in range(len(a)):
            assert_((mine.date[i] == list(range(1, 10))))
            assert_((mine.data1[i] == 0.0))
            assert_((mine.data2[i] == 0.0))

    def test_recarray_repr(self):
        a = np.array([(1, 0.1), (2, 0.2)],
                     dtype=[('foo', '<i4'), ('bar', '<f8')])
        a = np.rec.array(a)

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 119 Column: 9

              
        # make sure non-structured dtypes also show up as rec.array
        a = np.array(np.ones(4, dtype='f8'))
        assert_(repr(np.rec.array(a)).startswith('rec.array'))

        # check that the 'np.record' part of the dtype isn't shown
        a = np.rec.array(np.ones(3, dtype='i4,i4'))
        assert_equal(repr(a).find('numpy.record'), -1)
        a = np.rec.array(np.ones(3, dtype='i4'))

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 125 Column: 9

                      a = np.rec.array(np.ones(3, dtype='i4,i4'))
        assert_equal(repr(a).find('numpy.record'), -1)
        a = np.rec.array(np.ones(3, dtype='i4'))
        assert_(repr(a).find('dtype=int32') != -1)

    def test_0d_recarray_repr(self):
        arr_0d = np.rec.array((1, 2.0, '2003'), dtype='<i4,<f8,<M8[Y]')
        assert_equal(repr(arr_0d), textwrap.dedent("""\
            rec.array((1, 2., '2003'),

            

Reported by Pylint.

numpy/f2py/auxfuncs.py
186 issues
Attempted relative import beyond top-level package
Error

Line: 22 Column: 1

              import types
from functools import reduce

from . import __version__
from . import cfuncs

__all__ = [
    'applyrules', 'debugcapi', 'dictappend', 'errmess', 'gentitle',
    'getargs2', 'getcallprotoargument', 'getcallstatement',

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 23 Column: 1

              from functools import reduce

from . import __version__
from . import cfuncs

__all__ = [
    'applyrules', 'debugcapi', 'dictappend', 'errmess', 'gentitle',
    'getargs2', 'getcallprotoargument', 'getcallstatement',
    'getfortranname', 'getpymethoddef', 'getrestdoc', 'getusercode',

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 651 Column: 5

                      outmess(
            'warning: callstatement is defined without callprotoargument\n')
        return
    from .capi_maps import getctype
    arg_types, arg_types2 = [], []
    if l_and(isstringfunction, l_not(isfunction_wrap))(rout):
        arg_types.extend(['char*', 'size_t'])
    for n in rout['args']:
        var = rout['vars'][n]

            

Reported by Pylint.

No value for argument 'new' in unbound method call
Error

Line: 765 Column: 19

                      if isinstance(d[k], list):
            str = str.replace('#%s#' % (k), sep.join(flatlist(d[k])))
        else:
            str = str.replace('#%s#' % (k), d[k])
    return str


def dictappend(rd, ar):
    if isinstance(ar, list):

            

Reported by Pylint.

Unused argument 'var'
Error

Line: 67 Column: 15

                      sys.stdout.write(t)


def debugcapi(var):
    return 'capi' in debugoptions


def _isstring(var):
    return 'typespec' in var and var['typespec'] == 'character' and \

            

Reported by Pylint.

Unused argument 'var'
Error

Line: 546 Column: 12

                  return getcallstatement(rout) is not None


def istrue(var):
    return 1


def isfalse(var):
    return 0

            

Reported by Pylint.

Unused argument 'var'
Error

Line: 550 Column: 13

                  return 1


def isfalse(var):
    return 0


class F2PYError(Exception):
    pass

            

Reported by Pylint.

Use of possibly insecure function - consider using safer ast.literal_eval.
Security blacklist

Line: 573
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval

                  for i in range(len(f)):
        l = '%s,f%d=f[%d]' % (l, i, i)
        l2.append('f%d(v)' % (i))
    return eval('%s:%s' % (l, ' and '.join(l2)))


def l_or(*f):
    l, l2 = 'lambda v', []
    for i in range(len(f)):

            

Reported by Bandit.

Use of eval
Error

Line: 573 Column: 12

                  for i in range(len(f)):
        l = '%s,f%d=f[%d]' % (l, i, i)
        l2.append('f%d(v)' % (i))
    return eval('%s:%s' % (l, ' and '.join(l2)))


def l_or(*f):
    l, l2 = 'lambda v', []
    for i in range(len(f)):

            

Reported by Pylint.

Use of possibly insecure function - consider using safer ast.literal_eval.
Security blacklist

Line: 581
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval

                  for i in range(len(f)):
        l = '%s,f%d=f[%d]' % (l, i, i)
        l2.append('f%d(v)' % (i))
    return eval('%s:%s' % (l, ' or '.join(l2)))


def l_not(f):
    return eval('lambda v,f=f:not f(v)')


            

Reported by Bandit.

numpy/distutils/cpuinfo.py
182 issues
Unable to import 'winreg'
Error

Line: 486 Column: 13

                      info = []
        try:
            #XXX: Bad style to use so long `try:...except:...`. Fix it!
            import winreg

            prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)"
                              r"\s+stepping\s+(?P<STP>\d+)", re.IGNORECASE)
            chnd=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, self.pkey)
            pnum=0

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 72 Column: 16

                  def _try_call(self, func):
        try:
            return func()
        except Exception:
            pass

    def __getattr__(self, name):
        if not name.startswith('_'):
            if hasattr(self, '_'+name):

            

Reported by Pylint.

XXX
Error

Line: 187 Column: 2

              
    # Intel

    #XXX
    _is_i386 = _not_impl

    def _is_Intel(self):
        return self.info[0]['vendor_id']=='GenuineIntel'


            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 332 Column: 16

              
    def get_ip(self):
        try: return self.info.get('MACHINE')
        except Exception: pass
    def __machine(self, n):
        return self.info.get('MACHINE').lower() == 'ip%s' % (n)
    def _is_IP19(self): return self.__machine(19)
    def _is_IP20(self): return self.__machine(20)
    def _is_IP21(self): return self.__machine(21)

            

Reported by Pylint.

XXX: what does the value of
Error

Line: 476 Column: 3

              
    info = None
    pkey = r"HARDWARE\DESCRIPTION\System\CentralProcessor"
    # XXX: what does the value of
    #   HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0
    # mean?

    def __init__(self):
        if self.info is not None:

            

Reported by Pylint.

XXX: Bad style to use so long `try:...except:...`. Fix it!
Error

Line: 485 Column: 2

                          return
        info = []
        try:
            #XXX: Bad style to use so long `try:...except:...`. Fix it!
            import winreg

            prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)"
                              r"\s+stepping\s+(?P<STP>\d+)", re.IGNORECASE)
            chnd=winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, self.pkey)

            

Reported by Pylint.

Unused variable 'vtpe'
Error

Line: 504 Column: 42

                                  pidx=0
                    while True:
                        try:
                            name, value, vtpe=winreg.EnumValue(phnd, pidx)
                        except winreg.error:
                            break
                        else:
                            pidx=pidx+1
                            info[-1][name]=value

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 516 Column: 16

                                                  info[-1]["Family"]=int(srch.group("FML"))
                                    info[-1]["Model"]=int(srch.group("MDL"))
                                    info[-1]["Stepping"]=int(srch.group("STP"))
        except Exception as e:
            print(e, '(ignoring)')
        self.__class__.info = info

    def _not_impl(self): pass


            

Reported by Pylint.

XXX: other OS's. Eg. use _winreg on Win32. Or os.uname on unices.
Error

Line: 662 Column: 2

                  cpuinfo = Win32CPUInfo
elif sys.platform.startswith('cygwin'):
    cpuinfo = LinuxCPUInfo
#XXX: other OS's. Eg. use _winreg on Win32. Or os.uname on unices.
else:
    cpuinfo = CPUInfoBase

cpu = cpuinfo()


            

Reported by Pylint.

Consider possible security implications associated with getstatusoutput module.
Security blacklist

Line: 24
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess

              import types
import warnings

from subprocess import getstatusoutput


def getoutput(cmd, successful_status=(0,), stacklevel=1):
    try:
        status, output = getstatusoutput(cmd)

            

Reported by Bandit.

numpy/core/tests/test_unicode.py
175 issues
Instance of 'CreateZeros' has no 'ulen' member
Error

Line: 51 Column: 42

                  def content_check(self, ua, ua_scalar, nbytes):

        # Check the length of the unicode base type
        assert_(int(ua.dtype.str[2:]) == self.ulen)
        # Check the length of the data buffer
        assert_(buffer_length(ua) == nbytes)
        # Small check that data in array element is ok
        assert_(ua_scalar == u'')
        # Encode to ascii and double check

            

Reported by Pylint.

Instance of 'CreateZeros' has no 'ulen' member
Error

Line: 63 Column: 41

              
    def test_zeros0D(self):
        # Check creation of 0-dimensional objects
        ua = np.zeros((), dtype='U%s' % self.ulen)
        self.content_check(ua, ua[()], 4*self.ulen)

    def test_zerosSD(self):
        # Check creation of single-dimensional objects
        ua = np.zeros((2,), dtype='U%s' % self.ulen)

            

Reported by Pylint.

Instance of 'CreateZeros' has no 'ulen' member
Error

Line: 64 Column: 42

                  def test_zeros0D(self):
        # Check creation of 0-dimensional objects
        ua = np.zeros((), dtype='U%s' % self.ulen)
        self.content_check(ua, ua[()], 4*self.ulen)

    def test_zerosSD(self):
        # Check creation of single-dimensional objects
        ua = np.zeros((2,), dtype='U%s' % self.ulen)
        self.content_check(ua, ua[0], 4*self.ulen*2)

            

Reported by Pylint.

Instance of 'CreateZeros' has no 'ulen' member
Error

Line: 68 Column: 43

              
    def test_zerosSD(self):
        # Check creation of single-dimensional objects
        ua = np.zeros((2,), dtype='U%s' % self.ulen)
        self.content_check(ua, ua[0], 4*self.ulen*2)
        self.content_check(ua, ua[1], 4*self.ulen*2)

    def test_zerosMD(self):
        # Check creation of multi-dimensional objects

            

Reported by Pylint.

Instance of 'CreateZeros' has no 'ulen' member
Error

Line: 69 Column: 41

                  def test_zerosSD(self):
        # Check creation of single-dimensional objects
        ua = np.zeros((2,), dtype='U%s' % self.ulen)
        self.content_check(ua, ua[0], 4*self.ulen*2)
        self.content_check(ua, ua[1], 4*self.ulen*2)

    def test_zerosMD(self):
        # Check creation of multi-dimensional objects
        ua = np.zeros((2, 3, 4), dtype='U%s' % self.ulen)

            

Reported by Pylint.

Instance of 'CreateZeros' has no 'ulen' member
Error

Line: 70 Column: 41

                      # Check creation of single-dimensional objects
        ua = np.zeros((2,), dtype='U%s' % self.ulen)
        self.content_check(ua, ua[0], 4*self.ulen*2)
        self.content_check(ua, ua[1], 4*self.ulen*2)

    def test_zerosMD(self):
        # Check creation of multi-dimensional objects
        ua = np.zeros((2, 3, 4), dtype='U%s' % self.ulen)
        self.content_check(ua, ua[0, 0, 0], 4*self.ulen*2*3*4)

            

Reported by Pylint.

Instance of 'CreateZeros' has no 'ulen' member
Error

Line: 74 Column: 48

              
    def test_zerosMD(self):
        # Check creation of multi-dimensional objects
        ua = np.zeros((2, 3, 4), dtype='U%s' % self.ulen)
        self.content_check(ua, ua[0, 0, 0], 4*self.ulen*2*3*4)
        self.content_check(ua, ua[-1, -1, -1], 4*self.ulen*2*3*4)


class TestCreateZeros_1(CreateZeros):

            

Reported by Pylint.

Instance of 'CreateZeros' has no 'ulen' member
Error

Line: 75 Column: 47

                  def test_zerosMD(self):
        # Check creation of multi-dimensional objects
        ua = np.zeros((2, 3, 4), dtype='U%s' % self.ulen)
        self.content_check(ua, ua[0, 0, 0], 4*self.ulen*2*3*4)
        self.content_check(ua, ua[-1, -1, -1], 4*self.ulen*2*3*4)


class TestCreateZeros_1(CreateZeros):
    """Check the creation of zero-valued arrays (size 1)"""

            

Reported by Pylint.

Instance of 'CreateZeros' has no 'ulen' member
Error

Line: 76 Column: 50

                      # Check creation of multi-dimensional objects
        ua = np.zeros((2, 3, 4), dtype='U%s' % self.ulen)
        self.content_check(ua, ua[0, 0, 0], 4*self.ulen*2*3*4)
        self.content_check(ua, ua[-1, -1, -1], 4*self.ulen*2*3*4)


class TestCreateZeros_1(CreateZeros):
    """Check the creation of zero-valued arrays (size 1)"""
    ulen = 1

            

Reported by Pylint.

Instance of 'CreateValues' has no 'ulen' member
Error

Line: 100 Column: 42

                  def content_check(self, ua, ua_scalar, nbytes):

        # Check the length of the unicode base type
        assert_(int(ua.dtype.str[2:]) == self.ulen)
        # Check the length of the data buffer
        assert_(buffer_length(ua) == nbytes)
        # Small check that data in array element is ok
        assert_(ua_scalar == self.ucs_value*self.ulen)
        # Encode to UTF-8 and double check

            

Reported by Pylint.

numpy/core/tests/test_overrides.py
175 issues
Unable to import 'pytest'
Error

Line: 15 Column: 1

                  _get_implementing_args, array_function_dispatch,
    verify_matching_signatures, ARRAY_FUNCTION_ENABLED)
from numpy.compat import pickle
import pytest


requires_array_function = pytest.mark.skipif(
    not ARRAY_FUNCTION_ENABLED,
    reason="__array_function__ dispatch not enabled.")

            

Reported by Pylint.

Instance of 'ndarray' has no '__array_function__' member
Error

Line: 170 Column: 18

                      no_override_sub = array.view(NoOverrideSub)
        override_sub = array.view(OverrideSub)

        result = array.__array_function__(func=dispatched_two_arg,
                                          types=(np.ndarray,),
                                          args=(array, 1.), kwargs={})
        assert_equal(result, 'original')

        result = array.__array_function__(func=dispatched_two_arg,

            

Reported by Pylint.

Instance of 'ndarray' has no '__array_function__' member
Error

Line: 175 Column: 18

                                                        args=(array, 1.), kwargs={})
        assert_equal(result, 'original')

        result = array.__array_function__(func=dispatched_two_arg,
                                          types=(np.ndarray, Other),
                                          args=(array, other), kwargs={})
        assert_(result is NotImplemented)

        result = array.__array_function__(func=dispatched_two_arg,

            

Reported by Pylint.

Instance of 'ndarray' has no '__array_function__' member
Error

Line: 180 Column: 18

                                                        args=(array, other), kwargs={})
        assert_(result is NotImplemented)

        result = array.__array_function__(func=dispatched_two_arg,
                                          types=(np.ndarray, NoOverrideSub),
                                          args=(array, no_override_sub),
                                          kwargs={})
        assert_equal(result, 'original')


            

Reported by Pylint.

Instance of 'ndarray' has no '__array_function__' member
Error

Line: 186 Column: 18

                                                        kwargs={})
        assert_equal(result, 'original')

        result = array.__array_function__(func=dispatched_two_arg,
                                          types=(np.ndarray, OverrideSub),
                                          args=(array, override_sub),
                                          kwargs={})
        assert_equal(result, 'original')


            

Reported by Pylint.

Instance of 'ndarray' has no '__array_function__' member
Error

Line: 208 Column: 13

                      array = np.array(1)
        func = lambda x: x
        with assert_raises_regex(AttributeError, '_implementation'):
            array.__array_function__(func=func, types=(np.ndarray,),
                                     args=(array,), kwargs={})


@requires_array_function
class TestArrayFunctionDispatch:

            

Reported by Pylint.

function already defined line 274
Error

Line: 279 Column: 9

              
        # should not raise
        @array_function_dispatch(lambda x: (x,), verify=False)
        def f(y):
            pass


def _new_duck_type_and_implements():
    """Create a duck array type and implements functions."""

            

Reported by Pylint.

Unexpected keyword argument 'new_option' in function call
Error

Line: 341 Column: 13

                      result = my_array_func_with_option(MyArray(), new_option='yes')
        assert_equal(result, 'yes')
        with assert_raises(TypeError):
            func_with_option(MyArray(), new_option='no')

    def test_not_implemented(self):
        MyArray, implements = _new_duck_type_and_implements()

        @array_function_dispatch(lambda array: (array,), module='my')

            

Reported by Pylint.

Method has no argument
Error

Line: 366 Column: 13

                      # implement np.array_repr()

        class MyArray(np.ndarray):
            def __array_function__(*args, **kwargs):
                return NotImplemented

        array = np.array(1).view(MyArray)
        assert_equal(repr(array), 'MyArray(1)')
        assert_equal(str(array), '1')

            

Reported by Pylint.

Super of 'MyArray' has no '__array_function__' member
Error

Line: 426 Column: 24

                              return 'summed'

            def __array_function__(self, func, types, args, kwargs):
                return super().__array_function__(func, types, args, kwargs)

        # note: the internal implementation of np.sum() calls the .sum() method
        array = np.array(1).view(MyArray)
        assert_equal(np.sum(array), 'summed')


            

Reported by Pylint.

numpy/polynomial/tests/test_legendre.py
174 issues
Module 'numpy.random' has no 'random' member
Error

Line: 120 Column: 9

                  c3d = np.einsum('i,j,k->ijk', c1d, c1d, c1d)

    # some random values in [-1, 1)
    x = np.random.random((3, 5))*2 - 1
    y = polyval(x, [1., 2., 3.])

    def test_legval(self):
        #check empty input
        assert_equal(leg.legval([], [1]).size, 0)

            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 294 Column: 15

              
    def test_legint_axis(self):
        # check that axis keyword works
        c2d = np.random.random((3, 4))

        tgt = np.vstack([leg.legint(c) for c in c2d.T]).T
        res = leg.legint(c2d, axis=0)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 341 Column: 15

              
    def test_legder_axis(self):
        # check that axis keyword works
        c2d = np.random.random((3, 4))

        tgt = np.vstack([leg.legder(c) for c in c2d.T]).T
        res = leg.legder(c2d, axis=0)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 357 Column: 9

              
class TestVander:
    # some random values in [-1, 1)
    x = np.random.random((3, 5))*2 - 1

    def test_legvander(self):
        # check for 1d x
        x = np.arange(3)
        v = leg.legvander(x, 3)

            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 379 Column: 13

                  def test_legvander2d(self):
        # also tests polyval2d for non-square coefficient array
        x1, x2, x3 = self.x
        c = np.random.random((2, 3))
        van = leg.legvander2d(x1, x2, [1, 2])
        tgt = leg.legval2d(x1, x2, c)
        res = np.dot(van, c.flat)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 392 Column: 13

                  def test_legvander3d(self):
        # also tests polyval3d for non-square coefficient array
        x1, x2, x3 = self.x
        c = np.random.random((2, 3, 4))
        van = leg.legvander3d(x1, x2, x3, [1, 2, 3])
        tgt = leg.legval3d(x1, x2, x3, c)
        res = np.dot(van, c.flat)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 89 Column: 17

                              val2 = leg.legval(self.x, pol2)
                pol3 = leg.legmul(pol1, pol2)
                val3 = leg.legval(self.x, pol3)
                assert_(len(pol3) == i + j + 1, msg)
                assert_almost_equal(val3, val1*val2, err_msg=msg)

    def test_legdiv(self):
        for i in range(5):
            for j in range(5):

            

Reported by Pylint.

Unused variable 'x3'
Error

Line: 145 Column: 17

                          assert_equal(leg.legval(x, [1, 0, 0]).shape, dims)

    def test_legval2d(self):
        x1, x2, x3 = self.x
        y1, y2, y3 = self.y

        #test exceptions
        assert_raises(ValueError, leg.legval2d, x1, x2[:2], self.c2d)


            

Reported by Pylint.

Unused variable 'y3'
Error

Line: 146 Column: 17

              
    def test_legval2d(self):
        x1, x2, x3 = self.x
        y1, y2, y3 = self.y

        #test exceptions
        assert_raises(ValueError, leg.legval2d, x1, x2[:2], self.c2d)

        #test values

            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 159 Column: 9

                      #test shape
        z = np.ones((2, 3))
        res = leg.legval2d(z, z, self.c2d)
        assert_(res.shape == (2, 3))

    def test_legval3d(self):
        x1, x2, x3 = self.x
        y1, y2, y3 = self.y


            

Reported by Pylint.

numpy/polynomial/tests/test_polynomial.py
171 issues
Module 'numpy.random' has no 'random' member
Error

Line: 122 Column: 9

                  c3d = np.einsum('i,j,k->ijk', c1d, c1d, c1d)

    # some random values in [-1, 1)
    x = np.random.random((3, 5))*2 - 1
    y = poly.polyval(x, [1., 2., 3.])

    def test_polyval(self):
        #check empty input
        assert_equal(poly.polyval([], [1]).size, 0)

            

Reported by Pylint.

Module 'numpy.random' has no 'randint' member
Error

Line: 209 Column: 13

                      # check tensor=False
        rshape = (3, 5)
        x = np.arange(-3, 2)
        r = np.random.randint(-5, 5, size=rshape)
        res = poly.polyvalfromroots(x, r, tensor=False)
        tgt = np.empty(r.shape[1:])
        for ii in range(tgt.size):
            tgt[ii] = poly.polyvalfromroots(x[ii], r[:, ii])
        assert_equal(res, tgt)

            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 374 Column: 15

              
    def test_polyint_axis(self):
        # check that axis keyword works
        c2d = np.random.random((3, 4))

        tgt = np.vstack([poly.polyint(c) for c in c2d.T]).T
        res = poly.polyint(c2d, axis=0)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 418 Column: 15

              
    def test_polyder_axis(self):
        # check that axis keyword works
        c2d = np.random.random((3, 4))

        tgt = np.vstack([poly.polyder(c) for c in c2d.T]).T
        res = poly.polyder(c2d, axis=0)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 431 Column: 9

              
class TestVander:
    # some random values in [-1, 1)
    x = np.random.random((3, 5))*2 - 1

    def test_polyvander(self):
        # check for 1d x
        x = np.arange(3)
        v = poly.polyvander(x, 3)

            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 453 Column: 13

                  def test_polyvander2d(self):
        # also tests polyval2d for non-square coefficient array
        x1, x2, x3 = self.x
        c = np.random.random((2, 3))
        van = poly.polyvander2d(x1, x2, [1, 2])
        tgt = poly.polyval2d(x1, x2, c)
        res = np.dot(van, c.flat)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Module 'numpy.random' has no 'random' member
Error

Line: 466 Column: 13

                  def test_polyvander3d(self):
        # also tests polyval3d for non-square coefficient array
        x1, x2, x3 = self.x
        c = np.random.random((2, 3, 4))
        van = poly.polyvander3d(x1, x2, x3, [1, 2, 3])
        tgt = poly.polyval3d(x1, x2, x3, c)
        res = np.dot(van, c.flat)
        assert_almost_equal(res, tgt)


            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 169 Column: 9

              
        # check empty input
        assert_equal(poly.polyvalfromroots([], [1]).size, 0)
        assert_(poly.polyvalfromroots([], [1]).shape == (0,))

        # check empty input + multidimensional roots
        assert_equal(poly.polyvalfromroots([], [[1] * 5]).size, 0)
        assert_(poly.polyvalfromroots([], [[1] * 5]).shape == (5, 0))


            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 173 Column: 9

              
        # check empty input + multidimensional roots
        assert_equal(poly.polyvalfromroots([], [[1] * 5]).size, 0)
        assert_(poly.polyvalfromroots([], [[1] * 5]).shape == (5, 0))

        # check scalar input
        assert_equal(poly.polyvalfromroots(1, 1), 0)
        assert_(poly.polyvalfromroots(1, np.ones((3, 3))).shape == (3,))


            

Reported by Pylint.

Using deprecated method assert_()
Error

Line: 177 Column: 9

              
        # check scalar input
        assert_equal(poly.polyvalfromroots(1, 1), 0)
        assert_(poly.polyvalfromroots(1, np.ones((3, 3))).shape == (3,))

        # check normal input)
        x = np.linspace(-1, 1)
        y = [x**i for i in range(5)]
        for i in range(1, 5):

            

Reported by Pylint.