The following issues were found

pandas/tests/indexing/test_iloc.py
283 issues
Unable to import 'pytest'
Error

Line: 11 Column: 1

              )

import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas import (
    NA,

            

Reported by Pylint.

Access to a protected member _can_hold_element of a client class
Error

Line: 76 Column: 20

                      cat = Categorical(["alpha", "beta", "gamma"])

        if not using_array_manager:
            assert frame._mgr.blocks[0]._can_hold_element(cat)

        df = frame.copy()
        orig_vals = df.values
        indexer(df)[key, 0] = cat


            

Reported by Pylint.

Access to a protected member _mgr of a client class
Error

Line: 76 Column: 20

                      cat = Categorical(["alpha", "beta", "gamma"])

        if not using_array_manager:
            assert frame._mgr.blocks[0]._can_hold_element(cat)

        df = frame.copy()
        orig_vals = df.values
        indexer(df)[key, 0] = cat


            

Reported by Pylint.

TODO(ArrayManager) we always overwrite because ArrayManager takes
Error

Line: 85 Column: 3

                      overwrite = isinstance(key, slice) and key == slice(None)

        if overwrite or using_array_manager:
            # TODO(ArrayManager) we always overwrite because ArrayManager takes
            #  the "split" path, which still overwrites
            # TODO: GH#39986 this probably shouldn't behave differently
            expected = DataFrame({0: cat})
            assert not np.shares_memory(df.values, orig_vals)
        else:

            

Reported by Pylint.

TODO: GH#39986 this probably shouldn't behave differently
Error

Line: 87 Column: 3

                      if overwrite or using_array_manager:
            # TODO(ArrayManager) we always overwrite because ArrayManager takes
            #  the "split" path, which still overwrites
            # TODO: GH#39986 this probably shouldn't behave differently
            expected = DataFrame({0: cat})
            assert not np.shares_memory(df.values, orig_vals)
        else:
            expected = DataFrame({0: cat}).astype(object)
            if not using_array_manager:

            

Reported by Pylint.

TODO with mixed dataframe ("split" path), we always overwrite the column
Error

Line: 104 Column: 3

                      else:
            assert cat[0] != "gamma"

        # TODO with mixed dataframe ("split" path), we always overwrite the column
        frame = DataFrame({0: np.array([0, 1, 2], dtype=object), 1: range(3)})
        df = frame.copy()
        orig_vals = df.values
        indexer(df)[key, 0] = cat
        expected = DataFrame({0: cat, 1: range(3)})

            

Reported by Pylint.

TODO(ArrayManager) does not yet update parent
Error

Line: 112 Column: 3

                      expected = DataFrame({0: cat, 1: range(3)})
        tm.assert_frame_equal(df, expected)

    # TODO(ArrayManager) does not yet update parent
    @td.skip_array_manager_not_yet_implemented
    @pytest.mark.parametrize("box", [array, Series])
    def test_iloc_setitem_ea_inplace(self, frame_or_series, box, using_array_manager):
        # GH#38952 Case with not setting a full column
        #  IntegerArray without NAs

            

Reported by Pylint.

Access to a protected member _is_scalar_access of a client class
Error

Line: 148 Column: 16

                      index = Index([1, 2, 1])
        ser = Series(range(3), index=index)

        assert ser.iloc._is_scalar_access((1,))

        df = ser.to_frame()
        assert df.iloc._is_scalar_access((1, 0))

    def test_iloc_exceeds_bounds(self):

            

Reported by Pylint.

Access to a protected member _is_scalar_access of a client class
Error

Line: 151 Column: 16

                      assert ser.iloc._is_scalar_access((1,))

        df = ser.to_frame()
        assert df.iloc._is_scalar_access((1, 0))

    def test_iloc_exceeds_bounds(self):

        # GH6296
        # iloc should allow indexers that exceed the bounds

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 162 Column: 13

                      # lists of positions should raise IndexError!
        msg = "positional indexers are out-of-bounds"
        with pytest.raises(IndexError, match=msg):
            df.iloc[:, [0, 1, 2, 3, 4, 5]]
        with pytest.raises(IndexError, match=msg):
            df.iloc[[1, 30]]
        with pytest.raises(IndexError, match=msg):
            df.iloc[[1, -30]]
        with pytest.raises(IndexError, match=msg):

            

Reported by Pylint.

pandas/tests/series/test_arithmetic.py
279 issues
Unable to import 'pytest'
Error

Line: 5 Column: 1

              import operator

import numpy as np
import pytest
import pytz

from pandas._libs.tslibs import IncompatibleFrequency

from pandas.core.dtypes.common import (

            

Reported by Pylint.

Unable to import 'pytz'
Error

Line: 6 Column: 1

              
import numpy as np
import pytest
import pytz

from pandas._libs.tslibs import IncompatibleFrequency

from pandas.core.dtypes.common import (
    is_datetime64_dtype,

            

Reported by Pylint.

Instance of 'ExtensionIndex' has no 'tz_convert' member
Error

Line: 288 Column: 19

                  def test_alignment_doesnt_change_tz(self):
        # GH#33671
        dti = date_range("2016-01-01", periods=10, tz="CET")
        dti_utc = dti.tz_convert("UTC")
        ser = Series(10, index=dti)
        ser_utc = Series(10, index=dti_utc)

        # we don't care about the result, just that original indexes are unchanged
        ser * ser_utc

            

Reported by Pylint.

Instance of 'Index' has no 'tz_convert' member
Error

Line: 288 Column: 19

                  def test_alignment_doesnt_change_tz(self):
        # GH#33671
        dti = date_range("2016-01-01", periods=10, tz="CET")
        dti_utc = dti.tz_convert("UTC")
        ser = Series(10, index=dti)
        ser_utc = Series(10, index=dti_utc)

        # we don't care about the result, just that original indexes are unchanged
        ser * ser_utc

            

Reported by Pylint.

Instance of 'ExtensionIndex' has no 'tz_localize' member
Error

Line: 425 Column: 15

                      assert result.name == names[2]

        # datetime64tz dtype
        dti = dti.tz_localize("US/Central")
        dti = pd.DatetimeIndex(dti, freq="infer")  # freq not preserved by tz_localize
        ser = Series(dti).rename(names[1])
        result = op(ser, dti)
        assert result.name == names[2]


            

Reported by Pylint.

Instance of 'Index' has no 'tz_localize' member
Error

Line: 425 Column: 15

                      assert result.name == names[2]

        # datetime64tz dtype
        dti = dti.tz_localize("US/Central")
        dti = pd.DatetimeIndex(dti, freq="infer")  # freq not preserved by tz_localize
        ser = Series(dti).rename(names[1])
        result = op(ser, dti)
        assert result.name == names[2]


            

Reported by Pylint.

Access to a protected member _MIN_ELEMENTS of a client class
Error

Line: 38 Column: 21

                  autouse=True, scope="module", params=[0, 1000000], ids=["numexpr", "python"]
)
def switch_numexpr_min_elements(request):
    _MIN_ELEMENTS = expr._MIN_ELEMENTS
    expr._MIN_ELEMENTS = request.param
    yield request.param
    expr._MIN_ELEMENTS = _MIN_ELEMENTS



            

Reported by Pylint.

Access to a protected member _MIN_ELEMENTS of a client class
Error

Line: 39 Column: 5

              )
def switch_numexpr_min_elements(request):
    _MIN_ELEMENTS = expr._MIN_ELEMENTS
    expr._MIN_ELEMENTS = request.param
    yield request.param
    expr._MIN_ELEMENTS = _MIN_ELEMENTS


def _permute(obj):

            

Reported by Pylint.

Access to a protected member _MIN_ELEMENTS of a client class
Error

Line: 41 Column: 5

                  _MIN_ELEMENTS = expr._MIN_ELEMENTS
    expr._MIN_ELEMENTS = request.param
    yield request.param
    expr._MIN_ELEMENTS = _MIN_ELEMENTS


def _permute(obj):
    return obj.take(np.random.permutation(len(obj)))


            

Reported by Pylint.

Attribute 'x' defined outside __init__
Error

Line: 93 Column: 9

                      opname = all_arithmetic_operators
        op = getattr(Series, opname)
        m = MySeries([1, 2, 3], name="test")
        m.x = 42
        result = op(m, 1)
        assert result.x == 42

    def test_flex_add_scalar_fill_value(self):
        # GH12723

            

Reported by Pylint.

pandas/tests/reshape/test_pivot.py
278 issues
Unable to import 'pytest'
Error

Line: 9 Column: 1

              from itertools import product

import numpy as np
import pytest

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

            

Reported by Pylint.

Unused argument 'method'
Error

Line: 39 Column: 28

              

class TestPivotTable:
    def setup_method(self, method):
        self.data = DataFrame(
            {
                "A": [
                    "foo",
                    "foo",

            

Reported by Pylint.

Attribute 'data' defined outside __init__
Error

Line: 40 Column: 9

              
class TestPivotTable:
    def setup_method(self, method):
        self.data = DataFrame(
            {
                "A": [
                    "foo",
                    "foo",
                    "foo",

            

Reported by Pylint.

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

Line: 206 Column: 52

                      expected = DataFrame({"values": [1, 2, 3, 4]}, index=exp_index)
        tm.assert_frame_equal(result, expected)

    def test_pivot_table_dropna_categoricals(self, dropna):
        # GH 15193
        categories = ["a", "b", "c", "d"]

        df = DataFrame(
            {

            

Reported by Pylint.

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

Line: 234 Column: 53

              
        tm.assert_frame_equal(result, expected)

    def test_pivot_with_non_observable_dropna(self, dropna):
        # gh-21133
        df = DataFrame(
            {
                "A": Categorical(
                    [np.nan, "low", "high", "low", "high"],

            

Reported by Pylint.

Redefining name 'interval_values' from outer scope (line 33)
Error

Line: 287 Column: 46

              
        tm.assert_frame_equal(result, expected)

    def test_pivot_with_interval_index(self, interval_values, dropna):
        # GH 25814
        df = DataFrame({"A": interval_values, "B": 1})
        result = df.pivot_table(index="A", values="B", dropna=dropna)
        expected = DataFrame({"B": 1}, index=Index(interval_values.unique(), name="A"))
        if not dropna:

            

Reported by Pylint.

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

Line: 287 Column: 63

              
        tm.assert_frame_equal(result, expected)

    def test_pivot_with_interval_index(self, interval_values, dropna):
        # GH 25814
        df = DataFrame({"A": interval_values, "B": 1})
        result = df.pivot_table(index="A", values="B", dropna=dropna)
        expected = DataFrame({"B": 1}, index=Index(interval_values.unique(), name="A"))
        if not dropna:

            

Reported by Pylint.

Dangerous default value [] as argument
Error

Line: 852 Column: 9

                              pd.pivot(df, index="zoo", columns="foo", values=("bar", "baz"))

    def test_margins(self):
        def _check_output(
            result, values_col, index=["A", "B"], columns=["C"], margins_col="All"
        ):
            col_margins = result.loc[result.index[:-1], margins_col]
            expected_col_margins = self.data.groupby(index)[values_col].mean()
            tm.assert_series_equal(col_margins, expected_col_margins, check_names=False)

            

Reported by Pylint.

Dangerous default value [] as argument
Error

Line: 852 Column: 9

                              pd.pivot(df, index="zoo", columns="foo", values=("bar", "baz"))

    def test_margins(self):
        def _check_output(
            result, values_col, index=["A", "B"], columns=["C"], margins_col="All"
        ):
            col_margins = result.loc[result.index[:-1], margins_col]
            expected_col_margins = self.data.groupby(index)[values_col].mean()
            tm.assert_series_equal(col_margins, expected_col_margins, check_names=False)

            

Reported by Pylint.

Lambda may not be necessary
Error

Line: 1577 Column: 37

                              "value2": [1, 2] * 3,
            }
        )
        df["dt1"] = df["dt1"].apply(lambda d: pd.Timestamp(d))
        df["dt2"] = df["dt2"].apply(lambda d: pd.Timestamp(d))

        result = pivot_table(
            df, index="label", columns=df["dt1"].dt.hour, values="value1"
        )

            

Reported by Pylint.

pandas/tests/arithmetic/test_numeric.py
276 issues
Unable to import 'pytest'
Error

Line: 13 Column: 1

              from typing import Any

import numpy as np
import pytest

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

            

Reported by Pylint.

bad operand type for unary ~: Index
Error

Line: 128 Column: 33

                      tm.assert_equal(result, expected)

        result = obj != "a"
        tm.assert_equal(result, ~expected)

        msg = "Invalid comparison between dtype=float64 and str"
        with pytest.raises(TypeError, match=msg):
            obj < "a"


            

Reported by Pylint.

bad operand type for unary ~: IntervalArray
Error

Line: 128 Column: 33

                      tm.assert_equal(result, expected)

        result = obj != "a"
        tm.assert_equal(result, ~expected)

        msg = "Invalid comparison between dtype=float64 and str"
        with pytest.raises(TypeError, match=msg):
            obj < "a"


            

Reported by Pylint.

bad operand type for unary ~: PeriodArray
Error

Line: 128 Column: 33

                      tm.assert_equal(result, expected)

        result = obj != "a"
        tm.assert_equal(result, ~expected)

        msg = "Invalid comparison between dtype=float64 and str"
        with pytest.raises(TypeError, match=msg):
            obj < "a"


            

Reported by Pylint.

bad operand type for unary ~: ArrowStringArray
Error

Line: 128 Column: 33

                      tm.assert_equal(result, expected)

        result = obj != "a"
        tm.assert_equal(result, ~expected)

        msg = "Invalid comparison between dtype=float64 and str"
        with pytest.raises(TypeError, match=msg):
            obj < "a"


            

Reported by Pylint.

TODO: remove this kludge once mypy stops giving false positives here
Error

Line: 55 Column: 3

                  return expected


# TODO: remove this kludge once mypy stops giving false positives here
# List comprehension has incompatible type List[PandasObject]; expected List[RangeIndex]
#  See GH#29725
ser_or_index: list[Any] = [Series, Index]
lefts: list[Any] = [RangeIndex(10, 40, 10)]
lefts.extend(

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 94 Column: 13

                          "'[<>]' not supported between instances of 'numpy.ndarray' and 'Timestamp'"
        )
        with pytest.raises(TypeError, match=msg):
            df > ts
        with pytest.raises(TypeError, match=msg):
            df < ts
        with pytest.raises(TypeError, match=msg):
            ts < df
        with pytest.raises(TypeError, match=msg):

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 96 Column: 13

                      with pytest.raises(TypeError, match=msg):
            df > ts
        with pytest.raises(TypeError, match=msg):
            df < ts
        with pytest.raises(TypeError, match=msg):
            ts < df
        with pytest.raises(TypeError, match=msg):
            ts > df


            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 98 Column: 13

                      with pytest.raises(TypeError, match=msg):
            df < ts
        with pytest.raises(TypeError, match=msg):
            ts < df
        with pytest.raises(TypeError, match=msg):
            ts > df

        assert not (df == ts).any().any()
        assert (df != ts).all().all()

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 100 Column: 13

                      with pytest.raises(TypeError, match=msg):
            ts < df
        with pytest.raises(TypeError, match=msg):
            ts > df

        assert not (df == ts).any().any()
        assert (df != ts).all().all()

    def test_compare_invalid(self):

            

Reported by Pylint.

pandas/tests/dtypes/test_common.py
270 issues
Unable to import 'pytest'
Error

Line: 6 Column: 1

              from datetime import datetime

import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas.core.dtypes.cast import astype_nansafe
import pandas.core.dtypes.common as com

            

Reported by Pylint.

Unable to import 'scipy.sparse'
Error

Line: 187 Column: 9

                  assert not com.is_sparse(np.array([1, 2, 3]))

    if check_scipy:
        import scipy.sparse

        assert not com.is_sparse(scipy.sparse.bsr_matrix([1, 2, 3]))


@td.skip_if_no_scipy

            

Reported by Pylint.

Unable to import 'scipy.sparse'
Error

Line: 194 Column: 5

              
@td.skip_if_no_scipy
def test_is_scipy_sparse():
    from scipy.sparse import bsr_matrix

    assert com.is_scipy_sparse(bsr_matrix([1, 2, 3]))

    assert not com.is_scipy_sparse(SparseArray([1, 2, 3]))


            

Reported by Pylint.

Unable to import 'scipy.sparse'
Error

Line: 578 Column: 9

                  assert com.is_extension_type(s)

    if check_scipy:
        import scipy.sparse

        assert not com.is_extension_type(scipy.sparse.bsr_matrix([1, 2, 3]))


def test_is_extension_type_deprecation():

            

Reported by Pylint.

Unable to import 'scipy.sparse'
Error

Line: 607 Column: 9

                  assert com.is_extension_array_dtype(s)

    if check_scipy:
        import scipy.sparse

        assert not com.is_extension_array_dtype(scipy.sparse.bsr_matrix([1, 2, 3]))


def test_is_complex_dtype():

            

Reported by Pylint.

Redefining name 'dtypes' from outer scope (line 109)
Error

Line: 27 Column: 18

              

# EA & Actual Dtypes
def to_ea_dtypes(dtypes):
    """convert list of string dtypes to EA dtype"""
    return [getattr(pd, dt + "Dtype") for dt in dtypes]


def to_numpy_dtypes(dtypes):

            

Reported by Pylint.

Redefining name 'dtypes' from outer scope (line 109)
Error

Line: 32 Column: 21

                  return [getattr(pd, dt + "Dtype") for dt in dtypes]


def to_numpy_dtypes(dtypes):
    """convert list of string dtypes to numpy dtype"""
    return [getattr(np, dt) for dt in dtypes if isinstance(dt, str)]


class TestPandasDtype:

            

Reported by Pylint.

Lambda may not be necessary
Error

Line: 121 Column: 68

              }


@pytest.mark.parametrize("name1,dtype1", list(dtypes.items()), ids=lambda x: str(x))
@pytest.mark.parametrize("name2,dtype2", list(dtypes.items()), ids=lambda x: str(x))
def test_dtype_equal(name1, dtype1, name2, dtype2):

    # match equal to self, but not equal to other
    assert com.is_dtype_equal(dtype1, dtype1)

            

Reported by Pylint.

Lambda may not be necessary
Error

Line: 122 Column: 68

              

@pytest.mark.parametrize("name1,dtype1", list(dtypes.items()), ids=lambda x: str(x))
@pytest.mark.parametrize("name2,dtype2", list(dtypes.items()), ids=lambda x: str(x))
def test_dtype_equal(name1, dtype1, name2, dtype2):

    # match equal to self, but not equal to other
    assert com.is_dtype_equal(dtype1, dtype1)
    if name1 != name2:

            

Reported by Pylint.

TODO(jreback), this is slightly suspect
Error

Line: 466 Column: 3

                  assert not com.is_datetime_or_timedelta_dtype(pd.Series([1, 2]))
    assert not com.is_datetime_or_timedelta_dtype(np.array(["a", "b"]))

    # TODO(jreback), this is slightly suspect
    assert not com.is_datetime_or_timedelta_dtype(DatetimeTZDtype("ns", "US/Eastern"))

    assert com.is_datetime_or_timedelta_dtype(np.datetime64)
    assert com.is_datetime_or_timedelta_dtype(np.timedelta64)
    assert com.is_datetime_or_timedelta_dtype(np.array([], dtype=np.timedelta64))

            

Reported by Pylint.

pandas/tests/frame/indexing/test_setitem.py
262 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              from datetime import datetime

import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas.core.dtypes.base import _registry as ea_registry
from pandas.core.dtypes.common import (

            

Reported by Pylint.

Access to a protected member _mgr of a client class
Error

Line: 315 Column: 14

              
        # assert that A & C are not sharing the same base (e.g. they
        # are copies)
        v1 = df._mgr.arrays[1]
        v2 = df._mgr.arrays[2]
        tm.assert_extension_array_equal(v1, v2)
        v1base = v1._data.base
        v2base = v2._data.base
        assert v1base is None or (id(v1base) != id(v2base))

            

Reported by Pylint.

Access to a protected member _mgr of a client class
Error

Line: 316 Column: 14

                      # assert that A & C are not sharing the same base (e.g. they
        # are copies)
        v1 = df._mgr.arrays[1]
        v2 = df._mgr.arrays[2]
        tm.assert_extension_array_equal(v1, v2)
        v1base = v1._data.base
        v2base = v2._data.base
        assert v1base is None or (id(v1base) != id(v2base))


            

Reported by Pylint.

Access to a protected member _data of a client class
Error

Line: 318 Column: 18

                      v1 = df._mgr.arrays[1]
        v2 = df._mgr.arrays[2]
        tm.assert_extension_array_equal(v1, v2)
        v1base = v1._data.base
        v2base = v2._data.base
        assert v1base is None or (id(v1base) != id(v2base))

        # with nan
        df2 = df.copy()

            

Reported by Pylint.

Access to a protected member _data of a client class
Error

Line: 319 Column: 18

                      v2 = df._mgr.arrays[2]
        tm.assert_extension_array_equal(v1, v2)
        v1base = v1._data.base
        v2base = v2._data.base
        assert v1base is None or (id(v1base) != id(v2base))

        # with nan
        df2 = df.copy()
        df2.iloc[1, 1] = NaT

            

Reported by Pylint.

TODO(ArrayManager) .loc still overwrites
Error

Line: 408 Column: 3

              
            expected.columns = cols
            expected["C"] = expected["C"].astype("int64")
            # TODO(ArrayManager) .loc still overwrites
            expected["B"] = expected["B"].astype("int64")
        else:
            # set these with unique columns to be extra-unambiguous
            expected[2] = expected[2].astype(np.int64)
            expected[5] = expected[5].astype(np.int64)

            

Reported by Pylint.

Unused argument 'expected'
Error

Line: 679 Column: 44

                      assert expected.dtype == idx.dtype
        return expected

    def test_setitem_dt64series(self, idx, expected):
        # convert to utc
        df = DataFrame(np.random.randn(2, 1), columns=["A"])
        df["B"] = idx

        with tm.assert_produces_warning(FutureWarning) as m:

            

Reported by Pylint.

TODO(ArrayManager) update parent (_maybe_update_cacher)
Error

Line: 713 Column: 3

              

class TestDataFrameSetItemWithExpansion:
    # TODO(ArrayManager) update parent (_maybe_update_cacher)
    @td.skip_array_manager_not_yet_implemented
    def test_setitem_listlike_views(self):
        # GH#38148
        df = DataFrame({"a": [1, 2, 3], "b": [4, 4, 6]})


            

Reported by Pylint.

Access to a protected member _mgr of a client class
Error

Line: 786 Column: 37

              
        result1 = df["D"]
        result2 = df["E"]
        tm.assert_categorical_equal(result1._mgr.array, cat)

        # sorting
        ser.name = "E"
        tm.assert_series_equal(result2.sort_index(), ser.sort_index())


            

Reported by Pylint.

TODO(ArrayManager) rewrite not using .values
Error

Line: 889 Column: 3

              

class TestDataFrameSetItemBooleanMask:
    @td.skip_array_manager_invalid_test  # TODO(ArrayManager) rewrite not using .values
    @pytest.mark.parametrize(
        "mask_type",
        [lambda df: df > np.abs(df) / 2, lambda df: (df > np.abs(df) / 2).values],
        ids=["dataframe", "array"],
    )

            

Reported by Pylint.

pandas/tests/test_nanops.py
260 issues
Unable to import 'pytest'
Error

Line: 6 Column: 1

              import warnings

import numpy as np
import pytest

import pandas.util._test_decorators as td

from pandas.core.dtypes.common import is_integer_dtype


            

Reported by Pylint.

Unable to import 'scipy.stats'
Error

Line: 373 Column: 9

                  @td.skip_if_no_scipy
    @pytest.mark.parametrize("ddof", range(3))
    def test_nansem(self, ddof, skipna):
        from scipy.stats import sem

        with np.errstate(invalid="ignore"):
            self.check_funs(
                nanops.nansem,
                sem,

            

Reported by Pylint.

Unable to import 'scipy.stats'
Error

Line: 436 Column: 9

              
    @td.skip_if_no_scipy
    def test_nanskew(self, skipna):
        from scipy.stats import skew

        func = partial(self._skew_kurt_wrap, func=skew)
        with np.errstate(invalid="ignore"):
            self.check_funs(
                nanops.nanskew,

            

Reported by Pylint.

Unable to import 'scipy.stats'
Error

Line: 451 Column: 9

              
    @td.skip_if_no_scipy
    def test_nankurt(self, skipna):
        from scipy.stats import kurtosis

        func1 = partial(kurtosis, fisher=True)
        func = partial(self._skew_kurt_wrap, func=func1)
        with np.errstate(invalid="ignore"):
            self.check_funs(

            

Reported by Pylint.

Unable to import 'scipy.stats'
Error

Line: 583 Column: 9

              
    @td.skip_if_no_scipy
    def test_nancorr_kendall(self):
        from scipy.stats import kendalltau

        targ0 = kendalltau(self.arr_float_2d, self.arr_float1_2d)[0]
        targ1 = kendalltau(self.arr_float_2d.flat, self.arr_float1_2d.flat)[0]
        self.check_nancorr_nancov_2d(nanops.nancorr, targ0, targ1, method="kendall")
        targ0 = kendalltau(self.arr_float_1d, self.arr_float1_1d)[0]

            

Reported by Pylint.

Unable to import 'scipy.stats'
Error

Line: 594 Column: 9

              
    @td.skip_if_no_scipy
    def test_nancorr_spearman(self):
        from scipy.stats import spearmanr

        targ0 = spearmanr(self.arr_float_2d, self.arr_float1_2d)[0]
        targ1 = spearmanr(self.arr_float_2d.flat, self.arr_float1_2d.flat)[0]
        self.check_nancorr_nancov_2d(nanops.nancorr, targ0, targ1, method="spearman")
        targ0 = spearmanr(self.arr_float_1d, self.arr_float1_1d)[0]

            

Reported by Pylint.

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

Line: 893 Column: 16

              
    @property
    def prng(self):
        return np.random.RandomState(1234)


class TestNanskewFixedValues:

    # xref GH 11974

            

Reported by Pylint.

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

Line: 942 Column: 16

              
    @property
    def prng(self):
        return np.random.RandomState(1234)


class TestNankurtFixedValues:

    # xref GH 11974

            

Reported by Pylint.

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

Line: 991 Column: 16

              
    @property
    def prng(self):
        return np.random.RandomState(1234)


class TestDatetime64NaNOps:
    # Enabling mean changes the behavior of DataFrame.mean
    # See https://github.com/pandas-dev/pandas/issues/24752

            

Reported by Pylint.

Access to a protected member _USE_BOTTLENECK of a client class
Error

Line: 21 Column: 10

              from pandas.core.arrays import DatetimeArray
import pandas.core.nanops as nanops

use_bn = nanops._USE_BOTTLENECK
has_c16 = hasattr(np, "complex128")


@pytest.fixture(params=[True, False])
def skipna(request):

            

Reported by Pylint.

pandas/tests/series/indexing/test_setitem.py
257 issues
Unable to import 'pytest'
Error

Line: 7 Column: 1

              )

import numpy as np
import pytest

from pandas import (
    Categorical,
    DataFrame,
    DatetimeIndex,

            

Reported by Pylint.

Instance of 'ExtensionIndex' has no 'freq' member
Error

Line: 309 Column: 16

                      ser = Series(dti)
        assert ser._values is not dti
        assert ser._values._data.base is not dti._data._data.base
        assert dti.freq == "D"
        ser.iloc[1] = NaT
        assert ser._values.freq is None

        # check that the DatetimeIndex was not altered in place
        assert ser._values is not dti

            

Reported by Pylint.

Instance of 'Index' has no 'freq' member
Error

Line: 309 Column: 16

                      ser = Series(dti)
        assert ser._values is not dti
        assert ser._values._data.base is not dti._data._data.base
        assert dti.freq == "D"
        ser.iloc[1] = NaT
        assert ser._values.freq is None

        # check that the DatetimeIndex was not altered in place
        assert ser._values is not dti

            

Reported by Pylint.

Instance of 'ExtensionIndex' has no 'freq' member
Error

Line: 317 Column: 16

                      assert ser._values is not dti
        assert ser._values._data.base is not dti._data._data.base
        assert dti[1] == ts
        assert dti.freq == "D"

    def test_dt64tz_setitem_does_not_mutate_dti(self):
        # GH#21907, GH#24096
        dti = date_range("2016-01-01", periods=10, tz="US/Pacific")
        ts = dti[0]

            

Reported by Pylint.

Instance of 'Index' has no 'freq' member
Error

Line: 317 Column: 16

                      assert ser._values is not dti
        assert ser._values._data.base is not dti._data._data.base
        assert dti[1] == ts
        assert dti.freq == "D"

    def test_dt64tz_setitem_does_not_mutate_dti(self):
        # GH#21907, GH#24096
        dti = date_range("2016-01-01", periods=10, tz="US/Pacific")
        ts = dti[0]

            

Reported by Pylint.

Access to a protected member _values of a client class
Error

Line: 307 Column: 16

                      dti = date_range("20130101", periods=3, tz="US/Eastern")
        ts = dti[1]
        ser = Series(dti)
        assert ser._values is not dti
        assert ser._values._data.base is not dti._data._data.base
        assert dti.freq == "D"
        ser.iloc[1] = NaT
        assert ser._values.freq is None


            

Reported by Pylint.

Access to a protected member _data of a client class
Error

Line: 308 Column: 16

                      ts = dti[1]
        ser = Series(dti)
        assert ser._values is not dti
        assert ser._values._data.base is not dti._data._data.base
        assert dti.freq == "D"
        ser.iloc[1] = NaT
        assert ser._values.freq is None

        # check that the DatetimeIndex was not altered in place

            

Reported by Pylint.

Access to a protected member _data of a client class
Error

Line: 308 Column: 46

                      ts = dti[1]
        ser = Series(dti)
        assert ser._values is not dti
        assert ser._values._data.base is not dti._data._data.base
        assert dti.freq == "D"
        ser.iloc[1] = NaT
        assert ser._values.freq is None

        # check that the DatetimeIndex was not altered in place

            

Reported by Pylint.

Access to a protected member _data of a client class
Error

Line: 308 Column: 46

                      ts = dti[1]
        ser = Series(dti)
        assert ser._values is not dti
        assert ser._values._data.base is not dti._data._data.base
        assert dti.freq == "D"
        ser.iloc[1] = NaT
        assert ser._values.freq is None

        # check that the DatetimeIndex was not altered in place

            

Reported by Pylint.

Access to a protected member _values of a client class
Error

Line: 308 Column: 16

                      ts = dti[1]
        ser = Series(dti)
        assert ser._values is not dti
        assert ser._values._data.base is not dti._data._data.base
        assert dti.freq == "D"
        ser.iloc[1] = NaT
        assert ser._values.freq is None

        # check that the DatetimeIndex was not altered in place

            

Reported by Pylint.

pandas/tests/frame/methods/test_replace.py
256 issues
Unable to import 'pytest'
Error

Line: 8 Column: 1

              import re

import numpy as np
import pytest

from pandas.compat import np_version_under1p20

import pandas as pd
from pandas import (

            

Reported by Pylint.

Redefining name 'mix_ab' from outer scope (line 24)
Error

Line: 113 Column: 45

                      expected = DataFrame(expected)
        tm.assert_frame_equal(result, expected)

    def test_regex_replace_list_mixed(self, mix_ab):
        # mixed frame to make sure this doesn't break things
        dfmix = DataFrame(mix_ab)

        # lists of regexes and values
        # list of [re1, re2, ..., reN] -> [v1, v2, ..., vN]

            

Reported by Pylint.

Redefining name 'mix_ab' from outer scope (line 24)
Error

Line: 154 Column: 53

                      expec = DataFrame({"a": mix_ab["a"], "b": ["crap", "b_crap", "..", ".."]})
        tm.assert_frame_equal(res, expec)

    def test_regex_replace_list_mixed_inplace(self, mix_ab):
        dfmix = DataFrame(mix_ab)
        # the same inplace
        # lists of regexes and values
        # list of [re1, re2, ..., reN] -> [v1, v2, ..., vN]
        to_replace_res = [r"\s*\.\s*", r"a"]

            

Reported by Pylint.

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

Line: 194 Column: 45

                      expec = DataFrame({"a": mix_ab["a"], "b": ["crap", "b_crap", "..", ".."]})
        tm.assert_frame_equal(res, expec)

    def test_regex_replace_dict_mixed(self, mix_abc):
        dfmix = DataFrame(mix_abc)

        # dicts
        # single dict {re1: v1}, search the whole frame
        # need test for this...

            

Reported by Pylint.

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

Line: 263 Column: 46

                      tm.assert_frame_equal(res, expec)
        tm.assert_frame_equal(res2, expec)

    def test_regex_replace_dict_nested(self, mix_abc):
        # nested dicts will not work until this is implemented for Series
        dfmix = DataFrame(mix_abc)
        res = dfmix.replace({"b": {r"\s*\.\s*": np.nan}}, regex=True)
        res2 = dfmix.copy()
        res4 = dfmix.copy()

            

Reported by Pylint.

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

Line: 298 Column: 49

                      result = df.replace({"Type": {"Q": 0, "T": 1}})
        tm.assert_frame_equal(result, expected)

    def test_regex_replace_list_to_scalar(self, mix_abc):
        df = DataFrame(mix_abc)
        expec = DataFrame(
            {
                "a": mix_abc["a"],
                "b": np.array([np.nan] * 4),

            

Reported by Pylint.

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

Line: 322 Column: 49

                      tm.assert_frame_equal(res2, expec)
        tm.assert_frame_equal(res3, expec)

    def test_regex_replace_str_to_numeric(self, mix_abc):
        # what happens when you try to replace a numeric value with a regex?
        df = DataFrame(mix_abc)
        res = df.replace(r"\s*\.\s*", 0, regex=True)
        res2 = df.copy()
        return_value = res2.replace(r"\s*\.\s*", 0, inplace=True, regex=True)

            

Reported by Pylint.

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

Line: 337 Column: 56

                      tm.assert_frame_equal(res2, expec)
        tm.assert_frame_equal(res3, expec)

    def test_regex_replace_regex_list_to_numeric(self, mix_abc):
        df = DataFrame(mix_abc)
        res = df.replace([r"\s*\.\s*", "b"], 0, regex=True)
        res2 = df.copy()
        return_value = res2.replace([r"\s*\.\s*", "b"], 0, regex=True, inplace=True)
        assert return_value is None

            

Reported by Pylint.

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

Line: 353 Column: 52

                      tm.assert_frame_equal(res2, expec)
        tm.assert_frame_equal(res3, expec)

    def test_regex_replace_series_of_regexes(self, mix_abc):
        df = DataFrame(mix_abc)
        s1 = Series({"b": r"\s*\.\s*"})
        s2 = Series({"b": np.nan})
        res = df.replace(s1, s2, regex=True)
        res2 = df.copy()

            

Reported by Pylint.

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

Line: 371 Column: 63

                      tm.assert_frame_equal(res2, expec)
        tm.assert_frame_equal(res3, expec)

    def test_regex_replace_numeric_to_object_conversion(self, mix_abc):
        df = DataFrame(mix_abc)
        expec = DataFrame({"a": ["a", 1, 2, 3], "b": mix_abc["b"], "c": mix_abc["c"]})
        res = df.replace(0, "a")
        tm.assert_frame_equal(res, expec)
        assert res.a.dtype == np.object_

            

Reported by Pylint.

pandas/tests/groupby/test_grouping.py
254 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              """ test where we are determining what we are grouping, or getting groups """

import numpy as np
import pytest

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

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 28 Column: 13

                      df = DataFrame([[1, 2]], columns=["A", "B"])
        g = df.groupby("A")
        with pytest.raises(KeyError, match="\"Columns not found: 'C'\""):
            g[["C"]]

        with pytest.raises(KeyError, match="^[^A]+$"):
            # A should not be referenced as a bad column...
            # will have to rethink regex if you change message!
            g[["A", "C"]]

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 33 Column: 13

                      with pytest.raises(KeyError, match="^[^A]+$"):
            # A should not be referenced as a bad column...
            # will have to rethink regex if you change message!
            g[["A", "C"]]

    def test_groupby_duplicated_column_errormsg(self):
        # GH7511
        df = DataFrame(
            columns=["A", "B", "A", "C"], data=[range(4), range(2, 6), range(0, 8, 2)]

            

Reported by Pylint.

Redefining name 'Series' from outer scope (line 7)
Error

Line: 381 Column: 9

              
    def test_groupby_dict_mapping(self):
        # GH #679
        from pandas import Series

        s = Series({"T1": 5})
        result = s.groupby({"T1": "T2"}).agg(sum)
        expected = s.groupby(["T2"]).agg(sum)
        tm.assert_series_equal(result, expected)

            

Reported by Pylint.

Reimport 'Series' (imported line 7)
Error

Line: 381 Column: 9

              
    def test_groupby_dict_mapping(self):
        # GH #679
        from pandas import Series

        s = Series({"T1": 5})
        result = s.groupby({"T1": "T2"}).agg(sum)
        expected = s.groupby(["T2"]).agg(sum)
        tm.assert_series_equal(result, expected)

            

Reported by Pylint.

Access to a protected member _get_axis_name of a client class
Error

Line: 553 Column: 56

                      if axis in (1, "columns"):
            df = df.T
        df.groupby(level="exp", axis=axis)
        msg = f"level name foo is not the name of the {df._get_axis_name(axis)}"
        with pytest.raises(ValueError, match=msg):
            df.groupby(level="foo", axis=axis)

    @pytest.mark.parametrize("sort", [True, False])
    def test_groupby_level_with_nas(self, sort):

            

Reported by Pylint.

TODO: should prob allow a str of Interval work as well
Error

Line: 768 Column: 3

                      bins = [0, 5, 10, 15]
        g = d.groupby(pd.cut(d[0], bins), observed=observed)

        # TODO: should prob allow a str of Interval work as well
        # IOW '(0, 5]'
        result = g.get_group(pd.Interval(0, 5))
        expected = DataFrame([3, 1], index=[0, 1])
        tm.assert_frame_equal(result, expected)


            

Reported by Pylint.

Unused variable 'g'
Error

Line: 865 Column: 13

                      grouped = tsframe.groupby([lambda x: x.weekday(), lambda x: x.year])

        # test it works
        for g in grouped.grouper.groupings[0]:
            pass

    def test_multi_iter(self):
        s = Series(np.arange(6))
        k1 = np.array(["a", "a", "a", "b", "b", "b"])

            

Reported by Pylint.

Unused variable 'key'
Error

Line: 923 Column: 13

                      # axis = 1
        three_levels = three_group.groupby(["A", "B", "C"]).mean()
        grouped = three_levels.T.groupby(axis=1, level=(1, 2))
        for key, group in grouped:
            pass

    def test_dictify(self, df):
        dict(iter(df.groupby("A")))
        dict(iter(df.groupby(["A", "B"])))

            

Reported by Pylint.

Unused variable 'group'
Error

Line: 923 Column: 18

                      # axis = 1
        three_levels = three_group.groupby(["A", "B", "C"]).mean()
        grouped = three_levels.T.groupby(axis=1, level=(1, 2))
        for key, group in grouped:
            pass

    def test_dictify(self, df):
        dict(iter(df.groupby("A")))
        dict(iter(df.groupby(["A", "B"])))

            

Reported by Pylint.