The following issues were found

pandas/tests/arrays/integer/test_concat.py
6 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

import pandas as pd
import pandas._testing as tm


@pytest.mark.parametrize(
    "to_concat_dtypes, result_dtype",

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

import pandas as pd
import pandas._testing as tm


@pytest.mark.parametrize(
    "to_concat_dtypes, result_dtype",

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 1

                      (["Int64", "UInt64"], "Float64"),
        (["Int64", "boolean"], "Int64"),
        (["UInt8", "boolean"], "UInt8"),
    ],
)
def test_concat_series(to_concat_dtypes, result_dtype):

    result = pd.concat([pd.Series([0, 1, pd.NA], dtype=t) for t in to_concat_dtypes])
    expected = pd.concat([pd.Series([0, 1, pd.NA], dtype=object)] * 2).astype(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 52 Column: 1

                      (["Int64", "uint64"], "Float64"),
        (["Int64", "bool"], "Int64"),
        (["UInt8", "bool"], "UInt8"),
    ],
)
def test_concat_series_with_numpy(to_concat_dtypes, result_dtype):

    s1 = pd.Series([0, 1, pd.NA], dtype=to_concat_dtypes[0])
    s2 = pd.Series(np.array([0, 1], dtype=to_concat_dtypes[1]))

            

Reported by Pylint.

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

Line: 56 Column: 5

              )
def test_concat_series_with_numpy(to_concat_dtypes, result_dtype):

    s1 = pd.Series([0, 1, pd.NA], dtype=to_concat_dtypes[0])
    s2 = pd.Series(np.array([0, 1], dtype=to_concat_dtypes[1]))
    result = pd.concat([s1, s2], ignore_index=True)
    expected = pd.Series([0, 1, pd.NA, 0, 1], dtype=object).astype(result_dtype)
    tm.assert_series_equal(result, expected)


            

Reported by Pylint.

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

Line: 57 Column: 5

              def test_concat_series_with_numpy(to_concat_dtypes, result_dtype):

    s1 = pd.Series([0, 1, pd.NA], dtype=to_concat_dtypes[0])
    s2 = pd.Series(np.array([0, 1], dtype=to_concat_dtypes[1]))
    result = pd.concat([s1, s2], ignore_index=True)
    expected = pd.Series([0, 1, pd.NA, 0, 1], dtype=object).astype(result_dtype)
    tm.assert_series_equal(result, expected)

    # order doesn't matter for result

            

Reported by Pylint.

pandas/_typing.py
6 issues
Module 'numpy.random' has no 'RandomState' member
Error

Line: 119 Column: 5

                  ArrayLike,
    np.random.Generator,
    np.random.BitGenerator,
    np.random.RandomState,
]

