The following issues were found

numpy/typing/tests/data/reveal/npyio.py
58 issues
Value 'np.lib.npyio.BagObj' is unsubscriptable
Error

Line: 13 Column: 10

              str_file: IO[str]
bytes_file: IO[bytes]

bag_obj: np.lib.npyio.BagObj[int]
npz_file: np.lib.npyio.NpzFile

AR_i8: npt.NDArray[np.int64]
AR_LIKE_f8: List[float]


            

Reported by Pylint.

Module 'numpy.typing' has no 'NDArray' member
Error

Line: 16 Column: 8

              bag_obj: np.lib.npyio.BagObj[int]
npz_file: np.lib.npyio.NpzFile

AR_i8: npt.NDArray[np.int64]
AR_LIKE_f8: List[float]

reveal_type(bag_obj.a)  # E: int
reveal_type(bag_obj.b)  # E: int


            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 19 Column: 1

              AR_i8: npt.NDArray[np.int64]
AR_LIKE_f8: List[float]

reveal_type(bag_obj.a)  # E: int
reveal_type(bag_obj.b)  # E: int

reveal_type(npz_file.zip)  # E: zipfile.ZipFile
reveal_type(npz_file.fid)  # E: Union[None, typing.IO[builtins.str]]
reveal_type(npz_file.files)  # E: list[builtins.str]

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 20 Column: 1

              AR_LIKE_f8: List[float]

reveal_type(bag_obj.a)  # E: int
reveal_type(bag_obj.b)  # E: int

reveal_type(npz_file.zip)  # E: zipfile.ZipFile
reveal_type(npz_file.fid)  # E: Union[None, typing.IO[builtins.str]]
reveal_type(npz_file.files)  # E: list[builtins.str]
reveal_type(npz_file.allow_pickle)  # E: bool

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 22 Column: 1

              reveal_type(bag_obj.a)  # E: int
reveal_type(bag_obj.b)  # E: int

reveal_type(npz_file.zip)  # E: zipfile.ZipFile
reveal_type(npz_file.fid)  # E: Union[None, typing.IO[builtins.str]]
reveal_type(npz_file.files)  # E: list[builtins.str]
reveal_type(npz_file.allow_pickle)  # E: bool
reveal_type(npz_file.pickle_kwargs)  # E: Union[None, typing.Mapping[builtins.str, Any]]
reveal_type(npz_file.f)  # E: numpy.lib.npyio.BagObj[numpy.lib.npyio.NpzFile]

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 23 Column: 1

              reveal_type(bag_obj.b)  # E: int

reveal_type(npz_file.zip)  # E: zipfile.ZipFile
reveal_type(npz_file.fid)  # E: Union[None, typing.IO[builtins.str]]
reveal_type(npz_file.files)  # E: list[builtins.str]
reveal_type(npz_file.allow_pickle)  # E: bool
reveal_type(npz_file.pickle_kwargs)  # E: Union[None, typing.Mapping[builtins.str, Any]]
reveal_type(npz_file.f)  # E: numpy.lib.npyio.BagObj[numpy.lib.npyio.NpzFile]
reveal_type(npz_file["test"])  # E: numpy.ndarray[Any, numpy.dtype[Any]]

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 24 Column: 1

              
reveal_type(npz_file.zip)  # E: zipfile.ZipFile
reveal_type(npz_file.fid)  # E: Union[None, typing.IO[builtins.str]]
reveal_type(npz_file.files)  # E: list[builtins.str]
reveal_type(npz_file.allow_pickle)  # E: bool
reveal_type(npz_file.pickle_kwargs)  # E: Union[None, typing.Mapping[builtins.str, Any]]
reveal_type(npz_file.f)  # E: numpy.lib.npyio.BagObj[numpy.lib.npyio.NpzFile]
reveal_type(npz_file["test"])  # E: numpy.ndarray[Any, numpy.dtype[Any]]
reveal_type(len(npz_file))  # E: int

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 25 Column: 1

              reveal_type(npz_file.zip)  # E: zipfile.ZipFile
reveal_type(npz_file.fid)  # E: Union[None, typing.IO[builtins.str]]
reveal_type(npz_file.files)  # E: list[builtins.str]
reveal_type(npz_file.allow_pickle)  # E: bool
reveal_type(npz_file.pickle_kwargs)  # E: Union[None, typing.Mapping[builtins.str, Any]]
reveal_type(npz_file.f)  # E: numpy.lib.npyio.BagObj[numpy.lib.npyio.NpzFile]
reveal_type(npz_file["test"])  # E: numpy.ndarray[Any, numpy.dtype[Any]]
reveal_type(len(npz_file))  # E: int
with npz_file as f:

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 26 Column: 1

              reveal_type(npz_file.fid)  # E: Union[None, typing.IO[builtins.str]]
reveal_type(npz_file.files)  # E: list[builtins.str]
reveal_type(npz_file.allow_pickle)  # E: bool
reveal_type(npz_file.pickle_kwargs)  # E: Union[None, typing.Mapping[builtins.str, Any]]
reveal_type(npz_file.f)  # E: numpy.lib.npyio.BagObj[numpy.lib.npyio.NpzFile]
reveal_type(npz_file["test"])  # E: numpy.ndarray[Any, numpy.dtype[Any]]
reveal_type(len(npz_file))  # E: int
with npz_file as f:
    reveal_type(f)  # E: numpy.lib.npyio.NpzFile

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 27 Column: 1

              reveal_type(npz_file.files)  # E: list[builtins.str]
