The following issues were found

pandas/tests/groupby/test_size.py
16 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

from pandas import (
    DataFrame,
    Index,
    PeriodIndex,
    Series,
)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

from pandas import (
    DataFrame,
    Index,
    PeriodIndex,
    Series,
)

            

Reported by Pylint.

Argument name "by" doesn't conform to snake_case naming style
Error

Line: 14 Column: 1

              

@pytest.mark.parametrize("by", ["A", "B", ["A", "B"]])
def test_size(df, by):
    grouped = df.groupby(by=by)
    result = grouped.size()
    for key, group in grouped:
        assert result[key] == len(group)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 14 Column: 1

              

@pytest.mark.parametrize("by", ["A", "B", ["A", "B"]])
def test_size(df, by):
    grouped = df.groupby(by=by)
    result = grouped.size()
    for key, group in grouped:
        assert result[key] == len(group)


            

Reported by Pylint.

Argument name "df" doesn't conform to snake_case naming style
Error

Line: 14 Column: 1

              

@pytest.mark.parametrize("by", ["A", "B", ["A", "B"]])
def test_size(df, by):
    grouped = df.groupby(by=by)
    result = grouped.size()
    for key, group in grouped:
        assert result[key] == len(group)


            

Reported by Pylint.

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

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

                  grouped = df.groupby(by=by)
    result = grouped.size()
    for key, group in grouped:
        assert result[key] == len(group)


@pytest.mark.parametrize("by", ["A", "B", ["A", "B"]])
@pytest.mark.parametrize("sort", [True, False])
def test_size_sort(df, sort, by):

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 23 Column: 1

              
@pytest.mark.parametrize("by", ["A", "B", ["A", "B"]])
@pytest.mark.parametrize("sort", [True, False])
def test_size_sort(df, sort, by):
    df = DataFrame(np.random.choice(20, (1000, 3)), columns=list("ABC"))
    left = df.groupby(by=by, sort=sort).size()
    right = df.groupby(by=by, sort=sort)["C"].apply(lambda a: a.shape[0])
    tm.assert_series_equal(left, right, check_names=False)


            

Reported by Pylint.

Argument name "df" doesn't conform to snake_case naming style
Error

Line: 23 Column: 1

              
@pytest.mark.parametrize("by", ["A", "B", ["A", "B"]])
@pytest.mark.parametrize("sort", [True, False])
def test_size_sort(df, sort, by):
    df = DataFrame(np.random.choice(20, (1000, 3)), columns=list("ABC"))
    left = df.groupby(by=by, sort=sort).size()
    right = df.groupby(by=by, sort=sort)["C"].apply(lambda a: a.shape[0])
    tm.assert_series_equal(left, right, check_names=False)


            

Reported by Pylint.

Argument name "by" doesn't conform to snake_case naming style
Error

Line: 23 Column: 1

              
@pytest.mark.parametrize("by", ["A", "B", ["A", "B"]])
@pytest.mark.parametrize("sort", [True, False])
def test_size_sort(df, sort, by):
    df = DataFrame(np.random.choice(20, (1000, 3)), columns=list("ABC"))
    left = df.groupby(by=by, sort=sort).size()
    right = df.groupby(by=by, sort=sort)["C"].apply(lambda a: a.shape[0])
    tm.assert_series_equal(left, right, check_names=False)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 30 Column: 1

                  tm.assert_series_equal(left, right, check_names=False)


def test_size_series_dataframe():
    # https://github.com/pandas-dev/pandas/issues/11699
    df = DataFrame(columns=["A", "B"])
    out = Series(dtype="int64", index=Index([], name="A"))
    tm.assert_series_equal(df.groupby("A").size(), out)


            

Reported by Pylint.

pandas/tests/frame/methods/test_count.py
15 issues
Access to a protected member _series of a client class
Error

Line: 35 Column: 24

                      tm.assert_series_equal(result, expected)

    def test_count_objects(self, float_string_frame):
        dm = DataFrame(float_string_frame._series)
        df = DataFrame(float_string_frame._series)

        tm.assert_series_equal(dm.count(), df.count())
        tm.assert_series_equal(dm.count(1), df.count(1))

            

Reported by Pylint.

Access to a protected member _series of a client class
Error