# dtypes
NpDtype = Union[str, np.dtype]
Dtype = Union[

            

Reported by Pylint.

Unused PathLike imported from os
Error

Line: 13 Column: 1

                  TextIOWrapper,
)
from mmap import mmap
from os import PathLike
from typing import (
    IO,
    TYPE_CHECKING,
    Any,
    AnyStr,

            

Reported by Pylint.

TODO: add Ellipsis, see
Error

Line: 204 Column: 3

              # indexing
# PositionalIndexer -> valid 1D positional indexer, e.g. can pass
# to ndarray.__getitem__
# TODO: add Ellipsis, see
# https://github.com/python/typing/issues/684#issuecomment-548203158
# https://bugs.python.org/issue41810
PositionalIndexer = Union[int, np.integer, slice, Sequence[int], np.ndarray]
PositionalIndexer2D = Union[
    PositionalIndexer, Tuple[PositionalIndexer, PositionalIndexer]

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from datetime import (
    datetime,
    timedelta,
    tzinfo,
)
from io import (
    BufferedIOBase,
    RawIOBase,
    TextIOBase,

            

Reported by Pylint.

Class name "T" doesn't conform to PascalCase naming style
Error

Line: 135 Column: 1

              Renamer = Union[Mapping[Hashable, Any], Callable[[Hashable], Hashable]]

# to maintain type information across generic functions and parametrization
T = TypeVar("T")

# used in decorators to preserve the signature of the function it decorates
# see https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators
FuncType = Callable[..., Any]
F = TypeVar("F", bound=FuncType)

            

Reported by Pylint.

Class name "F" doesn't conform to PascalCase naming style
Error

Line: 140 Column: 1

              # used in decorators to preserve the signature of the function it decorates
# see https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators
FuncType = Callable[..., Any]
F = TypeVar("F", bound=FuncType)

# types of vectorized key functions for DataFrame::sort_values and
# DataFrame::sort_index, among others
ValueKeyFunc = Optional[Callable[["Series"], Union["Series", AnyArrayLike]]]
IndexKeyFunc = Optional[Callable[["Index"], Union["Index", AnyArrayLike]]]

            

Reported by Pylint.

pandas/_testing/_warnings.py
6 issues
Unused variable '__tracebackhide__'
Error

Line: 77 Column: 5

              
    ..warn:: This is *not* thread-safe.
    """
    __tracebackhide__ = True

    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter(filter_level)
        yield w


            

Reported by Pylint.

FIXME: kludge because pytest.filterwarnings does not
Error

Line: 154 Column: 3

                          if actual_warning.category == ResourceWarning and unclosed in str(
                actual_warning.message
            ):
                # FIXME: kludge because pytest.filterwarnings does not
                #  suppress these, xref GH#38630
                continue

            extra_warnings.append(
                (

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from __future__ import annotations

from contextlib import contextmanager
import re
from typing import (
    Sequence,
    Type,
    cast,
)

            

Reported by Pylint.

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

Line: 79 Column: 50

                  """
    __tracebackhide__ = True

    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter(filter_level)
        yield w

        if expected_warning:
            expected_warning = cast(Type[Warning], expected_warning)

            

Reported by Pylint.

Import outside toplevel (inspect.getframeinfo, inspect.stack)
Error

Line: 185 Column: 5

              def _assert_raised_with_correct_stacklevel(
    actual_warning: warnings.WarningMessage,
) -> None:
    from inspect import (
        getframeinfo,
        stack,
    )

    caller = getframeinfo(stack()[4][0])

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 196
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      f"File where warning is raised: {actual_warning.filename} != "
        f"{caller.filename}. Warning message: {actual_warning.message}"
    )
    assert actual_warning.filename == caller.filename, msg

            

Reported by Bandit.

pandas/tests/dtypes/cast/test_infer_datetimelike.py
6 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

from pandas import (
    DataFrame,
    NaT,
    Series,
    Timestamp,
)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

from pandas import (
    DataFrame,
    NaT,
    Series,
    Timestamp,
)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 18 Column: 1

                      # see gh-16362.
        ([[NaT, "a", "b", 0], [NaT, "b", "c", 1]], 8),
        ([[NaT, "a", 0], [NaT, "b", 1]], 6),
    ],
)
def test_maybe_infer_to_datetimelike_df_construct(data, exp_size):
    result = DataFrame(np.array(data))
    assert result.size == exp_size


            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 22
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              )
def test_maybe_infer_to_datetimelike_df_construct(data, exp_size):
    result = DataFrame(np.array(data))
    assert result.size == exp_size


def test_maybe_infer_to_datetimelike_ser_construct():
    # see gh-19671.
    result = Series(["M1701", Timestamp("20130101")])

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 25 Column: 1

                  assert result.size == exp_size


def test_maybe_infer_to_datetimelike_ser_construct():
    # see gh-19671.
    result = Series(["M1701", Timestamp("20130101")])
    assert result.dtype.kind == "O"

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 28
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def test_maybe_infer_to_datetimelike_ser_construct():
    # see gh-19671.
    result = Series(["M1701", Timestamp("20130101")])
    assert result.dtype.kind == "O"

            

Reported by Bandit.

pandas/tests/extension/base/base.py
6 issues
Missing module docstring
Error

Line: 1 Column: 1

              import pandas._testing as tm


class BaseExtensionTests:
    # classmethod and different signature is needed
    # to make inheritance compliant with mypy
    @classmethod
    def assert_equal(cls, left, right, **kwargs):
        return tm.assert_equal(left, right, **kwargs)

            

Reported by Pylint.

Missing class docstring
Error

Line: 4 Column: 1

              import pandas._testing as tm