reveal_type(npz_file.allow_pickle)  # E: bool
reveal_type(npz_file.pickle_kwargs)  # E: Union[None, typing.Mapping[builtins.str, Any]]
reveal_type(npz_file.f)  # E: numpy.lib.npyio.BagObj[numpy.lib.npyio.NpzFile]
reveal_type(npz_file["test"])  # E: numpy.ndarray[Any, numpy.dtype[Any]]
reveal_type(len(npz_file))  # E: int
with npz_file as f:
    reveal_type(f)  # E: numpy.lib.npyio.NpzFile


            

Reported by Pylint.

numpy/polynomial/_polybase.py
58 issues
Attempted relative import beyond top-level package
Error

Line: 14 Column: 1

              import numbers

import numpy as np
from . import polyutils as pu

__all__ = ['ABCPolyBase']

class ABCPolyBase(abc.ABC):
    """An abstract base class for immutable series classes.

            

Reported by Pylint.

Unexpected keyword argument 'w' in staticmethod call
Error

Line: 980 Column: 15

                          window = cls.window

        xnew = pu.mapdomain(x, domain, window)
        res = cls._fit(xnew, y, deg, w=w, rcond=rcond, full=full)
        if full:
            [coef, status] = res
            return cls(coef, domain=domain, window=window), status
        else:
            coef = res

            

Reported by Pylint.

Redefining built-in 'pow'
Error

Line: 139 Column: 17

              
    @staticmethod
    @abc.abstractmethod
    def _pow(c, pow, maxpower=None):
        pass

    @staticmethod
    @abc.abstractmethod
    def _val(x, c):

            

Reported by Pylint.

Unused argument 'needs_parens'
Error

Line: 397 Column: 43

                      return f" {cls.basis_name}_{i}({arg_str})"

    @classmethod
    def _repr_latex_term(cls, i, arg_str, needs_parens):
        if cls.basis_name is None:
            raise NotImplementedError(
                "Subclasses must define either a basis name, or override "
                "_repr_latex_term(i, arg_str, needs_parens)")
        # since we always add parens, we don't care if the expression needs them

            

Reported by Pylint.

TODO: we're stuck with disabling math formatting until we handle
Error

Line: 407 Column: 3

              
    @staticmethod
    def _repr_latex_scalar(x):
        # TODO: we're stuck with disabling math formatting until we handle
        # exponents in this function
        return r'\text{{{}}}'.format(x)

    def _repr_latex_(self):
        # get the scaled argument string to the basis functions

            

Reported by Pylint.

Redefining built-in 'dict'
Error

Line: 475 Column: 28

                      ret['window'] = self.window.copy()
        return ret

    def __setstate__(self, dict):
        self.__dict__ = dict

    # Call

    def __call__(self, arg):

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 503 Column: 16

                      othercoef = self._get_coefficients(other)
        try:
            coef = self._add(self.coef, othercoef)
        except Exception:
            return NotImplemented
        return self.__class__(coef, self.domain, self.window)

    def __sub__(self, other):
        othercoef = self._get_coefficients(other)

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 511 Column: 16

                      othercoef = self._get_coefficients(other)
        try:
            coef = self._sub(self.coef, othercoef)
        except Exception:
            return NotImplemented
        return self.__class__(coef, self.domain, self.window)

    def __mul__(self, other):
        othercoef = self._get_coefficients(other)

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 519 Column: 16

                      othercoef = self._get_coefficients(other)
        try:
            coef = self._mul(self.coef, othercoef)
        except Exception:
            return NotImplemented
        return self.__class__(coef, self.domain, self.window)

    def __truediv__(self, other):
        # there is no true divide if the rhs is not a Number, although it

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 552 Column: 16

                          quo, rem = self._div(self.coef, othercoef)
        except ZeroDivisionError:
            raise
        except Exception:
            return NotImplemented
        quo = self.__class__(quo, self.domain, self.window)
        rem = self.__class__(rem, self.domain, self.window)
        return quo, rem


            

Reported by Pylint.

benchmarks/benchmarks/bench_indexing.py
58 issues
Attempted relative import beyond top-level package
Error

Line: 1 Column: 1

              from .common import Benchmark, get_squares_, get_indexes_, get_indexes_rand_

from os.path import join as pjoin
import shutil
from numpy import memmap, float32, array
import numpy as np
from tempfile import mkdtemp



            

Reported by Pylint.

Use of exec detected.
Security

Line: 27
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b102_exec_used.html

                      code = "def run():\n    for a in squares_.values(): a[%s]%s"
        code = code % (sel, op)

        exec(code, ns)
        self.func = ns['run']

    def time_op(self, indexes, sel, op):
        self.func()


            

Reported by Bandit.

Use of exec
Error

Line: 27 Column: 9

                      code = "def run():\n    for a in squares_.values(): a[%s]%s"
        code = code % (sel, op)

        exec(code, ns)
        self.func = ns['run']

    def time_op(self, indexes, sel, op):
        self.func()


            

Reported by Pylint.

Attribute 'func' defined outside __init__
Error

Line: 28 Column: 9

                      code = code % (sel, op)

        exec(code, ns)
        self.func = ns['run']

    def time_op(self, indexes, sel, op):
        self.func()



            

Reported by Pylint.

Unused argument 'indexes'
Error

Line: 30 Column: 23

                      exec(code, ns)
        self.func = ns['run']

    def time_op(self, indexes, sel, op):
        self.func()


class ScalarIndexing(Benchmark):
    params = [[0, 1, 2]]

            

Reported by Pylint.

Unused argument 'sel'
Error

Line: 30 Column: 32

                      exec(code, ns)
        self.func = ns['run']

    def time_op(self, indexes, sel, op):
        self.func()


class ScalarIndexing(Benchmark):
    params = [[0, 1, 2]]

            

Reported by Pylint.

Unused argument 'op'
Error

Line: 30 Column: 37

                      exec(code, ns)
        self.func = ns['run']

    def time_op(self, indexes, sel, op):
        self.func()


class ScalarIndexing(Benchmark):
    params = [[0, 1, 2]]

            

Reported by Pylint.

Attribute 'array' defined outside __init__
Error

Line: 39 Column: 9

                  param_names = ["ndim"]

    def setup(self, ndim):
        self.array = np.ones((5,) * ndim)

    def time_index(self, ndim):
        # time indexing.
        arr = self.array
        indx = (1,) * ndim

            

Reported by Pylint.

Unused variable 'i'
Error

Line: 45 Column: 13

                      # time indexing.
        arr = self.array
        indx = (1,) * ndim
        for i in range(100):
            arr[indx]

    def time_assign(self, ndim):
        # time assignment from a python scalar
        arr = self.array

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 46 Column: 13

                      arr = self.array
        indx = (1,) * ndim
        for i in range(100):
            arr[indx]

    def time_assign(self, ndim):
        # time assignment from a python scalar
        arr = self.array
        indx = (1,) * ndim

            

Reported by Pylint.

numpy/core/_internal.py
57 issues
Attempted relative import beyond top-level package
Error

Line: 13 Column: 1

              import platform
import warnings

from .multiarray import dtype, array, ndarray
try:
    import ctypes
except ImportError:
    ctypes = None


            

Reported by Pylint.

Redefining built-in 'format'
Error

Line: 38 Column: 9

                      num = int(obj[1])
        if num < 0:
            raise ValueError("invalid offset.")
        format = dtype(obj[0], align=align)
        if n > 2:
            title = obj[2]
        else:
            title = None
        allfields.append((fname, format, num, title))

            

Reported by Pylint.

Redefining name 'dtype' from outer scope (line 13)
Error

Line: 140 Column: 34

              # pickles of ndarrays made with NumPy before release 1.0
# so don't remove the name here, or you'll
# break backward compatibility.
def _reconstruct(subtype, shape, dtype):
    return ndarray.__new__(subtype, shape, dtype)


# format_re was originally from numarray by J. Todd Miller


            

Reported by Pylint.

Redefining name 'dtype' from outer scope (line 13)
Error

Line: 163 Column: 39

                  while startindex < len(astr):
        mo = format_re.match(astr, pos=startindex)
        try:
            (order1, repeats, order2, dtype) = mo.groups()
        except (TypeError, AttributeError):
            raise ValueError(
                f'format number {len(result)+1} of "{astr}" is not recognized'
                ) from None
        startindex = mo.end()

            

Reported by Pylint.

Unused argument 'obj'
Error

Line: 241 Column: 25

              # Used for .ctypes attribute of ndarray

class _missing_ctypes:
    def cast(self, num, obj):
        return num.value

    class c_void_p:
        def __init__(self, ptr):
            self.value = ptr

            

Reported by Pylint.

Redefining name 'array' from outer scope (line 13)
Error

Line: 250 Column: 24

              

class _ctypes:
    def __init__(self, array, ptr=None):
        self._arr = array

        if ctypes:
            self._ctypes = ctypes
            self._data = self._ctypes.c_void_p(ptr)

            

Reported by Pylint.

Access to a protected member _arr of a client class
Error

Line: 283 Column: 9

                      # it hold the array reference. This is a workaround to circumvent the
        # CPython bug https://bugs.python.org/issue12836
        ptr = self._ctypes.cast(self._data, obj)
        ptr._arr = self._arr
        return ptr

    def shape_as(self, obj):
        """
        Return the shape tuple as an array of some other c-types

            