Line: 36 Column: 24

              
    def test_count_objects(self, float_string_frame):
        dm = DataFrame(float_string_frame._series)
        df = DataFrame(float_string_frame._series)

        tm.assert_series_equal(dm.count(), df.count())
        tm.assert_series_equal(dm.count(1), df.count(1))

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

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


class TestDataFrameCount:
    def test_count(self):

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              import pandas._testing as tm


class TestDataFrameCount:
    def test_count(self):
        # corner case
        frame = DataFrame()
        ct1 = frame.count(1)
        assert isinstance(ct1, Series)

            

Reported by Pylint.

Method could be a function
Error

Line: 9 Column: 5

              

class TestDataFrameCount:
    def test_count(self):
        # corner case
        frame = DataFrame()
        ct1 = frame.count(1)
        assert isinstance(ct1, Series)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 9 Column: 5

              

class TestDataFrameCount:
    def test_count(self):
        # corner case
        frame = DataFrame()
        ct1 = frame.count(1)
        assert isinstance(ct1, Series)


            

Reported by Pylint.

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

                      # corner case
        frame = DataFrame()
        ct1 = frame.count(1)
        assert isinstance(ct1, Series)

        ct2 = frame.count(0)
        assert isinstance(ct2, Series)

        # GH#423

            

Reported by Bandit.

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

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

                      assert isinstance(ct1, Series)

        ct2 = frame.count(0)
        assert isinstance(ct2, Series)

        # GH#423
        df = DataFrame(index=range(10))
        result = df.count(1)
        expected = Series(0, index=df.index)

            

Reported by Bandit.

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

Line: 19 Column: 9

                      assert isinstance(ct2, Series)

        # GH#423
        df = DataFrame(index=range(10))
        result = df.count(1)
        expected = Series(0, index=df.index)
        tm.assert_series_equal(result, expected)

        df = DataFrame(columns=range(10))

            

Reported by Pylint.

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

Line: 24 Column: 9

                      expected = Series(0, index=df.index)
        tm.assert_series_equal(result, expected)

        df = DataFrame(columns=range(10))
        result = df.count(0)
        expected = Series(0, index=df.columns)
        tm.assert_series_equal(result, expected)

        df = DataFrame()

            

Reported by Pylint.

pandas/tests/frame/methods/test_count_with_level_deprecated.py
15 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

from pandas import (
    DataFrame,
    Index,
    Series,
)
import pandas._testing as tm

            

Reported by Pylint.

Access to a protected member _get_axis of a client class
Error

Line: 96 Column: 21

                      frame = multiindex_dataframe_random_data

        def _check_counts(frame, axis=0):
            index = frame._get_axis(axis)
            for i in range(index.nlevels):
                with tm.assert_produces_warning(FutureWarning):
                    result = frame.count(axis=axis, level=i)
                expected = frame.groupby(axis=axis, level=i).count()
                expected = expected.reindex_like(result).astype("i8")

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

from pandas import (
    DataFrame,
    Index,
    Series,
)
import pandas._testing as tm

            

Reported by Pylint.

Missing class docstring
Error

Line: 12 Column: 1

              import pandas._testing as tm


class TestDataFrameCount:
    def test_count_multiindex(self, multiindex_dataframe_random_data):
        frame = multiindex_dataframe_random_data

        frame = frame.copy()
        frame.index.names = ["a", "b"]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 5

              

class TestDataFrameCount:
    def test_count_multiindex(self, multiindex_dataframe_random_data):
        frame = multiindex_dataframe_random_data

        frame = frame.copy()
        frame.index.names = ["a", "b"]


            

Reported by Pylint.

Method could be a function
Error

Line: 13 Column: 5

              

class TestDataFrameCount:
    def test_count_multiindex(self, multiindex_dataframe_random_data):
        frame = multiindex_dataframe_random_data

        frame = frame.copy()
        frame.index.names = ["a", "b"]


            

Reported by Pylint.

Method could be a function
Error