class BaseExtensionTests:
    # classmethod and different signature is needed
    # to make inheritance compliant with mypy
    @classmethod
    def assert_equal(cls, left, right, **kwargs):
        return tm.assert_equal(left, right, **kwargs)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 5

                  # classmethod and different signature is needed
    # to make inheritance compliant with mypy
    @classmethod
    def assert_equal(cls, left, right, **kwargs):
        return tm.assert_equal(left, right, **kwargs)

    @classmethod
    def assert_series_equal(cls, left, right, *args, **kwargs):
        return tm.assert_series_equal(left, right, *args, **kwargs)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 5

                      return tm.assert_equal(left, right, **kwargs)

    @classmethod
    def assert_series_equal(cls, left, right, *args, **kwargs):
        return tm.assert_series_equal(left, right, *args, **kwargs)

    @classmethod
    def assert_frame_equal(cls, left, right, *args, **kwargs):
        return tm.assert_frame_equal(left, right, *args, **kwargs)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 5

                      return tm.assert_series_equal(left, right, *args, **kwargs)

    @classmethod
    def assert_frame_equal(cls, left, right, *args, **kwargs):
        return tm.assert_frame_equal(left, right, *args, **kwargs)

    @classmethod
    def assert_extension_array_equal(cls, left, right, *args, **kwargs):
        return tm.assert_extension_array_equal(left, right, *args, **kwargs)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 5

                      return tm.assert_frame_equal(left, right, *args, **kwargs)

    @classmethod
    def assert_extension_array_equal(cls, left, right, *args, **kwargs):
        return tm.assert_extension_array_equal(left, right, *args, **kwargs)

            

Reported by Pylint.

pandas/tests/frame/methods/test_sample.py
6 issues
Use of possibly insecure function - consider using safer ast.literal_eval.
Security blacklist

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

                      obj = DataFrame({"col1": range(10, 20), "col2": range(20, 30)})
        if frame_or_series is Series:
            obj = obj["col1"]
        result = obj.sample(n=3, random_state=eval(func_str)(arg))
        expected = obj.sample(n=3, random_state=com.random_state(eval(func_str)(arg)))
        tm.assert_equal(result, expected)

    def test_sample_generator(self, frame_or_series):
        # GH#38100

            