Reported by Pylint.

Unused variable 'align'
Error

Line: 597 Column: 12

              
def _dtype_from_pep3118(spec):
    stream = _Stream(spec)
    dtype, align = __dtype_from_pep3118(stream, is_subdtype=False)
    return dtype

def __dtype_from_pep3118(stream, is_subdtype):
    field_spec = dict(
        names=[],

            

Reported by Pylint.

Redefining name 'dtype' from outer scope (line 13)
Error

Line: 597 Column: 5

              
def _dtype_from_pep3118(spec):
    stream = _Stream(spec)
    dtype, align = __dtype_from_pep3118(stream, is_subdtype=False)
    return dtype

def __dtype_from_pep3118(stream, is_subdtype):
    field_spec = dict(
        names=[],

            

Reported by Pylint.

Unused argument 'dummy'
Error

Line: 796 Column: 34

              def _lcm(a, b):
    return a // _gcd(a, b) * b

def array_ufunc_errmsg_formatter(dummy, ufunc, method, *inputs, **kwargs):
    """ Format the error message for when __array_ufunc__ gives up. """
    args_string = ', '.join(['{!r}'.format(arg) for arg in inputs] +
                            ['{}={!r}'.format(k, v)
                             for k, v in kwargs.items()])
    args = inputs + kwargs.get('out', ())

            

Reported by Pylint.

benchmarks/benchmarks/bench_lib.py
57 issues
Attempted relative import beyond top-level package
Error

Line: 4 Column: 1

              """Benchmarks for `numpy.lib`."""


from .common import Benchmark

import numpy as np


class Pad(Benchmark):

            

Reported by Pylint.

Unused argument 'pad_width'
Error

Line: 48 Column: 28

                      ["constant", "edge", "linear_ramp", "mean", "reflect", "wrap"],
    ]

    def setup(self, shape, pad_width, mode):
        # Make sure to fill the array to make the OS page fault
        # in the setup phase and not the timed phase
        self.array = np.full(shape, fill_value=1, dtype=np.float64)

    def time_pad(self, shape, pad_width, mode):

            

Reported by Pylint.

Unused argument 'mode'
Error

Line: 48 Column: 39

                      ["constant", "edge", "linear_ramp", "mean", "reflect", "wrap"],
    ]

    def setup(self, shape, pad_width, mode):
        # Make sure to fill the array to make the OS page fault
        # in the setup phase and not the timed phase
        self.array = np.full(shape, fill_value=1, dtype=np.float64)

    def time_pad(self, shape, pad_width, mode):

            