Line: 36 Column: 5

                          with tm.assert_produces_warning(FutureWarning):
                frame.count(level="x")

    def test_count_level_corner(self, multiindex_dataframe_random_data):
        frame = multiindex_dataframe_random_data

        ser = frame["A"][:0]
        with tm.assert_produces_warning(FutureWarning):
            result = ser.count(level=0)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 36 Column: 5

                          with tm.assert_produces_warning(FutureWarning):
                frame.count(level="x")

    def test_count_level_corner(self, multiindex_dataframe_random_data):
        frame = multiindex_dataframe_random_data

        ser = frame["A"][:0]
        with tm.assert_produces_warning(FutureWarning):
            result = ser.count(level=0)

            

Reported by Pylint.

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

Line: 45 Column: 9

                      expected = Series(0, index=ser.index.levels[0], name="A")
        tm.assert_series_equal(result, expected)

        df = frame[:0]
        with tm.assert_produces_warning(FutureWarning):
            result = df.count(level=0)
        expected = (
            DataFrame(
                index=ser.index.levels[0].set_names(["first"]), columns=df.columns

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 57 Column: 5

                      )
        tm.assert_frame_equal(result, expected)

    def test_count_index_with_nan(self):
        # https://github.com/pandas-dev/pandas/issues/21824
        df = DataFrame(
            {
                "Person": ["John", "Myla", None, "John", "Myla"],
                "Age": [24.0, 5, 21.0, 33, 26],

            

Reported by Pylint.

pandas/tests/computation/test_compat.py
15 issues
Unable to import 'pytest'
Error

Line: 1 Column: 1

              import pytest

from pandas.compat._optional import VERSIONS

import pandas as pd
from pandas.core.computation.engines import ENGINES
import pandas.core.computation.expr as expr
from pandas.util.version import Version


            

Reported by Pylint.

Unused variable 'b'
Error

Line: 32 Column: 12

              @pytest.mark.parametrize("parser", expr.PARSERS)
def test_invalid_numexpr_version(engine, parser):
    def testit():
        a, b = 1, 2  # noqa
        res = pd.eval("a + b", engine=engine, parser=parser)
        assert res == 3

    if engine == "numexpr":
        try:

            

Reported by Pylint.

Unused variable 'a'
Error

Line: 32 Column: 9

              @pytest.mark.parametrize("parser", expr.PARSERS)
def test_invalid_numexpr_version(engine, parser):
    def testit():
        a, b = 1, 2  # noqa
        res = pd.eval("a + b", engine=engine, parser=parser)
        assert res == 3

    if engine == "numexpr":
        try:

            

Reported by Pylint.

Unused numexpr imported as ne
Error

Line: 38 Column: 13

              
    if engine == "numexpr":
        try:
            import numexpr as ne  # noqa F401
        except ImportError:
            pytest.skip("no numexpr")
        else:
            testit()
    else:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import pytest

from pandas.compat._optional import VERSIONS

import pandas as pd
from pandas.core.computation.engines import ENGINES
import pandas.core.computation.expr as expr
from pandas.util.version import Version


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 1

              from pandas.util.version import Version


def test_compat():
    # test we have compat with our version of nu

    from pandas.core.computation.check import NUMEXPR_INSTALLED

    try:

            

Reported by Pylint.

Import outside toplevel (pandas.core.computation.check.NUMEXPR_INSTALLED)
Error

Line: 14 Column: 5

              def test_compat():
    # test we have compat with our version of nu

    from pandas.core.computation.check import NUMEXPR_INSTALLED

    try:
        import numexpr as ne

        ver = ne.__version__

            

Reported by Pylint.

Import outside toplevel (numexpr)
Error

Line: 17 Column: 9

                  from pandas.core.computation.check import NUMEXPR_INSTALLED

    try:
        import numexpr as ne

        ver = ne.__version__
        if Version(ver) < Version(VERSIONS["numexpr"]):
            assert not NUMEXPR_INSTALLED
        else:

            

Reported by Pylint.

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

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

              
        ver = ne.__version__
        if Version(ver) < Version(VERSIONS["numexpr"]):
            assert not NUMEXPR_INSTALLED
        else:
            assert NUMEXPR_INSTALLED
    except ImportError:
        pytest.skip("not testing numexpr version compat")


            

Reported by Bandit.

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

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

                      if Version(ver) < Version(VERSIONS["numexpr"]):
            assert not NUMEXPR_INSTALLED
        else:
            assert NUMEXPR_INSTALLED
    except ImportError:
        pytest.skip("not testing numexpr version compat")


@pytest.mark.parametrize("engine", ENGINES)

            

Reported by Bandit.

pandas/tests/extension/test_external_block.py
15 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

from pandas._libs.internals import BlockPlacement
import pandas.util._test_decorators as td

import pandas as pd
from pandas.core.internals import BlockManager
from pandas.core.internals.blocks import ExtensionBlock

            

Reported by Pylint.

Unable to import 'pandas._libs.internals'
Error

Line: 4 Column: 1

              import numpy as np
import pytest

from pandas._libs.internals import BlockPlacement
import pandas.util._test_decorators as td

import pandas as pd
from pandas.core.internals import BlockManager
from pandas.core.internals.blocks import ExtensionBlock

            

Reported by Pylint.

No name 'internals' in module 'pandas._libs'
Error

Line: 4 Column: 1

              import numpy as np
import pytest

from pandas._libs.internals import BlockPlacement
import pandas.util._test_decorators as td

import pandas as pd
from pandas.core.internals import BlockManager
from pandas.core.internals.blocks import ExtensionBlock

            

Reported by Pylint.

Method '_can_hold_na' was expected to be 'method', found it instead as 'property'
Error

Line: 20 Column: 5

              
    # Cannot override final attribute "_can_hold_na"
    @property  # type: ignore[misc]
    def _can_hold_na(self) -> bool:
        return False


@pytest.fixture
def df():

            

Reported by Pylint.

Access to a protected member _mgr of a client class
Error

Line: 27 Column: 14

              @pytest.fixture
def df():
    df1 = pd.DataFrame({"a": [1, 2, 3]})
    blocks = df1._mgr.blocks
    values = np.arange(3, dtype="int64")
    bp = BlockPlacement(slice(1, 2))
    custom_block = CustomBlock(values, placement=bp, ndim=2)
    blocks = blocks + (custom_block,)
    block_manager = BlockManager(blocks, [pd.Index(["a", "b"]), df1.index])

            

Reported by Pylint.

Redefining name 'df' from outer scope (line 25)
Error

Line: 36 Column: 23

                  return pd.DataFrame(block_manager)


def test_concat_axis1(df):
    # GH17954
    df2 = pd.DataFrame({"c": [0.1, 0.2, 0.3]})
    res = pd.concat([df, df2], axis=1)
    assert isinstance(res._mgr.blocks[1], CustomBlock)

            

Reported by Pylint.

Access to a protected member _mgr of a client class
Error

Line: 40 Column: 23

                  # GH17954
    df2 = pd.DataFrame({"c": [0.1, 0.2, 0.3]})
    res = pd.concat([df, df2], axis=1)
    assert isinstance(res._mgr.blocks[1], CustomBlock)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

from pandas._libs.internals import BlockPlacement
import pandas.util._test_decorators as td

import pandas as pd
from pandas.core.internals import BlockManager
from pandas.core.internals.blocks import ExtensionBlock

            

Reported by Pylint.

Missing class docstring
Error

Line: 14 Column: 1

              pytestmark = td.skip_array_manager_invalid_test


class CustomBlock(ExtensionBlock):

    _holder = np.ndarray

    # Cannot override final attribute "_can_hold_na"
    @property  # type: ignore[misc]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 25 Column: 1

              

@pytest.fixture
def df():
    df1 = pd.DataFrame({"a": [1, 2, 3]})
    blocks = df1._mgr.blocks
    values = np.arange(3, dtype="int64")
    bp = BlockPlacement(slice(1, 2))
    custom_block = CustomBlock(values, placement=bp, ndim=2)

            

Reported by Pylint.

pandas/tests/arrays/period/test_constructors.py
15 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

from pandas._libs.tslibs import iNaT
from pandas._libs.tslibs.period import IncompatibleFrequency

import pandas as pd
import pandas._testing as tm
from pandas.core.arrays import (

            

Reported by Pylint.

No name 'period' in module 'pandas._libs.tslibs'
Error

Line: 5 Column: 1

              import pytest

from pandas._libs.tslibs import iNaT
from pandas._libs.tslibs.period import IncompatibleFrequency

import pandas as pd
import pandas._testing as tm
from pandas.core.arrays import (
    PeriodArray,

            

Reported by Pylint.

Unable to import 'pandas._libs.tslibs.period'
Error

Line: 5 Column: 1

              import pytest

from pandas._libs.tslibs import iNaT
from pandas._libs.tslibs.period import IncompatibleFrequency

import pandas as pd
import pandas._testing as tm
from pandas.core.arrays import (
    PeriodArray,

            

Reported by Pylint.

Access to a protected member _from_datetime64 of a client class
Error

Line: 54 Column: 14

              def test_from_datetime64_freq_changes():
    # https://github.com/pandas-dev/pandas/issues/23438
    arr = pd.date_range("2017", periods=3, freq="D")
    result = PeriodArray._from_datetime64(arr, freq="M")
    expected = period_array(["2017-01-01", "2017-01-01", "2017-01-01"], freq="M")
    tm.assert_period_array_equal(result, expected)


@pytest.mark.parametrize(

            

Reported by Pylint.

Access to a protected member _from_sequence of a client class
Error

Line: 95 Column: 9

              
    msg = str(arr[0].ordinal)
    with pytest.raises(TypeError, match=msg):
        PeriodArray._from_sequence(arr.asi8, dtype=arr.dtype)

    with pytest.raises(TypeError, match=msg):
        PeriodArray._from_sequence(list(arr.asi8), dtype=arr.dtype)

            

Reported by Pylint.

Access to a protected member _from_sequence of a client class
Error

Line: 98 Column: 9

                      PeriodArray._from_sequence(arr.asi8, dtype=arr.dtype)

    with pytest.raises(TypeError, match=msg):
        PeriodArray._from_sequence(list(arr.asi8), dtype=arr.dtype)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

from pandas._libs.tslibs import iNaT
from pandas._libs.tslibs.period import IncompatibleFrequency

import pandas as pd
import pandas._testing as tm
from pandas.core.arrays import (

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 1

                      (pd.Series(pd.date_range("2017", periods=3)), None, [17167, 17168, 17169]),
        (pd.date_range("2017", periods=3), None, [17167, 17168, 17169]),
        (pd.period_range("2017", periods=4, freq="Q"), None, [188, 189, 190, 191]),
    ],
)
def test_period_array_ok(data, freq, expected):
    result = period_array(data, freq=freq).asi8
    expected = np.asarray(expected, dtype=np.int64)
    tm.assert_numpy_array_equal(result, expected)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 35 Column: 1

                  tm.assert_numpy_array_equal(result, expected)


def test_period_array_readonly_object():
    # https://github.com/pandas-dev/pandas/issues/25403
    pa = period_array([pd.Period("2019-01-01")])
    arr = np.asarray(pa, dtype="object")
    arr.setflags(write=False)


            

Reported by Pylint.

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

Line: 37 Column: 5

              
def test_period_array_readonly_object():
    # https://github.com/pandas-dev/pandas/issues/25403
    pa = period_array([pd.Period("2019-01-01")])
    arr = np.asarray(pa, dtype="object")
    arr.setflags(write=False)

    result = period_array(arr)
    tm.assert_period_array_equal(result, pa)

            

Reported by Pylint.

pandas/tests/arithmetic/common.py
15 issues
Unable to import 'pytest'
Error

Line: 5 Column: 1

              Assertion helpers for arithmetic tests.
"""
import numpy as np
import pytest

from pandas import (
    DataFrame,
    Index,
    Series,

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 28 Column: 9

                  msg : str or None, default None
    """
    with pytest.raises(TypeError, match=msg):
        left + right
    with pytest.raises(TypeError, match=msg):
        right + left
    with pytest.raises(TypeError, match=msg):
        left - right
    with pytest.raises(TypeError, match=msg):

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 30 Column: 9

                  with pytest.raises(TypeError, match=msg):
        left + right
    with pytest.raises(TypeError, match=msg):
        right + left
    with pytest.raises(TypeError, match=msg):
        left - right
    with pytest.raises(TypeError, match=msg):
        right - left


            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 32 Column: 9

                  with pytest.raises(TypeError, match=msg):
        right + left
    with pytest.raises(TypeError, match=msg):
        left - right
    with pytest.raises(TypeError, match=msg):
        right - left


def get_upcast_box(box, vector):

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 34 Column: 9

                  with pytest.raises(TypeError, match=msg):
        left - right
    with pytest.raises(TypeError, match=msg):
        right - left


def get_upcast_box(box, vector):
    """
    Given two box-types, find the one that takes priority

            

Reported by Pylint.

Access to a protected member _ndarray of a client class
Error

Line: 69 Column: 20

                      # Eventually we'd like this to be tighter, but for now we'll
        #  just exclude PandasArray[bool]
        if isinstance(x, PandasArray):
            return x._ndarray
        return x

    result = xbox2(left == right)
    expected = xbox(np.zeros(result.shape, dtype=np.bool_))


            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 102 Column: 9

                      ]
    )
    with pytest.raises(TypeError, match=msg):
        left < right
    with pytest.raises(TypeError, match=msg):
        left <= right
    with pytest.raises(TypeError, match=msg):
        left > right
    with pytest.raises(TypeError, match=msg):

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 104 Column: 9

                  with pytest.raises(TypeError, match=msg):
        left < right
    with pytest.raises(TypeError, match=msg):
        left <= right
    with pytest.raises(TypeError, match=msg):
        left > right
    with pytest.raises(TypeError, match=msg):
        left >= right
    with pytest.raises(TypeError, match=msg):

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 106 Column: 9

                  with pytest.raises(TypeError, match=msg):
        left <= right
    with pytest.raises(TypeError, match=msg):
        left > right
    with pytest.raises(TypeError, match=msg):
        left >= right
    with pytest.raises(TypeError, match=msg):
        right < left
    with pytest.raises(TypeError, match=msg):

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 108 Column: 9

                  with pytest.raises(TypeError, match=msg):
        left > right
    with pytest.raises(TypeError, match=msg):
        left >= right
    with pytest.raises(TypeError, match=msg):
        right < left
    with pytest.raises(TypeError, match=msg):
        right <= left
    with pytest.raises(TypeError, match=msg):

            

Reported by Pylint.

pandas/tests/groupby/test_any_all.py
15 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              import builtins

import numpy as np
import pytest

import pandas as pd
from pandas import (
    DataFrame,
    Index,

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import builtins

import numpy as np
import pytest

import pandas as pd
from pandas import (
    DataFrame,
    Index,

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 34 Column: 1

                      [True, False, False],
        [False, False, False],
        [np.nan, np.nan, np.nan],
    ],
)
def test_groupby_bool_aggs(agg_func, skipna, vals):
    df = DataFrame({"key": ["a"] * 3 + ["b"] * 3, "val": vals * 2})

    # Figure out expectation using Python builtin

            

Reported by Pylint.

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

Line: 37 Column: 5

                  ],
)
def test_groupby_bool_aggs(agg_func, skipna, vals):
    df = DataFrame({"key": ["a"] * 3 + ["b"] * 3, "val": vals * 2})

    # Figure out expectation using Python builtin
    exp = getattr(builtins, agg_func)(vals)

    # edge case for missing data with skipna and 'any'

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 51 Column: 1

                  tm.assert_frame_equal(result, exp_df)


def test_any():
    df = DataFrame(
        [[1, 2, "foo"], [1, np.nan, "bar"], [3, np.nan, "baz"]],
        columns=["A", "B", "C"],
    )
    expected = DataFrame(

            

Reported by Pylint.

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

Line: 52 Column: 5

              

def test_any():
    df = DataFrame(
        [[1, 2, "foo"], [1, np.nan, "bar"], [3, np.nan, "baz"]],
        columns=["A", "B", "C"],
    )
    expected = DataFrame(
        [[True, True], [False, True]], columns=["B", "C"], index=[1, 3]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 65 Column: 1

              

@pytest.mark.parametrize("bool_agg_func", ["any", "all"])
def test_bool_aggs_dup_column_labels(bool_agg_func):
    # 21668
    df = DataFrame([[True, True]], columns=["a", "a"])
    grp_by = df.groupby([0])
    result = getattr(grp_by, bool_agg_func)()


            

Reported by Pylint.

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

Line: 67 Column: 5

              @pytest.mark.parametrize("bool_agg_func", ["any", "all"])
def test_bool_aggs_dup_column_labels(bool_agg_func):
    # 21668
    df = DataFrame([[True, True]], columns=["a", "a"])
    grp_by = df.groupby([0])
    result = getattr(grp_by, bool_agg_func)()

    expected = df
    tm.assert_frame_equal(result, expected)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 86 Column: 1

                      [False, pd.NA, False],
        [True, pd.NA, True],
        [True, pd.NA, False],
    ],
)
def test_masked_kleene_logic(bool_agg_func, skipna, data):
    # GH#37506
    ser = Series(data, dtype="boolean")


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 127 Column: 1

                          "boolean",
            pd.array([pd.NA], dtype="boolean"),
            pd.array([pd.NA], dtype="boolean"),
        ),
    ],
)
def test_masked_mixed_types(dtype1, dtype2, exp_col1, exp_col2):
    # GH#37506
    data = [1.0, np.nan]

            

Reported by Pylint.

pandas/tests/groupby/test_groupby_subclass.py
15 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              from datetime import datetime

import numpy as np
import pytest

from pandas import (
    DataFrame,
    Series,
)

            

Reported by Pylint.

Access to a protected member _constructor_sliced of a client class
Error

Line: 46 Column: 36

                  # Reduction or transformation kernels should preserve type
    slices = {"ngroup", "cumcount", "size"}
    if isinstance(obj, DataFrame) and groupby_func in slices:
        assert isinstance(result1, obj._constructor_sliced)
    else:
        assert isinstance(result1, type(obj))

    # Confirm .agg() groupby operations return same results
    if isinstance(result1, DataFrame):

            

Reported by Pylint.

Access to a protected member _metadata of a client class
Error

Line: 60 Column: 26

              def test_groupby_preserves_metadata():
    # GH-37343
    custom_df = tm.SubclassedDataFrame({"a": [1, 2, 3], "b": [1, 1, 2], "c": [7, 8, 9]})
    assert "testattr" in custom_df._metadata
    custom_df.testattr = "hello"
    for _, group_df in custom_df.groupby("c"):
        assert group_df.testattr == "hello"



            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from datetime import datetime

import numpy as np
import pytest

from pandas import (
    DataFrame,
    Series,
)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

                      tm.SubclassedDataFrame({"A": np.arange(0, 10)}),
        tm.SubclassedSeries(np.arange(0, 10), name="A"),
    ],
)
@pytest.mark.filterwarnings("ignore:tshift is deprecated:FutureWarning")
def test_groupby_preserves_subclass(obj, groupby_func):
    # GH28330 -- preserve subclass through groupby operations

    if isinstance(obj, Series) and groupby_func in {"corrwith"}:

            

Reported by Pylint.

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

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

                  grouped = obj.groupby(np.arange(0, 10))

    # Groups should preserve subclass type
    assert isinstance(grouped.get_group(0), type(obj))

    args = []
    if groupby_func in {"fillna", "nth"}:
        args.append(0)
    elif groupby_func == "corrwith":

            

Reported by Bandit.

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

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

                  # Reduction or transformation kernels should preserve type
    slices = {"ngroup", "cumcount", "size"}
    if isinstance(obj, DataFrame) and groupby_func in slices:
        assert isinstance(result1, obj._constructor_sliced)
    else:
        assert isinstance(result1, type(obj))

    # Confirm .agg() groupby operations return same results
    if isinstance(result1, DataFrame):

            

Reported by Bandit.

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

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

                  if isinstance(obj, DataFrame) and groupby_func in slices:
        assert isinstance(result1, obj._constructor_sliced)
    else:
        assert isinstance(result1, type(obj))

    # Confirm .agg() groupby operations return same results
    if isinstance(result1, DataFrame):
        tm.assert_frame_equal(result1, result2)
    else:

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 57 Column: 1

                      tm.assert_series_equal(result1, result2)


def test_groupby_preserves_metadata():
    # GH-37343
    custom_df = tm.SubclassedDataFrame({"a": [1, 2, 3], "b": [1, 1, 2], "c": [7, 8, 9]})
    assert "testattr" in custom_df._metadata
    custom_df.testattr = "hello"
    for _, group_df in custom_df.groupby("c"):

            

Reported by Pylint.

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

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

              def test_groupby_preserves_metadata():
    # GH-37343
    custom_df = tm.SubclassedDataFrame({"a": [1, 2, 3], "b": [1, 1, 2], "c": [7, 8, 9]})
    assert "testattr" in custom_df._metadata
    custom_df.testattr = "hello"
    for _, group_df in custom_df.groupby("c"):
        assert group_df.testattr == "hello"



            

Reported by Bandit.

pandas/tests/extension/list/array.py
15 issues
Method '__setitem__' is abstract in class 'ExtensionArray' but is not overridden
Error

Line: 43 Column: 1

                      return ListArray


class ListArray(ExtensionArray):
    dtype = ListDtype()
    __array_priority__ = 1000

    def __init__(self, values, dtype=None, copy=False):
        if not isinstance(values, np.ndarray):

            

Reported by Pylint.

Unused argument 'dtype'
Error

Line: 47 Column: 32

                  dtype = ListDtype()
    __array_priority__ = 1000

    def __init__(self, values, dtype=None, copy=False):
        if not isinstance(values, np.ndarray):
            raise TypeError("Need to pass a numpy array as values")
        for val in values:
            if not isinstance(val, self.dtype.type) and not pd.isna(val):
                raise TypeError("All values must be of type " + str(self.dtype.type))

            

Reported by Pylint.

Unused argument 'copy'
Error

Line: 47 Column: 44

                  dtype = ListDtype()
    __array_priority__ = 1000

    def __init__(self, values, dtype=None, copy=False):
        if not isinstance(values, np.ndarray):
            raise TypeError("Need to pass a numpy array as values")
        for val in values:
            if not isinstance(val, self.dtype.type) and not pd.isna(val):
                raise TypeError("All values must be of type " + str(self.dtype.type))

            

Reported by Pylint.

Parameters differ from overridden '_from_sequence' method
Error

Line: 56 Column: 5

                      self.data = values

    @classmethod
    def _from_sequence(cls, scalars, dtype=None, copy=False):
        data = np.empty(len(scalars), dtype=object)
        data[:] = scalars
        return cls(data)

    def __getitem__(self, item):

            

Reported by Pylint.

Unused argument 'copy'
Error

Line: 56 Column: 50

                      self.data = values

    @classmethod
    def _from_sequence(cls, scalars, dtype=None, copy=False):
        data = np.empty(len(scalars), dtype=object)
        data[:] = scalars
        return cls(data)

    def __getitem__(self, item):

            

Reported by Pylint.

Unused argument 'dtype'
Error

Line: 56 Column: 38

                      self.data = values

    @classmethod
    def _from_sequence(cls, scalars, dtype=None, copy=False):
        data = np.empty(len(scalars), dtype=object)
        data[:] = scalars
        return cls(data)

    def __getitem__(self, item):

            

Reported by Pylint.

Parameters differ from overridden 'take' method
Error

Line: 76 Column: 5

                          [not isinstance(x, list) and np.isnan(x) for x in self.data], dtype=bool
        )

    def take(self, indexer, allow_fill=False, fill_value=None):
        # re-implement here, since NumPy has trouble setting
        # sized objects like UserDicts into scalar slots of
        # an ndarary.
        indexer = np.asarray(indexer)
        msg = (

            

Reported by Pylint.

TODO: Use a regular dict. See _NDFrameIndexer._setitem_with_indexer
Error

Line: 126 Column: 3

              

def make_data():
    # TODO: Use a regular dict. See _NDFrameIndexer._setitem_with_indexer
    data = np.empty(100, dtype=object)
    data[:] = [
        [random.choice(string.ascii_letters) for _ in range(random.randint(0, 10))]
        for _ in range(100)
    ]

            

Reported by Pylint.

Missing class docstring
Error

Line: 26 Column: 1

              from pandas.core.arrays import ExtensionArray


class ListDtype(ExtensionDtype):
    type = list
    name = "list"
    na_value = np.nan

    @classmethod

            

Reported by Pylint.

Missing class docstring
Error

Line: 43 Column: 1

                      return ListArray


class ListArray(ExtensionArray):
    dtype = ListDtype()
    __array_priority__ = 1000

    def __init__(self, values, dtype=None, copy=False):
        if not isinstance(values, np.ndarray):

            

Reported by Pylint.