The following issues were found

pandas/tests/frame/methods/test_to_records.py
65 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              from collections import abc

import numpy as np
import pytest

from pandas import (
    CategoricalDtype,
    DataFrame,
    MultiIndex,

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from collections import abc

import numpy as np
import pytest

from pandas import (
    CategoricalDtype,
    DataFrame,
    MultiIndex,

            

Reported by Pylint.

Missing class docstring
Error

Line: 17 Column: 1

              import pandas._testing as tm


class TestDataFrameToRecords:
    def test_to_records_timeseries(self):
        index = date_range("1/1/2000", periods=10)
        df = DataFrame(np.random.randn(10, 3), index=index, columns=["a", "b", "c"])

        result = df.to_records()

            

Reported by Pylint.

Method could be a function
Error

Line: 18 Column: 5

              

class TestDataFrameToRecords:
    def test_to_records_timeseries(self):
        index = date_range("1/1/2000", periods=10)
        df = DataFrame(np.random.randn(10, 3), index=index, columns=["a", "b", "c"])

        result = df.to_records()
        assert result["index"].dtype == "M8[ns]"

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 18 Column: 5

              

class TestDataFrameToRecords:
    def test_to_records_timeseries(self):
        index = date_range("1/1/2000", periods=10)
        df = DataFrame(np.random.randn(10, 3), index=index, columns=["a", "b", "c"])

        result = df.to_records()
        assert result["index"].dtype == "M8[ns]"

            

Reported by Pylint.

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

Line: 20 Column: 9

              class TestDataFrameToRecords:
    def test_to_records_timeseries(self):
        index = date_range("1/1/2000", periods=10)
        df = DataFrame(np.random.randn(10, 3), index=index, columns=["a", "b", "c"])

        result = df.to_records()
        assert result["index"].dtype == "M8[ns]"

        result = df.to_records(index=False)

            

Reported by Pylint.

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

                      df = DataFrame(np.random.randn(10, 3), index=index, columns=["a", "b", "c"])

        result = df.to_records()
        assert result["index"].dtype == "M8[ns]"

        result = df.to_records(index=False)

    def test_to_records_dt64(self):
        df = DataFrame(

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 27 Column: 5

              
        result = df.to_records(index=False)

    def test_to_records_dt64(self):
        df = DataFrame(
            [["one", "two", "three"], ["four", "five", "six"]],
            index=date_range("2012-01-01", "2012-01-02"),
        )


            

Reported by Pylint.

Method could be a function
Error

Line: 27 Column: 5

              
        result = df.to_records(index=False)

    def test_to_records_dt64(self):
        df = DataFrame(
            [["one", "two", "three"], ["four", "five", "six"]],
            index=date_range("2012-01-01", "2012-01-02"),
        )


            

Reported by Pylint.

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

Line: 28 Column: 9

                      result = df.to_records(index=False)

    def test_to_records_dt64(self):
        df = DataFrame(
            [["one", "two", "three"], ["four", "five", "six"]],
            index=date_range("2012-01-01", "2012-01-02"),
        )

        expected = df.index.values[0]

            

Reported by Pylint.

pandas/tests/extension/test_categorical.py
65 issues
Unable to import 'pytest'
Error

Line: 19 Column: 1

              import string

import numpy as np
import pytest

import pandas as pd
from pandas import (
    Categorical,
    CategoricalIndex,

            

Reported by Pylint.

Redefining name 'data' from outer scope (line 49)
Error

Line: 90 Column: 33

              
class TestInterface(base.BaseInterfaceTests):
    @pytest.mark.skip(reason="Memory usage doesn't match")
    def test_memory_usage(self, data):
        # Is this deliberate?
        super().test_memory_usage(data)

    def test_contains(self, data, data_missing):
        # GH-37867

            

Reported by Pylint.

Redefining name 'data' from outer scope (line 49)
Error

Line: 94 Column: 29

                      # Is this deliberate?
        super().test_memory_usage(data)

    def test_contains(self, data, data_missing):
        # GH-37867
        # na value handling in Categorical.__contains__ is deprecated.
        # See base.BaseInterFaceTests.test_contains for more details.

        na_value = data.dtype.na_value

            

Reported by Pylint.

Redefining name 'data_missing' from outer scope (line 59)
Error

Line: 94 Column: 35

                      # Is this deliberate?
        super().test_memory_usage(data)

    def test_contains(self, data, data_missing):
        # GH-37867
        # na value handling in Categorical.__contains__ is deprecated.
        # See base.BaseInterFaceTests.test_contains for more details.

        na_value = data.dtype.na_value

            

Reported by Pylint.

Redefining name 'na_value' from outer scope (line 75)
Error

Line: 99 Column: 9

                      # na value handling in Categorical.__contains__ is deprecated.
        # See base.BaseInterFaceTests.test_contains for more details.

        na_value = data.dtype.na_value
        # ensure data without missing values
        data = data[~data.isna()]

        # first elements are non-missing
        assert data[0] in data

            

Reported by Pylint.

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

Line: 120 Column: 26

              

class TestConstructors(base.BaseConstructorsTests):
    def test_empty(self, dtype):
        cls = dtype.construct_array_type()
        result = cls._empty((4,), dtype=dtype)

        assert isinstance(result, cls)
        # the dtype we passed is not initialized, so will not match the

            

Reported by Pylint.

Access to a protected member _empty of a client class
Error

Line: 122 Column: 18

              class TestConstructors(base.BaseConstructorsTests):
    def test_empty(self, dtype):
        cls = dtype.construct_array_type()
        result = cls._empty((4,), dtype=dtype)

        assert isinstance(result, cls)
        # the dtype we passed is not initialized, so will not match the
        #  dtype on our result.
        assert result.dtype == CategoricalDtype([])

            

Reported by Pylint.

Redefining name 'data' from outer scope (line 49)
Error

Line: 136 Column: 35

              
class TestGetitem(base.BaseGetitemTests):
    @pytest.mark.skip(reason="Backwards compatibility")
    def test_getitem_scalar(self, data):
        # CategoricalDtype.type isn't "correct" since it should
        # be a parent of the elements (object). But don't want
        # to break things by changing.
        super().test_getitem_scalar(data)


            

Reported by Pylint.

Redefining name 'data_missing' from outer scope (line 59)
Error

Line: 149 Column: 37

              
class TestMissing(base.BaseMissingTests):
    @pytest.mark.skip(reason="Not implemented")
    def test_fillna_limit_pad(self, data_missing):
        super().test_fillna_limit_pad(data_missing)

    @pytest.mark.skip(reason="Not implemented")
    def test_fillna_limit_backfill(self, data_missing):
        super().test_fillna_limit_backfill(data_missing)

            

Reported by Pylint.

Redefining name 'data_missing' from outer scope (line 59)
Error

Line: 153 Column: 42

                      super().test_fillna_limit_pad(data_missing)

    @pytest.mark.skip(reason="Not implemented")
    def test_fillna_limit_backfill(self, data_missing):
        super().test_fillna_limit_backfill(data_missing)


class TestReduce(base.BaseNoReduceTests):
    pass

            

Reported by Pylint.

pandas/tests/series/methods/test_quantile.py
64 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

from pandas.core.dtypes.common import is_integer

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

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

from pandas.core.dtypes.common import is_integer

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

            

Reported by Pylint.

Missing class docstring
Error

Line: 15 Column: 1

              from pandas.core.indexes.datetimes import Timestamp


class TestSeriesQuantile:
    def test_quantile(self, datetime_series):

        q = datetime_series.quantile(0.1)
        assert q == np.percentile(datetime_series.dropna(), 10)


            

Reported by Pylint.

Method could be a function
Error

Line: 16 Column: 5

              

class TestSeriesQuantile:
    def test_quantile(self, datetime_series):

        q = datetime_series.quantile(0.1)
        assert q == np.percentile(datetime_series.dropna(), 10)

        q = datetime_series.quantile(0.9)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 5

              

class TestSeriesQuantile:
    def test_quantile(self, datetime_series):

        q = datetime_series.quantile(0.1)
        assert q == np.percentile(datetime_series.dropna(), 10)

        q = datetime_series.quantile(0.9)

            

Reported by Pylint.

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

Line: 18 Column: 9

              class TestSeriesQuantile:
    def test_quantile(self, datetime_series):

        q = datetime_series.quantile(0.1)
        assert q == np.percentile(datetime_series.dropna(), 10)

        q = datetime_series.quantile(0.9)
        assert q == np.percentile(datetime_series.dropna(), 90)


            

Reported by Pylint.

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

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

                  def test_quantile(self, datetime_series):

        q = datetime_series.quantile(0.1)
        assert q == np.percentile(datetime_series.dropna(), 10)

        q = datetime_series.quantile(0.9)
        assert q == np.percentile(datetime_series.dropna(), 90)

        # object dtype

            

Reported by Bandit.

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

Line: 21 Column: 9

                      q = datetime_series.quantile(0.1)
        assert q == np.percentile(datetime_series.dropna(), 10)

        q = datetime_series.quantile(0.9)
        assert q == np.percentile(datetime_series.dropna(), 90)

        # object dtype
        q = Series(datetime_series, dtype=object).quantile(0.9)
        assert q == np.percentile(datetime_series.dropna(), 90)

            

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

                      assert q == np.percentile(datetime_series.dropna(), 10)

        q = datetime_series.quantile(0.9)
        assert q == np.percentile(datetime_series.dropna(), 90)

        # object dtype
        q = Series(datetime_series, dtype=object).quantile(0.9)
        assert q == np.percentile(datetime_series.dropna(), 90)


            

Reported by Bandit.

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

Line: 25 Column: 9

                      assert q == np.percentile(datetime_series.dropna(), 90)

        # object dtype
        q = Series(datetime_series, dtype=object).quantile(0.9)
        assert q == np.percentile(datetime_series.dropna(), 90)

        # datetime64[ns] dtype
        dts = datetime_series.index.to_series()
        q = dts.quantile(0.2)

            

Reported by Pylint.

pandas/tests/series/methods/test_align.py
64 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest
import pytz

import pandas as pd
from pandas import (
    Series,
    date_range,
    period_range,

            

Reported by Pylint.

Unable to import 'pytz'
Error

Line: 3 Column: 1

              import numpy as np
import pytest
import pytz

import pandas as pd
from pandas import (
    Series,
    date_range,
    period_range,

            

Reported by Pylint.

TODO: assert something?
Error

Line: 185 Column: 3

                  rng = period_range("1/1/2000", "1/1/2010", freq="A")
    ts = Series(np.random.randn(len(rng)), index=rng)

    # TODO: assert something?
    ts.align(ts[::2], join=join_type)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest
import pytz

import pandas as pd
from pandas import (
    Series,
    date_range,
    period_range,

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 1

                      [[None, -5], [None, 0]],
        [[None, 0], [None, 0]],
    ],
)
@pytest.mark.parametrize("fill", [None, -1])
def test_align(datetime_series, first_slice, second_slice, join_type, fill):
    a = datetime_series[slice(*first_slice)]
    b = datetime_series[slice(*second_slice)]


            

Reported by Pylint.

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

Line: 25 Column: 5

              )
@pytest.mark.parametrize("fill", [None, -1])
def test_align(datetime_series, first_slice, second_slice, join_type, fill):
    a = datetime_series[slice(*first_slice)]
    b = datetime_series[slice(*second_slice)]

    aa, ab = a.align(b, join=join_type, fill_value=fill)

    join_index = a.index.join(b.index, how=join_type)

            

Reported by Pylint.

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

Line: 26 Column: 5

              @pytest.mark.parametrize("fill", [None, -1])
def test_align(datetime_series, first_slice, second_slice, join_type, fill):
    a = datetime_series[slice(*first_slice)]
    b = datetime_series[slice(*second_slice)]

    aa, ab = a.align(b, join=join_type, fill_value=fill)

    join_index = a.index.join(b.index, how=join_type)
    if fill is not None:

            

Reported by Pylint.

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

Line: 28 Column: 9

                  a = datetime_series[slice(*first_slice)]
    b = datetime_series[slice(*second_slice)]

    aa, ab = a.align(b, join=join_type, fill_value=fill)

    join_index = a.index.join(b.index, how=join_type)
    if fill is not None:
        diff_a = aa.index.difference(join_index)
        diff_b = ab.index.difference(join_index)

            

Reported by Pylint.

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

Line: 28 Column: 5

                  a = datetime_series[slice(*first_slice)]
    b = datetime_series[slice(*second_slice)]

    aa, ab = a.align(b, join=join_type, fill_value=fill)

    join_index = a.index.join(b.index, how=join_type)
    if fill is not None:
        diff_a = aa.index.difference(join_index)
        diff_b = ab.index.difference(join_index)

            

Reported by Pylint.

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

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

                      diff_a = aa.index.difference(join_index)
        diff_b = ab.index.difference(join_index)
        if len(diff_a) > 0:
            assert (aa.reindex(diff_a) == fill).all()
        if len(diff_b) > 0:
            assert (ab.reindex(diff_b) == fill).all()

    ea = a.reindex(join_index)
    eb = b.reindex(join_index)

            

Reported by Bandit.

pandas/tests/test_downstream.py
64 issues
Unable to import 'pytest'
Error

Line: 9 Column: 1

              import sys

import numpy as np  # noqa
import pytest

import pandas.util._test_decorators as td

from pandas import DataFrame
import pandas._testing as tm

            

Reported by Pylint.

Unable to import 'dask.dataframe'
Error

Line: 40 Column: 5

                  toolz = import_module("toolz")  # noqa
    dask = import_module("dask")  # noqa

    import dask.dataframe as dd

    ddf = dd.from_pandas(df, npartitions=3)
    assert ddf.A is not None
    assert ddf.compute() is not None


            

Reported by Pylint.

Unable to import 'cftime'
Error

Line: 58 Column: 5

              @td.skip_if_no("xarray", "0.10.4")
def test_xarray_cftimeindex_nearest():
    # https://github.com/pydata/xarray/issues/3751
    import cftime
    import xarray

    times = xarray.cftime_range("0001", periods=2)
    key = cftime.DatetimeGregorian(2000, 1, 1)
    with tm.assert_produces_warning(

            

Reported by Pylint.

Unable to import 'xarray'
Error

Line: 59 Column: 5

              def test_xarray_cftimeindex_nearest():
    # https://github.com/pydata/xarray/issues/3751
    import cftime
    import xarray

    times = xarray.cftime_range("0001", periods=2)
    key = cftime.DatetimeGregorian(2000, 1, 1)
    with tm.assert_produces_warning(
        FutureWarning, match="deprecated", check_stacklevel=False

            

Reported by Pylint.

Unable to import 'statsmodels.api'
Error

Line: 102 Column: 5

              def test_statsmodels():

    statsmodels = import_module("statsmodels")  # noqa
    import statsmodels.api as sm
    import statsmodels.formula.api as smf

    df = sm.datasets.get_rdataset("Guerry", "HistData").data
    smf.ols("Lottery ~ Literacy + np.log(Pop1831)", data=df).fit()


            

Reported by Pylint.

Unable to import 'statsmodels.formula.api'
Error

Line: 103 Column: 5

              
    statsmodels = import_module("statsmodels")  # noqa
    import statsmodels.api as sm
    import statsmodels.formula.api as smf

    df = sm.datasets.get_rdataset("Guerry", "HistData").data
    smf.ols("Lottery ~ Literacy + np.log(Pop1831)", data=df).fit()



            

Reported by Pylint.

Unable to import 'sklearn'
Error

Line: 114 Column: 5

              def test_scikit_learn(df):

    sklearn = import_module("sklearn")  # noqa
    from sklearn import (
        datasets,
        svm,
    )

    digits = datasets.load_digits()

            

Reported by Pylint.

Unused numpy imported as np
Error

Line: 8 Column: 1

              import subprocess
import sys

import numpy as np  # noqa
import pytest

import pandas.util._test_decorators as td

from pandas import DataFrame

            

Reported by Pylint.

TODO(ArrayManager) dask is still accessing the blocks
Error

Line: 32 Column: 3

                  return DataFrame({"A": [1, 2, 3]})


# TODO(ArrayManager) dask is still accessing the blocks
# https://github.com/dask/dask/pull/7318
@td.skip_array_manager_not_yet_implemented
def test_dask(df):

    toolz = import_module("toolz")  # noqa

            

Reported by Pylint.

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

Line: 35 Column: 15

              # TODO(ArrayManager) dask is still accessing the blocks
# https://github.com/dask/dask/pull/7318
@td.skip_array_manager_not_yet_implemented
def test_dask(df):

    toolz = import_module("toolz")  # noqa
    dask = import_module("dask")  # noqa

    import dask.dataframe as dd

            

Reported by Pylint.

pandas/core/groupby/grouper.py
64 issues
Method 'result_index' has no '_values' member
Error

Line: 628 Column: 20

              
        elif self._all_grouper is not None:
            # retain dtype for categories, including unobserved ones
            return self.result_index._values

        return self._codes_and_uniques[1]

    @cache_readonly
    def result_index(self) -> Index:

            

Reported by Pylint.

Unused argument 'args'
Error

Line: 262 Column: 1

              
    _attributes: tuple[str, ...] = ("key", "level", "freq", "axis", "sort")

    def __new__(cls, *args, **kwargs):
        if kwargs.get("freq") is not None:
            from pandas.core.resample import TimeGrouper

            _check_deprecated_resample_kwargs(kwargs, origin=cls)
            cls = TimeGrouper

            

Reported by Pylint.

Invalid assignment to cls in method
Error

Line: 267 Column: 13

                          from pandas.core.resample import TimeGrouper

            _check_deprecated_resample_kwargs(kwargs, origin=cls)
            cls = TimeGrouper
        return super().__new__(cls)

    def __init__(
        self,
        key=None,

            

Reported by Pylint.

TODO: What are we assuming about subsequent calls?
Error

Line: 350 Column: 3

              
        # Keep self.grouper value before overriding
        if self._grouper is None:
            # TODO: What are we assuming about subsequent calls?
            self._grouper = self._gpr_index
            self._indexer = self.indexer

        # the key must be a valid info item
        if self.key is not None:

            

Reported by Pylint.

Access to a protected member _info_axis of a client class
Error

Line: 373 Column: 31

                              else:
                    ax = self._grouper.take(obj.index)
            else:
                if key not in obj._info_axis:
                    raise KeyError(f"The grouper name {key} is not found")
                ax = Index(obj[key], name=key)

        else:
            ax = obj._get_axis(self.axis)

            

Reported by Pylint.

Access to a protected member _get_level_number of a client class
Error

Line: 385 Column: 29

                              # if a level is given it must be a mi level or
                # equivalent to the axis name
                if isinstance(ax, MultiIndex):
                    level = ax._get_level_number(level)
                    ax = Index(ax._get_level_values(level), name=ax.names[level])

                else:
                    if level not in (0, ax.name):
                        raise ValueError(f"The level {level} is not valid")

            

Reported by Pylint.

TODO: why does putting na_position="first" fix datetimelike cases?
Error

Line: 395 Column: 3

                      # possibly sort
        if (self.sort or sort) and not ax.is_monotonic:
            # use stable sort to support first, last, nth
            # TODO: why does putting na_position="first" fix datetimelike cases?
            indexer = self.indexer = ax.array.argsort(
                kind="mergesort", na_position="first"
            )
            ax = ax.take(indexer)
            obj = obj.take(indexer, axis=self.axis)

            

Reported by Pylint.

Access to a protected member _reverse_indexer of a client class
Error

Line: 606 Column: 16

                          return self.grouping_vector.indices

        values = Categorical(self.grouping_vector)
        return values._reverse_indexer()

    @property
    def codes(self) -> np.ndarray:
        if self._codes is not None:
            # _codes is set in __init__ for MultiIndex cases

            

Reported by Pylint.

Access to a protected member _values of a client class
Error

Line: 624 Column: 20

                      """
        if self._group_index is not None:
            # _group_index is set in __init__ for MultiIndex cases
            return self._group_index._values

        elif self._all_grouper is not None:
            # retain dtype for categories, including unobserved ones
            return self.result_index._values


            

Reported by Pylint.

Access to a protected member _values of a client class
Error

Line: 628 Column: 20

              
        elif self._all_grouper is not None:
            # retain dtype for categories, including unobserved ones
            return self.result_index._values

        return self._codes_and_uniques[1]

    @cache_readonly
    def result_index(self) -> Index:

            

Reported by Pylint.

pandas/tests/indexes/multi/test_get_set.py
64 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

from pandas.core.dtypes.dtypes import DatetimeTZDtype

import pandas as pd
from pandas import (
    CategoricalIndex,
    MultiIndex,

            

Reported by Pylint.

Instance of 'CategoricalIndex' has no 'ordered' member
Error

Line: 377 Column: 59

              
    result_lvl = result.get_level_values(0)
    expected_lvl = CategoricalIndex(
        list("bacb"), categories=cidx.categories, ordered=cidx.ordered
    )
    tm.assert_index_equal(result_lvl, expected_lvl)


def test_set_value_keeps_names():

            

Reported by Pylint.

Access to a protected member _get_level_number of a client class
Error

Line: 26 Column: 12

              
def test_get_level_number_integer(idx):
    idx.names = [1, 0]
    assert idx._get_level_number(1) == 0
    assert idx._get_level_number(0) == 1
    msg = "Too many levels: Index has only 2 levels, not 3"
    with pytest.raises(IndexError, match=msg):
        idx._get_level_number(2)
    with pytest.raises(KeyError, match="Level fourth not found"):

            

Reported by Pylint.

Access to a protected member _get_level_number of a client class
Error

Line: 27 Column: 12

              def test_get_level_number_integer(idx):
    idx.names = [1, 0]
    assert idx._get_level_number(1) == 0
    assert idx._get_level_number(0) == 1
    msg = "Too many levels: Index has only 2 levels, not 3"
    with pytest.raises(IndexError, match=msg):
        idx._get_level_number(2)
    with pytest.raises(KeyError, match="Level fourth not found"):
        idx._get_level_number("fourth")

            

Reported by Pylint.

Access to a protected member _get_level_number of a client class
Error

Line: 30 Column: 9

                  assert idx._get_level_number(0) == 1
    msg = "Too many levels: Index has only 2 levels, not 3"
    with pytest.raises(IndexError, match=msg):
        idx._get_level_number(2)
    with pytest.raises(KeyError, match="Level fourth not found"):
        idx._get_level_number("fourth")


def test_get_dtypes():

            

Reported by Pylint.

Access to a protected member _get_level_number of a client class
Error

Line: 32 Column: 9

                  with pytest.raises(IndexError, match=msg):
        idx._get_level_number(2)
    with pytest.raises(KeyError, match="Level fourth not found"):
        idx._get_level_number("fourth")


def test_get_dtypes():
    # Test MultiIndex.dtypes (# Gh37062)
    idx_multitype = MultiIndex.from_product(

            

Reported by Pylint.

Access to a protected member _get_level_number of a client class
Error

Line: 74 Column: 9

                  frame = multiindex_dataframe_random_data

    with pytest.raises(IndexError, match="Too many levels"):
        frame.index._get_level_number(2)
    with pytest.raises(IndexError, match="not a valid level number"):
        frame.index._get_level_number(-3)


def test_set_name_methods(idx, index_names):

            

Reported by Pylint.

Access to a protected member _get_level_number of a client class
Error

Line: 76 Column: 9

                  with pytest.raises(IndexError, match="Too many levels"):
        frame.index._get_level_number(2)
    with pytest.raises(IndexError, match="not a valid level number"):
        frame.index._get_level_number(-3)


def test_set_name_methods(idx, index_names):
    # so long as these are synonyms, we don't need to test set_names
    assert idx.rename == idx.set_names

            

Reported by Pylint.

Access to a protected member _is_copy of a client class
Error

Line: 391 Column: 12

                      np.random.randn(6, 4), columns=["one", "two", "three", "four"], index=idx
    )
    df = df.sort_index()
    assert df._is_copy is None
    assert df.index.names == ("Name", "Number")
    df.at[("grethe", "4"), "one"] = 99.34
    assert df._is_copy is None
    assert df.index.names == ("Name", "Number")


            

Reported by Pylint.

Access to a protected member _is_copy of a client class
Error

Line: 394 Column: 12

                  assert df._is_copy is None
    assert df.index.names == ("Name", "Number")
    df.at[("grethe", "4"), "one"] = 99.34
    assert df._is_copy is None
    assert df.index.names == ("Name", "Number")


def test_set_levels_with_iterable():
    # GH23273

            

Reported by Pylint.

pandas/tests/reshape/concat/test_append.py
64 issues
Unable to import 'pytest'
Error

Line: 6 Column: 1

              
import dateutil
import numpy as np
import pytest

import pandas.util._test_decorators as td

import pandas as pd
from pandas import (

            

Reported by Pylint.

TODO(ArrayManager) DataFrame.append reindexes a Series itself (giving
Error

Line: 304 Column: 3

                      assert appended["A"].dtype == "f8"
        assert appended["B"].dtype == "O"

    # TODO(ArrayManager) DataFrame.append reindexes a Series itself (giving
    # float dtype) -> delay reindexing until concat_array_managers which properly
    # takes care of all-null dtype inference
    @td.skip_array_manager_not_yet_implemented
    def test_append_empty_frame_to_series_with_dateutil_tz(self):
        # GH 23682

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import datetime as dt
from itertools import combinations

import dateutil
import numpy as np
import pytest

import pandas.util._test_decorators as td


            

Reported by Pylint.

Missing class docstring
Error

Line: 22 Column: 1

              import pandas._testing as tm


class TestAppend:
    def test_append(self, sort, float_frame):
        mixed_frame = float_frame.copy()
        mixed_frame["foo"] = "bar"

        begin_index = float_frame.index[:5]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 5

              

class TestAppend:
    def test_append(self, sort, float_frame):
        mixed_frame = float_frame.copy()
        mixed_frame["foo"] = "bar"

        begin_index = float_frame.index[:5]
        end_index = float_frame.index[5:]

            

Reported by Pylint.

Method could be a function
Error

Line: 23 Column: 5

              

class TestAppend:
    def test_append(self, sort, float_frame):
        mixed_frame = float_frame.copy()
        mixed_frame["foo"] = "bar"

        begin_index = float_frame.index[:5]
        end_index = float_frame.index[5:]

            

Reported by Pylint.

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

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

              
        del end_frame["A"]
        partial_appended = begin_frame.append(end_frame, sort=sort)
        assert "A" in partial_appended

        partial_appended = end_frame.append(begin_frame, sort=sort)
        assert "A" in partial_appended

        # mixed type handling

            

Reported by Bandit.

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

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

                      assert "A" in partial_appended

        partial_appended = end_frame.append(begin_frame, sort=sort)
        assert "A" in partial_appended

        # mixed type handling
        appended = mixed_frame[:5].append(mixed_frame[5:])
        tm.assert_frame_equal(appended, mixed_frame)


            

Reported by Bandit.

Method could be a function
Error

Line: 57 Column: 5

                          mixed_appended2.reindex(columns=["A", "B", "C", "D"]),
        )

    def test_append_empty(self, float_frame):
        empty = DataFrame()

        appended = float_frame.append(empty)
        tm.assert_frame_equal(float_frame, appended)
        assert appended is not float_frame

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 57 Column: 5

                          mixed_appended2.reindex(columns=["A", "B", "C", "D"]),
        )

    def test_append_empty(self, float_frame):
        empty = DataFrame()

        appended = float_frame.append(empty)
        tm.assert_frame_equal(float_frame, appended)
        assert appended is not float_frame

            

Reported by Pylint.

pandas/tests/indexes/test_engines.py
63 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              import re

import numpy as np
import pytest

from pandas._libs import (
    algos as libalgos,
    index as libindex,
)

            

Reported by Pylint.

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

Line: 6 Column: 1

              import numpy as np
import pytest

from pandas._libs import (
    algos as libalgos,
    index as libindex,
)

import pandas as pd

            

Reported by Pylint.

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

Line: 6 Column: 1

              import numpy as np
import pytest

from pandas._libs import (
    algos as libalgos,
    index as libindex,
)

import pandas as pd

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 54 Column: 17

                      msg = "|".join([re.escape(str(scalar)), re.escape(repr(scalar))])
        for dti in [dti1, dti2, dti3, dti4, dti5]:
            with pytest.raises(TypeError, match=msg):
                scalar in dti._engine

            with pytest.raises(KeyError, match=msg):
                dti._engine.get_loc(scalar)



            

Reported by Pylint.

Access to a protected member _engine of a client class
Error

Line: 54 Column: 27

                      msg = "|".join([re.escape(str(scalar)), re.escape(repr(scalar))])
        for dti in [dti1, dti2, dti3, dti4, dti5]:
            with pytest.raises(TypeError, match=msg):
                scalar in dti._engine

            with pytest.raises(KeyError, match=msg):
                dti._engine.get_loc(scalar)



            

Reported by Pylint.

Access to a protected member _engine of a client class
Error

Line: 57 Column: 17

                              scalar in dti._engine

            with pytest.raises(KeyError, match=msg):
                dti._engine.get_loc(scalar)


class TestTimedeltaEngine:
    @pytest.mark.parametrize(
        "scalar",

            

Reported by Pylint.

Access to a protected member _engine of a client class
Error

Line: 86 Column: 27

                      msg = "|".join([re.escape(str(scalar)), re.escape(repr(scalar))])
        for tdi in [tdi1, tdi2, tdi3, tdi4, tdi5]:
            with pytest.raises(TypeError, match=msg):
                scalar in tdi._engine

            with pytest.raises(KeyError, match=msg):
                tdi._engine.get_loc(scalar)



            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 86 Column: 17

                      msg = "|".join([re.escape(str(scalar)), re.escape(repr(scalar))])
        for tdi in [tdi1, tdi2, tdi3, tdi4, tdi5]:
            with pytest.raises(TypeError, match=msg):
                scalar in tdi._engine

            with pytest.raises(KeyError, match=msg):
                tdi._engine.get_loc(scalar)



            

Reported by Pylint.

Access to a protected member _engine of a client class
Error

Line: 89 Column: 17

                              scalar in tdi._engine

            with pytest.raises(KeyError, match=msg):
                tdi._engine.get_loc(scalar)


class TestNumericEngine:
    def test_is_monotonic(self, numeric_indexing_engine_type_and_dtype):
        engine_type, dtype = numeric_indexing_engine_type_and_dtype

            

Reported by Pylint.

Redefining name 'numeric_indexing_engine_type_and_dtype' from outer scope (line 29)
Error

Line: 93 Column: 33

              

class TestNumericEngine:
    def test_is_monotonic(self, numeric_indexing_engine_type_and_dtype):
        engine_type, dtype = numeric_indexing_engine_type_and_dtype
        num = 1000
        arr = np.array([1] * num + [2] * num + [3] * num, dtype=dtype)

        # monotonic increasing

            

Reported by Pylint.

pandas/tests/frame/methods/test_drop_duplicates.py
63 issues
Unable to import 'pytest'
Error

Line: 5 Column: 1

              import re

import numpy as np
import pytest

from pandas import (
    DataFrame,
    NaT,
)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from datetime import datetime
import re

import numpy as np
import pytest

from pandas import (
    DataFrame,
    NaT,

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 1

              

@pytest.mark.parametrize("subset", ["a", ["a"], ["a", "B"]])
def test_drop_duplicates_with_misspelled_column_name(subset):
    # GH 19730
    df = DataFrame({"A": [0, 0, 1], "B": [0, 0, 1], "C": [0, 0, 1]})
    msg = re.escape("Index(['a'], dtype='object')")

    with pytest.raises(KeyError, match=msg):

            

Reported by Pylint.

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

Line: 17 Column: 5

              @pytest.mark.parametrize("subset", ["a", ["a"], ["a", "B"]])
def test_drop_duplicates_with_misspelled_column_name(subset):
    # GH 19730
    df = DataFrame({"A": [0, 0, 1], "B": [0, 0, 1], "C": [0, 0, 1]})
    msg = re.escape("Index(['a'], dtype='object')")

    with pytest.raises(KeyError, match=msg):
        df.drop_duplicates(subset)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 1

                      df.drop_duplicates(subset)


def test_drop_duplicates():
    df = DataFrame(
        {
            "AAA": ["foo", "bar", "foo", "bar", "foo", "bar", "bar", "foo"],
            "B": ["one", "one", "two", "two", "two", "two", "one", "two"],
            "C": [1, 1, 2, 2, 2, 2, 1, 2],

            

Reported by Pylint.

Too many statements (61/50)
Error

Line: 24 Column: 1

                      df.drop_duplicates(subset)


def test_drop_duplicates():
    df = DataFrame(
        {
            "AAA": ["foo", "bar", "foo", "bar", "foo", "bar", "bar", "foo"],
            "B": ["one", "one", "two", "two", "two", "two", "one", "two"],
            "C": [1, 1, 2, 2, 2, 2, 1, 2],

            

Reported by Pylint.

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

Line: 25 Column: 5

              

def test_drop_duplicates():
    df = DataFrame(
        {
            "AAA": ["foo", "bar", "foo", "bar", "foo", "bar", "bar", "foo"],
            "B": ["one", "one", "two", "two", "two", "two", "one", "two"],
            "C": [1, 1, 2, 2, 2, 2, 1, 2],
            "D": range(8),

            

Reported by Pylint.

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

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

                  result = df.drop_duplicates("AAA", keep=False)
    expected = df.loc[[]]
    tm.assert_frame_equal(result, expected)
    assert len(result) == 0

    # multi column
    expected = df.loc[[0, 1, 2, 3]]
    result = df.drop_duplicates(np.array(["AAA", "B"]))
    tm.assert_frame_equal(result, expected)

            

Reported by Bandit.

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

Line: 95 Column: 5

                  tm.assert_frame_equal(result, expected)

    # GH 11376
    df = DataFrame({"x": [7, 6, 3, 3, 4, 8, 0], "y": [0, 6, 5, 5, 9, 1, 2]})
    expected = df.loc[df.index != 3]
    tm.assert_frame_equal(df.drop_duplicates(), expected)

    df = DataFrame([[1, 0], [0, 2]])
    tm.assert_frame_equal(df.drop_duplicates(), df)

            

Reported by Pylint.

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

Line: 99 Column: 5

                  expected = df.loc[df.index != 3]
    tm.assert_frame_equal(df.drop_duplicates(), expected)

    df = DataFrame([[1, 0], [0, 2]])
    tm.assert_frame_equal(df.drop_duplicates(), df)

    df = DataFrame([[-2, 0], [0, -4]])
    tm.assert_frame_equal(df.drop_duplicates(), df)


            

Reported by Pylint.