Reported by Pylint.

Attribute 'array' defined outside __init__
Error

Line: 51 Column: 9

                  def setup(self, shape, pad_width, mode):
        # Make sure to fill the array to make the OS page fault
        # in the setup phase and not the timed phase
        self.array = np.full(shape, fill_value=1, dtype=np.float64)

    def time_pad(self, shape, pad_width, mode):
        np.pad(self.array, pad_width, mode)



            

Reported by Pylint.

Unused argument 'shape'
Error

Line: 53 Column: 24

                      # in the setup phase and not the timed phase
        self.array = np.full(shape, fill_value=1, dtype=np.float64)

    def time_pad(self, shape, pad_width, mode):
        np.pad(self.array, pad_width, mode)


class Nan(Benchmark):
    """Benchmarks for nan functions"""

            

Reported by Pylint.

Attribute 'arr' defined outside __init__
Error

Line: 74 Column: 9

                      # approximate desired percentage np.nan content
        base_array = np.random.uniform(size=array_size)
        base_array[base_array < percent_nans / 100.] = np.nan
        self.arr = base_array

    def time_nanmin(self, array_size, percent_nans):
        np.nanmin(self.arr)

    def time_nanmax(self, array_size, percent_nans):

            

Reported by Pylint.

Unused argument 'array_size'
Error

Line: 76 Column: 27

                      base_array[base_array < percent_nans / 100.] = np.nan
        self.arr = base_array

    def time_nanmin(self, array_size, percent_nans):
        np.nanmin(self.arr)

    def time_nanmax(self, array_size, percent_nans):
        np.nanmax(self.arr)


            

Reported by Pylint.

Unused argument 'percent_nans'
Error

Line: 76 Column: 39

                      base_array[base_array < percent_nans / 100.] = np.nan
        self.arr = base_array

    def time_nanmin(self, array_size, percent_nans):
        np.nanmin(self.arr)

    def time_nanmax(self, array_size, percent_nans):
        np.nanmax(self.arr)


            

Reported by Pylint.

Unused argument 'array_size'
Error

Line: 79 Column: 27

                  def time_nanmin(self, array_size, percent_nans):
        np.nanmin(self.arr)

    def time_nanmax(self, array_size, percent_nans):
        np.nanmax(self.arr)

    def time_nanargmin(self, array_size, percent_nans):
        np.nanargmin(self.arr)


            

Reported by Pylint.

Unused argument 'percent_nans'
Error

Line: 79 Column: 39

                  def time_nanmin(self, array_size, percent_nans):
        np.nanmin(self.arr)

    def time_nanmax(self, array_size, percent_nans):
        np.nanmax(self.arr)

    def time_nanargmin(self, array_size, percent_nans):
        np.nanargmin(self.arr)


            

Reported by Pylint.

numpy/typing/tests/data/reveal/type_check.py
57 issues
Module 'numpy.typing' has no 'NDArray' member
Error

Line: 9 Column: 8

              f: float

# NOTE: Avoid importing the platform specific `np.float128` type
AR_i8: npt.NDArray[np.int64]
AR_i4: npt.NDArray[np.int32]
AR_f2: npt.NDArray[np.float16]
AR_f8: npt.NDArray[np.float64]
AR_f16: npt.NDArray[np.floating[npt._128Bit]]
AR_c8: npt.NDArray[np.complex64]

            

Reported by Pylint.

Module 'numpy.typing' has no 'NDArray' member
Error

Line: 10 Column: 8

              
# NOTE: Avoid importing the platform specific `np.float128` type
AR_i8: npt.NDArray[np.int64]
AR_i4: npt.NDArray[np.int32]
AR_f2: npt.NDArray[np.float16]
AR_f8: npt.NDArray[np.float64]
AR_f16: npt.NDArray[np.floating[npt._128Bit]]
AR_c8: npt.NDArray[np.complex64]
AR_c16: npt.NDArray[np.complex128]

            

Reported by Pylint.

Module 'numpy.typing' has no 'NDArray' member
Error

Line: 11 Column: 8

              # NOTE: Avoid importing the platform specific `np.float128` type
AR_i8: npt.NDArray[np.int64]
AR_i4: npt.NDArray[np.int32]
AR_f2: npt.NDArray[np.float16]
AR_f8: npt.NDArray[np.float64]
AR_f16: npt.NDArray[np.floating[npt._128Bit]]
AR_c8: npt.NDArray[np.complex64]
AR_c16: npt.NDArray[np.complex128]


            