Reported by Bandit.

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

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

                      if frame_or_series is Series:
            obj = obj["col1"]
        result = obj.sample(n=3, random_state=eval(func_str)(arg))
        expected = obj.sample(n=3, random_state=com.random_state(eval(func_str)(arg)))
        tm.assert_equal(result, expected)

    def test_sample_generator(self, frame_or_series):
        # GH#38100
        obj = frame_or_series(np.arange(100))

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 65
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
    def test_sample_lengths(self, obj):
        # Check lengths are right
        assert len(obj.sample(n=4) == 4)
        assert len(obj.sample(frac=0.34) == 3)
        assert len(obj.sample(frac=0.36) == 4)

    def test_sample_invalid_random_state(self, obj):
        # Check for error when random_state argument invalid.

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 66
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  def test_sample_lengths(self, obj):
        # Check lengths are right
        assert len(obj.sample(n=4) == 4)
        assert len(obj.sample(frac=0.34) == 3)
        assert len(obj.sample(frac=0.36) == 4)

    def test_sample_invalid_random_state(self, obj):
        # Check for error when random_state argument invalid.
        msg = (

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 67
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      # Check lengths are right
        assert len(obj.sample(n=4) == 4)
        assert len(obj.sample(frac=0.34) == 3)
        assert len(obj.sample(frac=0.36) == 4)

    def test_sample_invalid_random_state(self, obj):
        # Check for error when random_state argument invalid.
        msg = (
            "random_state must be an integer, array-like, a BitGenerator, Generator, "

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 183
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      # Consecutive calls should advance the seed
        result1 = obj.sample(n=50, random_state=rng)
        result2 = obj.sample(n=50, random_state=rng)
        assert not (result1.index.values == result2.index.values).all()

        # Matching generator initialization must give same result
        # Consecutive calls should advance the seed
        result1 = obj.sample(n=50, random_state=np.random.default_rng(11))
        result2 = obj.sample(n=50, random_state=np.random.default_rng(11))

            

Reported by Bandit.

pandas/tests/indexes/datetimes/methods/test_to_frame.py
5 issues
Missing module docstring
Error

Line: 1 Column: 1

              from pandas import (
    DataFrame,
    date_range,
)
import pandas._testing as tm


class TestToFrame:
    def test_to_frame_datetime_tz(self):

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 8 Column: 1

              import pandas._testing as tm


class TestToFrame:
    def test_to_frame_datetime_tz(self):
        # GH#25809
        idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
        result = idx.to_frame()
        expected = DataFrame(idx, index=idx)

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              import pandas._testing as tm


class TestToFrame:
    def test_to_frame_datetime_tz(self):
        # GH#25809
        idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
        result = idx.to_frame()
        expected = DataFrame(idx, index=idx)

            

Reported by Pylint.

Method could be a function
Error

Line: 9 Column: 5

              

class TestToFrame:
    def test_to_frame_datetime_tz(self):
        # GH#25809
        idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
        result = idx.to_frame()
        expected = DataFrame(idx, index=idx)
        tm.assert_frame_equal(result, expected)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 5

              

class TestToFrame:
    def test_to_frame_datetime_tz(self):
        # GH#25809
        idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
        result = idx.to_frame()
        expected = DataFrame(idx, index=idx)
        tm.assert_frame_equal(result, expected)

            

Reported by Pylint.

pandas/compat/_optional.py
5 issues
Missing module docstring
Error

Line: 1 Column: 1

              from __future__ import annotations

import importlib
import sys
import types
import warnings

from pandas.util.version import Version


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 53 Column: 1

              }


def get_version(module: types.ModuleType) -> str:
    version = getattr(module, "__version__", None)
    if version is None:
        # xlrd uses a capitalized attribute name
        version = getattr(module, "__VERSION__", None)


            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 105
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                      is ``'warn'``.
    """

    assert errors in {"warn", "raise", "ignore"}

    package_name = INSTALL_MAPPING.get(name)
    install_name = package_name if package_name is not None else name

    msg = (

            

Reported by Bandit.

Unnecessary "else" after "raise"
Error

Line: 117 Column: 9

                  try:
        module = importlib.import_module(name)
    except ImportError:
        if errors == "raise":
            raise ImportError(msg) from None
        else:
            return None

    # Handle submodules: if we have submodule, grab parent module from sys.modules

            

Reported by Pylint.

Unnecessary "elif" after "return"
Error

Line: 137 Column: 13

                              f"Pandas requires version '{minimum_version}' or newer of '{parent}' "
                f"(version '{version}' currently installed)."
            )
            if errors == "warn":
                warnings.warn(msg, UserWarning)
                return None
            elif errors == "raise":
                raise ImportError(msg)


            

Reported by Pylint.

pandas/tests/frame/methods/test_is_homogeneous_dtype.py
5 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas import (
    Categorical,
    DataFrame,
)

            

Reported by Pylint.

Access to a protected member _is_homogeneous_type of a client class
Error

Line: 57 Column: 12

                  ],
)
def test_is_homogeneous_type(data, expected):
    assert data._is_homogeneous_type is expected

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas import (
    Categorical,
    DataFrame,
)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 53 Column: 1

                      (
            DataFrame({"A": Categorical(["a", "b"]), "B": Categorical(["b", "c"])}),
            False,
        ),
    ],
)
def test_is_homogeneous_type(data, expected):
    assert data._is_homogeneous_type is expected

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 57
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  ],
)
def test_is_homogeneous_type(data, expected):
    assert data._is_homogeneous_type is expected

            

Reported by Bandit.

pandas/tests/dtypes/cast/test_dict_compat.py
5 issues
Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np

from pandas.core.dtypes.cast import dict_compat

from pandas import Timestamp


def test_dict_compat():
    data_datetime64 = {np.datetime64("1990-03-15"): 1, np.datetime64("2015-03-15"): 2}

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              from pandas import Timestamp


def test_dict_compat():
    data_datetime64 = {np.datetime64("1990-03-15"): 1, np.datetime64("2015-03-15"): 2}
    data_unchanged = {1: 2, 3: 4, 5: 6}
    expected = {Timestamp("1990-3-15"): 1, Timestamp("2015-03-15"): 2}
    assert dict_compat(data_datetime64) == expected
    assert dict_compat(expected) == expected

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 12
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  data_datetime64 = {np.datetime64("1990-03-15"): 1, np.datetime64("2015-03-15"): 2}
    data_unchanged = {1: 2, 3: 4, 5: 6}
    expected = {Timestamp("1990-3-15"): 1, Timestamp("2015-03-15"): 2}
    assert dict_compat(data_datetime64) == expected
    assert dict_compat(expected) == expected
    assert dict_compat(data_unchanged) == data_unchanged

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 13
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  data_unchanged = {1: 2, 3: 4, 5: 6}
    expected = {Timestamp("1990-3-15"): 1, Timestamp("2015-03-15"): 2}
    assert dict_compat(data_datetime64) == expected
    assert dict_compat(expected) == expected
    assert dict_compat(data_unchanged) == data_unchanged

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 14
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  expected = {Timestamp("1990-3-15"): 1, Timestamp("2015-03-15"): 2}
    assert dict_compat(data_datetime64) == expected
    assert dict_compat(expected) == expected
    assert dict_compat(data_unchanged) == data_unchanged

            

Reported by Bandit.