Reported by Pylint.

Module 'numpy.typing' has no 'NDArray' member
Error

Line: 12 Column: 8

              AR_i8: npt.NDArray[np.int64]
AR_i4: npt.NDArray[np.int32]
AR_f2: npt.NDArray[np.float16]
AR_f8: npt.NDArray[np.float64]
AR_f16: npt.NDArray[np.floating[npt._128Bit]]
AR_c8: npt.NDArray[np.complex64]
AR_c16: npt.NDArray[np.complex128]

AR_LIKE_f: List[float]

            

Reported by Pylint.

Module 'numpy.typing' has no 'NDArray' member
Error

Line: 13 Column: 9

              AR_i4: npt.NDArray[np.int32]
AR_f2: npt.NDArray[np.float16]
AR_f8: npt.NDArray[np.float64]
AR_f16: npt.NDArray[np.floating[npt._128Bit]]
AR_c8: npt.NDArray[np.complex64]
AR_c16: npt.NDArray[np.complex128]

AR_LIKE_f: List[float]


            

Reported by Pylint.

Value 'np.floating' is unsubscriptable
Error

Line: 13 Column: 21

              AR_i4: npt.NDArray[np.int32]
AR_f2: npt.NDArray[np.float16]
AR_f8: npt.NDArray[np.float64]
AR_f16: npt.NDArray[np.floating[npt._128Bit]]
AR_c8: npt.NDArray[np.complex64]
AR_c16: npt.NDArray[np.complex128]

AR_LIKE_f: List[float]


            

Reported by Pylint.

Module 'numpy.typing' has no 'NDArray' member
Error

Line: 14 Column: 8

              AR_f2: npt.NDArray[np.float16]
AR_f8: npt.NDArray[np.float64]
AR_f16: npt.NDArray[np.floating[npt._128Bit]]
AR_c8: npt.NDArray[np.complex64]
AR_c16: npt.NDArray[np.complex128]

AR_LIKE_f: List[float]

class RealObj:

            

Reported by Pylint.

Module 'numpy.typing' has no 'NDArray' member
Error

Line: 15 Column: 9

              AR_f8: npt.NDArray[np.float64]
AR_f16: npt.NDArray[np.floating[npt._128Bit]]
AR_c8: npt.NDArray[np.complex64]
AR_c16: npt.NDArray[np.complex128]

AR_LIKE_f: List[float]

class RealObj:
    real: slice

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 25 Column: 1

              class ImagObj:
    imag: slice

reveal_type(np.mintypecode(["f8"], typeset="qfQF"))

reveal_type(np.asfarray(AR_f8))  # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
reveal_type(np.asfarray(AR_LIKE_f))  # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
reveal_type(np.asfarray(AR_f8, dtype="c16"))  # E: numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]
reveal_type(np.asfarray(AR_f8, dtype="i8"))  # E: numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 27 Column: 1

              
reveal_type(np.mintypecode(["f8"], typeset="qfQF"))

reveal_type(np.asfarray(AR_f8))  # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
reveal_type(np.asfarray(AR_LIKE_f))  # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
reveal_type(np.asfarray(AR_f8, dtype="c16"))  # E: numpy.ndarray[Any, numpy.dtype[numpy.complexfloating[Any, Any]]]
reveal_type(np.asfarray(AR_f8, dtype="i8"))  # E: numpy.ndarray[Any, numpy.dtype[numpy.floating[Any]]]

reveal_type(np.real(RealObj()))  # E: slice

            

Reported by Pylint.

numpy/lib/tests/test_packbits.py
56 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              import numpy as np
from numpy.testing import assert_array_equal, assert_equal, assert_raises
import pytest
from itertools import chain

def test_packbits():
    # Copied from the docstring.
    a = [[[1, 0, 1], [0, 1, 0]],
         [[1, 1, 0], [0, 0, 1]]]

            

Reported by Pylint.

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

Line: 203 Column: 15

                  # result is the same if input is multiplied with a nonzero value
    for dtype in 'bBhHiIlLqQ':
        arr = np.array(a, dtype=dtype)
        rnd = np.random.randint(low=np.iinfo(dtype).min,
                                high=np.iinfo(dtype).max, size=arr.size,
                                dtype=dtype)
        rnd[rnd == 0] = 1
        arr *= rnd.astype(dtype)
        b = np.packbits(arr, axis=-1)

            

Reported by Pylint.

Unused variable 'dt'
Error

Line: 218 Column: 13

                  # test some with a larger arrays gh-8637
    # code is covered earlier but larger array makes crash on bug more likely
    for s in range(950, 1050):
        for dt in '?bBhHiIlLqQ':
            x = np.ones((200, s), dtype=bool)
            np.packbits(x, axis=1)


def test_unpackbits():

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
from numpy.testing import assert_array_equal, assert_equal, assert_raises
import pytest
from itertools import chain

def test_packbits():
    # Copied from the docstring.
    a = [[[1, 0, 1], [0, 1, 0]],
         [[1, 1, 0], [0, 0, 1]]]

            

Reported by Pylint.

standard import "from itertools import chain" should be placed before "import numpy as np"
Error

Line: 4 Column: 1

              import numpy as np
from numpy.testing import assert_array_equal, assert_equal, assert_raises
import pytest
from itertools import chain

def test_packbits():
    # Copied from the docstring.
    a = [[[1, 0, 1], [0, 1, 0]],
         [[1, 1, 0], [0, 0, 1]]]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 6 Column: 1

              import pytest
from itertools import chain

def test_packbits():
    # Copied from the docstring.
    a = [[[1, 0, 1], [0, 1, 0]],
         [[1, 1, 0], [0, 0, 1]]]
    for dt in '?bBhHiIlLqQ':
        arr = np.array(a, dtype=dt)

            

Reported by Pylint.

Variable name "a" doesn't conform to snake_case naming style
Error

Line: 8 Column: 5

              
def test_packbits():
    # Copied from the docstring.
    a = [[[1, 0, 1], [0, 1, 0]],
         [[1, 1, 0], [0, 0, 1]]]
    for dt in '?bBhHiIlLqQ':
        arr = np.array(a, dtype=dt)
        b = np.packbits(arr, axis=-1)
        assert_equal(b.dtype, np.uint8)

            

Reported by Pylint.

Variable name "dt" doesn't conform to snake_case naming style
Error

Line: 10 Column: 9

                  # Copied from the docstring.
    a = [[[1, 0, 1], [0, 1, 0]],
         [[1, 1, 0], [0, 0, 1]]]
    for dt in '?bBhHiIlLqQ':
        arr = np.array(a, dtype=dt)
        b = np.packbits(arr, axis=-1)
        assert_equal(b.dtype, np.uint8)
        assert_array_equal(b, np.array([[[160], [64]], [[192], [32]]]))


            

Reported by Pylint.

Variable name "b" doesn't conform to snake_case naming style
Error

Line: 12 Column: 9

                       [[1, 1, 0], [0, 0, 1]]]
    for dt in '?bBhHiIlLqQ':
        arr = np.array(a, dtype=dt)
        b = np.packbits(arr, axis=-1)
        assert_equal(b.dtype, np.uint8)
        assert_array_equal(b, np.array([[[160], [64]], [[192], [32]]]))

    assert_raises(TypeError, np.packbits, np.array(a, dtype=float))


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

                  assert_raises(TypeError, np.packbits, np.array(a, dtype=float))


def test_packbits_empty():
    shapes = [
        (0,), (10, 20, 0), (10, 0, 20), (0, 10, 20), (20, 0, 0), (0, 20, 0),
        (0, 0, 20), (0, 0, 0),
    ]
    for dt in '?bBhHiIlLqQ':

            

Reported by Pylint.

numpy/core/records.py
56 issues
Attempted relative import beyond top-level package
Error

Line: 40 Column: 1

              from collections import Counter
from contextlib import nullcontext

from . import numeric as sb
from . import numerictypes as nt
from numpy.compat import os_fspath
from numpy.core.overrides import set_module
from .arrayprint import get_printoptions


            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 41 Column: 1

              from contextlib import nullcontext

from . import numeric as sb
from . import numerictypes as nt
from numpy.compat import os_fspath
from numpy.core.overrides import set_module
from .arrayprint import get_printoptions

# All of the functions allow formats to be a dtype

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 44 Column: 1

              from . import numerictypes as nt
from numpy.compat import os_fspath
from numpy.core.overrides import set_module
from .arrayprint import get_printoptions

# All of the functions allow formats to be a dtype
__all__ = [
    'record', 'recarray', 'format_parser',
    'fromarrays', 'fromrecords', 'fromstring', 'fromfile', 'array',

            

Reported by Pylint.

Redefining built-in 'list'
Error

Line: 78 Column: 20

              numfmt = nt.sctypeDict


def find_duplicate(list):
    """Find duplication in a list, return a list of duplicated elements"""
    return [
        item
        for item, counts in Counter(list).items()
        if counts > 1

            

Reported by Pylint.

Unused argument 'obj'
Error

Line: 435 Column: 34

                                                    strides=strides, order=order)
        return self

    def __array_finalize__(self, obj):
        if self.dtype.type is not record and self.dtype.names is not None:
            # if self.dtype is not np.record, invoke __setattr__ which will
            # convert it to a record if it is a void dtype.
            self.dtype = self.dtype


            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 485 Column: 16

                      newattr = attr not in self.__dict__
        try:
            ret = object.__setattr__(self, attr, val)
        except Exception:
            fielddict = ndarray.__getattribute__(self, 'dtype').fields or {}
            if attr not in fielddict:
                raise
        else:
            fielddict = ndarray.__getattribute__(self, 'dtype').fields or {}

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 498 Column: 24

                              # internal attribute.
                try:
                    object.__delattr__(self, attr)
                except Exception:
                    return ret
        try:
            res = fielddict[attr][:2]
        except (TypeError, KeyError) as e:
            raise AttributeError(

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 745 Column: 13

                      if isinstance(shape, int):
            shape = (shape,)
        if len(shape) > 1:
            raise ValueError("Can only deal with 1-d array.")
        _array = recarray(shape, descr)
        for k in range(_array.size):
            _array[k] = tuple(recList[k])
        # list of lists instead of list of tuples ?
        # 2018-02-07, 1.14.1

            

Reported by Pylint.

Too many lines in module (1091/1000)
Error

Line: 1 Column: 1

              """
Record Arrays
=============
Record arrays expose the fields of structured arrays as properties.

Most commonly, ndarrays contain elements of a single type, e.g. floats,
integers, bools etc.  However, it is possible for elements to be combinations
of these using structured types, such as::


            

Reported by Pylint.

third party import "from numpy.compat import os_fspath" should be placed before "from . import numeric as sb"
Error

Line: 42 Column: 1

              
from . import numeric as sb
from . import numerictypes as nt
from numpy.compat import os_fspath
from numpy.core.overrides import set_module
from .arrayprint import get_printoptions

# All of the functions allow formats to be a dtype
__all__ = [

            

Reported by Pylint.

numpy/distutils/mingw32ccompiler.py
56 issues
Undefined variable 'CalledProcessError'
Error

Line: 70 Column: 30

                      if self.gcc_version is None:
            try:
                out_string  = subprocess.check_output(['gcc', '-dumpversion'])
            except (OSError, CalledProcessError):
                out_string = ""  # ignore failures to match old behavior
            result = re.search(r'(\d+\.\d+)', out_string)
            if result:
                self.gcc_version = StrictVersion(result.group(1))


            

Reported by Pylint.

Module 'sys' has no 'real_prefix' member
Error

Line: 253 Column: 42

                  stems = [sys.prefix]
    if hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix:
        stems.append(sys.base_prefix)
    elif hasattr(sys, 'real_prefix') and sys.real_prefix != sys.prefix:
        stems.append(sys.real_prefix)

    sub_dirs = ['', 'lib', 'bin']
    # generate possible combinations of directory trees and sub-directories
    lib_dirs = []

            

Reported by Pylint.

Module 'sys' has no 'real_prefix' member
Error

Line: 254 Column: 22

                  if hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix:
        stems.append(sys.base_prefix)
    elif hasattr(sys, 'real_prefix') and sys.real_prefix != sys.prefix:
        stems.append(sys.real_prefix)

    sub_dirs = ['', 'lib', 'bin']
    # generate possible combinations of directory trees and sub-directories
    lib_dirs = []
    for stem in stems:

            

Reported by Pylint.

Module 'sys' has no 'real_prefix' member
Error

Line: 430 Column: 42

                  stems = [sys.prefix]
    if hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix:
        stems.append(sys.base_prefix)
    elif hasattr(sys, 'real_prefix') and sys.real_prefix != sys.prefix:
        stems.append(sys.real_prefix)

    # possible subdirectories within those trees where it is placed
    sub_dirs = ['libs', 'lib']


            

Reported by Pylint.

Module 'sys' has no 'real_prefix' member
Error

Line: 431 Column: 22

                  if hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix:
        stems.append(sys.base_prefix)
    elif hasattr(sys, 'real_prefix') and sys.real_prefix != sys.prefix:
        stems.append(sys.real_prefix)

    # possible subdirectories within those trees where it is placed
    sub_dirs = ['libs', 'lib']

    # generate a list of candidate locations

            

Reported by Pylint.

Module 'sys' has no 'real_prefix' member
Error

Line: 490 Column: 37

                      if hasattr(sys, 'base_prefix'):
            base_lib = os.path.join(sys.base_prefix, 'libs', lib_name)
        elif hasattr(sys, 'real_prefix'):
            base_lib = os.path.join(sys.real_prefix, 'libs', lib_name)
        else:
            base_lib = ''  # os.path.isfile('') == False

        if os.path.isfile(base_lib):
            lib_file = base_lib

            

Reported by Pylint.

Unused import numpy.distutils.ccompiler
Error

Line: 18 Column: 1

              import textwrap

# Overwrite certain distutils.ccompiler functions:
import numpy.distutils.ccompiler  # noqa: F401
from numpy.distutils import log
# NT stuff
# 1. Make sure libpython<version>.a exists for gcc.  If not, build it.
# 2. Force windows to use gcc (we're struggling with MSVC and g77 support)
#    --> this is done in numpy/distutils/ccompiler.py

            

Reported by Pylint.

Signature differs from overridden 'link' method
Error

Line: 166 Column: 5

              
    # __init__ ()

    def link(self,
             target_desc,
             objects,
             output_filename,
             output_dir,
             libraries,

            

Reported by Pylint.

Unused variable 'dirs'
Error

Line: 331 Column: 19

                                                 'winsxs')
        if not os.path.exists(winsxs_path):
            return None
        for root, dirs, files in os.walk(winsxs_path):
            if dll_name in files and arch in root:
                return os.path.join(root, dll_name)
        return None

    def _find_dll_in_path(dll_name):

            

Reported by Pylint.

XXX: ideally, we should use exactly the same version as used by python. I
Error

Line: 536 Column: 3

              # directory, but this requires the manifest for this to work. This is a big
# mess, thanks MS for a wonderful system.

# XXX: ideally, we should use exactly the same version as used by python. I
# submitted a patch to get this version, but it was only included for python
# 2.6.1 and above. So for versions below, we use a "best guess".
_MSVCRVER_TO_FULLVER = {}
if sys.platform == 'win32':
    try:

            

Reported by Pylint.

numpy/typing/tests/data/reveal/getlimits.py
56 issues
Value 'np.core.getlimits.MachArLike' is unsubscriptable
Error

Line: 14 Column: 12

              
finfo_f8: np.finfo[np.float64]
iinfo_i8: np.iinfo[np.int64]
machar_f4: np.core.getlimits.MachArLike[_32Bit]

reveal_type(np.finfo(f))  # E: numpy.finfo[{double}]
reveal_type(np.finfo(f8))  # E: numpy.finfo[{float64}]
reveal_type(np.finfo(c8))  # E: numpy.finfo[{float32}]
reveal_type(np.finfo('f2'))  # E: numpy.finfo[numpy.floating[Any]]

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 16 Column: 1

              iinfo_i8: np.iinfo[np.int64]
machar_f4: np.core.getlimits.MachArLike[_32Bit]

reveal_type(np.finfo(f))  # E: numpy.finfo[{double}]
reveal_type(np.finfo(f8))  # E: numpy.finfo[{float64}]
reveal_type(np.finfo(c8))  # E: numpy.finfo[{float32}]
reveal_type(np.finfo('f2'))  # E: numpy.finfo[numpy.floating[Any]]

reveal_type(finfo_f8.dtype)  # E: numpy.dtype[{float64}]

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 17 Column: 1

              machar_f4: np.core.getlimits.MachArLike[_32Bit]

reveal_type(np.finfo(f))  # E: numpy.finfo[{double}]
reveal_type(np.finfo(f8))  # E: numpy.finfo[{float64}]
reveal_type(np.finfo(c8))  # E: numpy.finfo[{float32}]
reveal_type(np.finfo('f2'))  # E: numpy.finfo[numpy.floating[Any]]

reveal_type(finfo_f8.dtype)  # E: numpy.dtype[{float64}]
reveal_type(finfo_f8.bits)  # E: int

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 18 Column: 1

              
reveal_type(np.finfo(f))  # E: numpy.finfo[{double}]
reveal_type(np.finfo(f8))  # E: numpy.finfo[{float64}]
reveal_type(np.finfo(c8))  # E: numpy.finfo[{float32}]
reveal_type(np.finfo('f2'))  # E: numpy.finfo[numpy.floating[Any]]

reveal_type(finfo_f8.dtype)  # E: numpy.dtype[{float64}]
reveal_type(finfo_f8.bits)  # E: int
reveal_type(finfo_f8.eps)  # E: {float64}

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 19 Column: 1

              reveal_type(np.finfo(f))  # E: numpy.finfo[{double}]
reveal_type(np.finfo(f8))  # E: numpy.finfo[{float64}]
reveal_type(np.finfo(c8))  # E: numpy.finfo[{float32}]
reveal_type(np.finfo('f2'))  # E: numpy.finfo[numpy.floating[Any]]

reveal_type(finfo_f8.dtype)  # E: numpy.dtype[{float64}]
reveal_type(finfo_f8.bits)  # E: int
reveal_type(finfo_f8.eps)  # E: {float64}
reveal_type(finfo_f8.epsneg)  # E: {float64}

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 21 Column: 1

              reveal_type(np.finfo(c8))  # E: numpy.finfo[{float32}]
reveal_type(np.finfo('f2'))  # E: numpy.finfo[numpy.floating[Any]]

reveal_type(finfo_f8.dtype)  # E: numpy.dtype[{float64}]
reveal_type(finfo_f8.bits)  # E: int
reveal_type(finfo_f8.eps)  # E: {float64}
reveal_type(finfo_f8.epsneg)  # E: {float64}
reveal_type(finfo_f8.iexp)  # E: int
reveal_type(finfo_f8.machep)  # E: int

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 22 Column: 1

              reveal_type(np.finfo('f2'))  # E: numpy.finfo[numpy.floating[Any]]

reveal_type(finfo_f8.dtype)  # E: numpy.dtype[{float64}]
reveal_type(finfo_f8.bits)  # E: int
reveal_type(finfo_f8.eps)  # E: {float64}
reveal_type(finfo_f8.epsneg)  # E: {float64}
reveal_type(finfo_f8.iexp)  # E: int
reveal_type(finfo_f8.machep)  # E: int
reveal_type(finfo_f8.max)  # E: {float64}

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 23 Column: 1

              
reveal_type(finfo_f8.dtype)  # E: numpy.dtype[{float64}]
reveal_type(finfo_f8.bits)  # E: int
reveal_type(finfo_f8.eps)  # E: {float64}
reveal_type(finfo_f8.epsneg)  # E: {float64}
reveal_type(finfo_f8.iexp)  # E: int
reveal_type(finfo_f8.machep)  # E: int
reveal_type(finfo_f8.max)  # E: {float64}
reveal_type(finfo_f8.maxexp)  # E: int

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 24 Column: 1

              reveal_type(finfo_f8.dtype)  # E: numpy.dtype[{float64}]
reveal_type(finfo_f8.bits)  # E: int
reveal_type(finfo_f8.eps)  # E: {float64}
reveal_type(finfo_f8.epsneg)  # E: {float64}
reveal_type(finfo_f8.iexp)  # E: int
reveal_type(finfo_f8.machep)  # E: int
reveal_type(finfo_f8.max)  # E: {float64}
reveal_type(finfo_f8.maxexp)  # E: int
reveal_type(finfo_f8.min)  # E: {float64}

            

Reported by Pylint.

Undefined variable 'reveal_type'
Error

Line: 25 Column: 1

              reveal_type(finfo_f8.bits)  # E: int
reveal_type(finfo_f8.eps)  # E: {float64}
reveal_type(finfo_f8.epsneg)  # E: {float64}
reveal_type(finfo_f8.iexp)  # E: int
reveal_type(finfo_f8.machep)  # E: int
reveal_type(finfo_f8.max)  # E: {float64}
reveal_type(finfo_f8.maxexp)  # E: int
reveal_type(finfo_f8.min)  # E: {float64}
reveal_type(finfo_f8.minexp)  # E: int

            

Reported by Pylint.