The following issues were found

pandas/tests/indexes/multi/test_get_level_values.py
16 issues
Non-iterable value idx2.levels is used in an iterating context
Error

Line: 114 Column: 40

                  idx2 = MultiIndex.from_arrays(
        [idx._get_level_values(level) for level in range(idx.nlevels)]
    )
    assert all(x.is_monotonic for x in idx2.levels)

            

Reported by Pylint.

Access to a protected member _get_level_values of a client class
Error

Line: 112 Column: 10

                      [PeriodIndex([Period("2019Q1"), Period("2019Q2")], name="b")]
    )
    idx2 = MultiIndex.from_arrays(
        [idx._get_level_values(level) for level in range(idx.nlevels)]
    )
    assert all(x.is_monotonic for x in idx2.levels)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np

import pandas as pd
from pandas import (
    CategoricalIndex,
    Index,
    MultiIndex,
    Timestamp,
    date_range,

            

Reported by Pylint.

Missing class docstring
Error

Line: 14 Column: 1

              import pandas._testing as tm


class TestGetLevelValues:
    def test_get_level_values_box_datetime64(self):

        dates = date_range("1/1/2000", periods=4)
        levels = [dates, [0, 1]]
        codes = [[0, 0, 1, 1, 2, 2, 3, 3], [0, 1, 0, 1, 0, 1, 0, 1]]

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 14 Column: 1

              import pandas._testing as tm


class TestGetLevelValues:
    def test_get_level_values_box_datetime64(self):

        dates = date_range("1/1/2000", periods=4)
        levels = [dates, [0, 1]]
        codes = [[0, 0, 1, 1, 2, 2, 3, 3], [0, 1, 0, 1, 0, 1, 0, 1]]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 5

              

class TestGetLevelValues:
    def test_get_level_values_box_datetime64(self):

        dates = date_range("1/1/2000", periods=4)
        levels = [dates, [0, 1]]
        codes = [[0, 0, 1, 1, 2, 2, 3, 3], [0, 1, 0, 1, 0, 1, 0, 1]]


            

Reported by Pylint.

Method could be a function
Error

Line: 15 Column: 5

              

class TestGetLevelValues:
    def test_get_level_values_box_datetime64(self):

        dates = date_range("1/1/2000", periods=4)
        levels = [dates, [0, 1]]
        codes = [[0, 0, 1, 1, 2, 2, 3, 3], [0, 1, 0, 1, 0, 1, 0, 1]]


            

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

              
        index = MultiIndex(levels=levels, codes=codes)

        assert isinstance(index.get_level_values(0)[0], Timestamp)


def test_get_level_values(idx):
    result = idx.get_level_values(0)
    expected = Index(["foo", "foo", "bar", "baz", "qux", "qux"], name="first")

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 26 Column: 1

                      assert isinstance(index.get_level_values(0)[0], Timestamp)


def test_get_level_values(idx):
    result = idx.get_level_values(0)
    expected = Index(["foo", "foo", "bar", "baz", "qux", "qux"], name="first")
    tm.assert_index_equal(result, expected)
    assert result.name == "first"


            

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

                  result = idx.get_level_values(0)
    expected = Index(["foo", "foo", "bar", "baz", "qux", "qux"], name="first")
    tm.assert_index_equal(result, expected)
    assert result.name == "first"

    result = idx.get_level_values("first")
    expected = idx.get_level_values(0)
    tm.assert_index_equal(result, expected)


            

Reported by Bandit.

asv_bench/benchmarks/tslibs/tz_convert.py
16 issues
Unable to import 'pytz'
Error

Line: 2 Column: 1

              import numpy as np
from pytz import UTC

from pandas._libs.tslibs.tzconversion import tz_localize_to_utc

from .tslib import (
    _sizes,
    _tzs,
    tzlocal_obj,

            

Reported by Pylint.

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

Line: 4 Column: 1

              import numpy as np
from pytz import UTC

from pandas._libs.tslibs.tzconversion import tz_localize_to_utc

from .tslib import (
    _sizes,
    _tzs,
    tzlocal_obj,

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 6 Column: 1

              
from pandas._libs.tslibs.tzconversion import tz_localize_to_utc

from .tslib import (
    _sizes,
    _tzs,
    tzlocal_obj,
)


            

Reported by Pylint.

Attribute 'i8data' defined outside __init__
Error

Line: 33 Column: 9

                          raise NotImplementedError

        arr = np.random.randint(0, 10, size=size, dtype="i8")
        self.i8data = arr

    def time_tz_convert_from_utc(self, size, tz):
        # effectively:
        #  dti = DatetimeIndex(self.i8data, tz=tz)
        #  dti.tz_localize(None)

            

Reported by Pylint.

Unused argument 'size'
Error

Line: 35 Column: 40

                      arr = np.random.randint(0, 10, size=size, dtype="i8")
        self.i8data = arr

    def time_tz_convert_from_utc(self, size, tz):
        # effectively:
        #  dti = DatetimeIndex(self.i8data, tz=tz)
        #  dti.tz_localize(None)
        if old_sig:
            tz_convert_from_utc(self.i8data, UTC, tz)

            

Reported by Pylint.

Unused argument 'size'
Error

Line: 44 Column: 39

                      else:
            tz_convert_from_utc(self.i8data, tz)

    def time_tz_localize_to_utc(self, size, tz):
        # effectively:
        #  dti = DatetimeIndex(self.i8data)
        #  dti.tz_localize(tz, ambiguous="NaT", nonexistent="NaT")
        tz_localize_to_utc(self.i8data, tz, ambiguous="NaT", nonexistent="NaT")

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
from pytz import UTC

from pandas._libs.tslibs.tzconversion import tz_localize_to_utc

from .tslib import (
    _sizes,
    _tzs,
    tzlocal_obj,

            

Reported by Pylint.

Constant name "old_sig" doesn't conform to UPPER_CASE naming style
Error

Line: 13 Column: 5

              )

try:
    old_sig = False
    from pandas._libs.tslibs.tzconversion import tz_convert_from_utc
except ImportError:
    old_sig = True
    from pandas._libs.tslibs.tzconversion import tz_convert as tz_convert_from_utc


            

Reported by Pylint.

Constant name "old_sig" doesn't conform to UPPER_CASE naming style
Error

Line: 16 Column: 5

                  old_sig = False
    from pandas._libs.tslibs.tzconversion import tz_convert_from_utc
except ImportError:
    old_sig = True
    from pandas._libs.tslibs.tzconversion import tz_convert as tz_convert_from_utc


class TimeTZConvert:
    params = [

            

Reported by Pylint.

Missing class docstring
Error

Line: 20 Column: 1

                  from pandas._libs.tslibs.tzconversion import tz_convert as tz_convert_from_utc


class TimeTZConvert:
    params = [
        _sizes,
        [x for x in _tzs if x is not None],
    ]
    param_names = ["size", "tz"]

            

Reported by Pylint.

pandas/tests/arrays/sparse/test_combine_concat.py
16 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

import pandas as pd
import pandas._testing as tm
from pandas.core.arrays.sparse import SparseArray


class TestSparseArrayConcat:

            

Reported by Pylint.

Access to a protected member _concat_same_type of a client class
Error

Line: 15 Column: 18

                      a = SparseArray([1, 0, 0, 2], kind=kind)
        b = SparseArray([1, 0, 2, 2], kind=kind)

        result = SparseArray._concat_same_type([a, b])
        # Can't make any assertions about the sparse index itself
        # since we aren't don't merge sparse blocs across arrays
        # in to_concat
        expected = np.array([1, 2, 1, 2, 2], dtype="int64")
        tm.assert_numpy_array_equal(result.sp_values, expected)

            

Reported by Pylint.

Access to a protected member _concat_same_type of a client class
Error

Line: 29 Column: 18

                      a = SparseArray([1, 0, 0, 2], kind=kind)
        b = SparseArray([1, 0, 2, 2], kind=other)

        result = SparseArray._concat_same_type([a, b])
        expected = np.array([1, 2, 1, 2, 2], dtype="int64")
        tm.assert_numpy_array_equal(result.sp_values, expected)
        assert result.kind == kind



            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

import pandas as pd
import pandas._testing as tm
from pandas.core.arrays.sparse import SparseArray


class TestSparseArrayConcat:

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              from pandas.core.arrays.sparse import SparseArray


class TestSparseArrayConcat:
    @pytest.mark.parametrize("kind", ["integer", "block"])
    def test_basic(self, kind):
        a = SparseArray([1, 0, 0, 2], kind=kind)
        b = SparseArray([1, 0, 2, 2], kind=kind)


            

Reported by Pylint.

Method could be a function
Error

Line: 11 Column: 5

              
class TestSparseArrayConcat:
    @pytest.mark.parametrize("kind", ["integer", "block"])
    def test_basic(self, kind):
        a = SparseArray([1, 0, 0, 2], kind=kind)
        b = SparseArray([1, 0, 2, 2], kind=kind)

        result = SparseArray._concat_same_type([a, b])
        # Can't make any assertions about the sparse index itself

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 5

              
class TestSparseArrayConcat:
    @pytest.mark.parametrize("kind", ["integer", "block"])
    def test_basic(self, kind):
        a = SparseArray([1, 0, 0, 2], kind=kind)
        b = SparseArray([1, 0, 2, 2], kind=kind)

        result = SparseArray._concat_same_type([a, b])
        # Can't make any assertions about the sparse index itself

            

Reported by Pylint.

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

Line: 12 Column: 9

              class TestSparseArrayConcat:
    @pytest.mark.parametrize("kind", ["integer", "block"])
    def test_basic(self, kind):
        a = SparseArray([1, 0, 0, 2], kind=kind)
        b = SparseArray([1, 0, 2, 2], kind=kind)

        result = SparseArray._concat_same_type([a, b])
        # Can't make any assertions about the sparse index itself
        # since we aren't don't merge sparse blocs across arrays

            

Reported by Pylint.

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

Line: 13 Column: 9

                  @pytest.mark.parametrize("kind", ["integer", "block"])
    def test_basic(self, kind):
        a = SparseArray([1, 0, 0, 2], kind=kind)
        b = SparseArray([1, 0, 2, 2], kind=kind)

        result = SparseArray._concat_same_type([a, b])
        # Can't make any assertions about the sparse index itself
        # since we aren't don't merge sparse blocs across arrays
        # in to_concat

            

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

                      # in to_concat
        expected = np.array([1, 2, 1, 2, 2], dtype="int64")
        tm.assert_numpy_array_equal(result.sp_values, expected)
        assert result.kind == kind

    @pytest.mark.parametrize("kind", ["integer", "block"])
    def test_uses_first_kind(self, kind):
        other = "integer" if kind == "block" else "block"
        a = SparseArray([1, 0, 0, 2], kind=kind)

            

Reported by Bandit.

pandas/tests/arrays/interval/test_ops.py
16 issues
Unable to import 'pytest'
Error

Line: 3 Column: 1

              """Tests for Interval-Interval operations, such as overlaps, contains, etc."""
import numpy as np
import pytest

from pandas import (
    Interval,
    IntervalIndex,
    Timedelta,
    Timestamp,

            

Reported by Pylint.

Redefining name 'constructor' from outer scope (line 16)
Error

Line: 40 Column: 38

              

class TestOverlaps:
    def test_overlaps_interval(self, constructor, start_shift, closed, other_closed):
        start, shift = start_shift
        interval = Interval(start, start + 3 * shift, other_closed)

        # intervals: identical, nested, spanning, partial, adjacent, disjoint
        tuples = [

            

Reported by Pylint.

Redefining name 'start_shift' from outer scope (line 30)
Error

Line: 40 Column: 51

              

class TestOverlaps:
    def test_overlaps_interval(self, constructor, start_shift, closed, other_closed):
        start, shift = start_shift
        interval = Interval(start, start + 3 * shift, other_closed)

        # intervals: identical, nested, spanning, partial, adjacent, disjoint
        tuples = [

            

Reported by Pylint.

Redefining name 'constructor' from outer scope (line 16)
Error

Line: 61 Column: 48

                      tm.assert_numpy_array_equal(result, expected)

    @pytest.mark.parametrize("other_constructor", [IntervalArray, IntervalIndex])
    def test_overlaps_interval_container(self, constructor, other_constructor):
        # TODO: modify this test when implemented
        interval_container = constructor.from_breaks(range(5))
        other_container = other_constructor.from_breaks(range(5))
        with pytest.raises(NotImplementedError, match="^$"):
            interval_container.overlaps(other_container)

            

Reported by Pylint.

TODO: modify this test when implemented
Error

Line: 62 Column: 3

              
    @pytest.mark.parametrize("other_constructor", [IntervalArray, IntervalIndex])
    def test_overlaps_interval_container(self, constructor, other_constructor):
        # TODO: modify this test when implemented
        interval_container = constructor.from_breaks(range(5))
        other_container = other_constructor.from_breaks(range(5))
        with pytest.raises(NotImplementedError, match="^$"):
            interval_container.overlaps(other_container)


            

Reported by Pylint.

Redefining name 'constructor' from outer scope (line 16)
Error

Line: 68 Column: 32

                      with pytest.raises(NotImplementedError, match="^$"):
            interval_container.overlaps(other_container)

    def test_overlaps_na(self, constructor, start_shift):
        """NA values are marked as False"""
        start, shift = start_shift
        interval = Interval(start, start + shift)

        tuples = [

            

Reported by Pylint.

Redefining name 'start_shift' from outer scope (line 30)
Error

Line: 68 Column: 45

                      with pytest.raises(NotImplementedError, match="^$"):
            interval_container.overlaps(other_container)

    def test_overlaps_na(self, constructor, start_shift):
        """NA values are marked as False"""
        start, shift = start_shift
        interval = Interval(start, start + shift)

        tuples = [

            

Reported by Pylint.

Redefining name 'constructor' from outer scope (line 16)
Error

Line: 89 Column: 42

                      [10, True, "foo", Timedelta("1 day"), Timestamp("2018-01-01")],
        ids=lambda x: type(x).__name__,
    )
    def test_overlaps_invalid_type(self, constructor, other):
        interval_container = constructor.from_breaks(range(5))
        msg = f"`other` must be Interval-like, got {type(other).__name__}"
        with pytest.raises(TypeError, match=msg):
            interval_container.overlaps(other)

            

Reported by Pylint.

Missing class docstring
Error

Line: 39 Column: 1

                  return request.param


class TestOverlaps:
    def test_overlaps_interval(self, constructor, start_shift, closed, other_closed):
        start, shift = start_shift
        interval = Interval(start, start + 3 * shift, other_closed)

        # intervals: identical, nested, spanning, partial, adjacent, disjoint

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 40 Column: 5

              

class TestOverlaps:
    def test_overlaps_interval(self, constructor, start_shift, closed, other_closed):
        start, shift = start_shift
        interval = Interval(start, start + 3 * shift, other_closed)

        # intervals: identical, nested, spanning, partial, adjacent, disjoint
        tuples = [

            

Reported by Pylint.

pandas/core/array_algos/quantile.py
16 issues
TODO(EA2D): make-believe not needed with 2D EAs
Error

Line: 133 Column: 3

                  -------
    ExtensionArray
    """
    # TODO(EA2D): make-believe not needed with 2D EAs
    orig = values

    # asarray needed for Sparse, see GH#24600
    mask = np.asarray(values.isna())
    mask = np.atleast_2d(mask)

            

Reported by Pylint.

Access to a protected member _values_for_factorize of a client class
Error

Line: 140 Column: 23

                  mask = np.asarray(values.isna())
    mask = np.atleast_2d(mask)

    arr, fill_value = values._values_for_factorize()
    arr = np.atleast_2d(arr)

    result = _quantile_with_mask(arr, mask, fill_value, qs, interpolation)

    if not is_sparse(orig.dtype):

            

Reported by Pylint.

Access to a protected member _from_factorized of a client class
Error

Line: 150 Column: 22

              
        if orig.ndim == 2:
            # i.e. DatetimeArray
            result = type(orig)._from_factorized(result, orig)

        else:
            assert result.shape == (1, len(qs)), result.shape
            result = type(orig)._from_factorized(result[0], orig)


            

Reported by Pylint.

Access to a protected member _from_factorized of a client class
Error

Line: 154 Column: 22

              
        else:
            assert result.shape == (1, len(qs)), result.shape
            result = type(orig)._from_factorized(result[0], orig)

    # error: Incompatible return value type (got "ndarray", expected "ExtensionArray")
    return result  # type: ignore[return-value]



            

Reported by Pylint.

Access to a protected member _from_sequence of a client class
Error

Line: 185 Column: 15

                  assert res.shape[0] == 1
    res = res[0]
    try:
        out = type(values)._from_sequence(res, dtype=values.dtype)
    except TypeError:
        # GH#42626: not able to safely cast Int64
        # for floating point output
        out = np.atleast_2d(np.asarray(res, dtype=np.float64))
    return out

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np

from pandas._typing import ArrayLike

from pandas.core.dtypes.common import is_sparse

            

Reported by Pylint.

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

Line: 21 Column: 1

                  from pandas.core.arrays import ExtensionArray


def quantile_compat(values: ArrayLike, qs: np.ndarray, interpolation: str) -> ArrayLike:
    """
    Compute the quantiles of the given values for each quantile in `qs`.

    Parameters
    ----------

            

Reported by Pylint.

Unnecessary "else" after "return"
Error

Line: 35 Column: 5

                  -------
    np.ndarray or ExtensionArray
    """
    if isinstance(values, np.ndarray):
        fill_value = na_value_for_dtype(values.dtype, compat=False)
        mask = isna(values)
        return _quantile_with_mask(values, mask, fill_value, qs, interpolation)
    else:
        # In general we don't want to import from arrays here;

            

Reported by Pylint.

Import outside toplevel (pandas.core.arrays.BaseMaskedArray)
Error

Line: 42 Column: 9

                  else:
        # In general we don't want to import from arrays here;
        #  this is temporary pending discussion in GH#41428
        from pandas.core.arrays import BaseMaskedArray

        if isinstance(values, BaseMaskedArray):
            # e.g. IntegerArray, does not implement _from_factorized
            out = _quantile_ea_fallback(values, qs, interpolation)


            

Reported by Pylint.

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

Line: 54 Column: 1

                      return out


def _quantile_with_mask(
    values: np.ndarray,
    mask: np.ndarray,
    fill_value,
    qs: np.ndarray,
    interpolation: str,

            

Reported by Pylint.

pandas/tests/arrays/categorical/test_sorting.py
16 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

from pandas import (
    Categorical,
    Index,
)
import pandas._testing as tm


            

Reported by Pylint.

Access to a protected member _codes of a client class
Error

Line: 72 Column: 22

              
        # sort (inplace order)
        cat1 = cat.copy()
        orig_codes = cat1._codes
        cat1.sort_values(inplace=True)
        assert cat1._codes is orig_codes
        exp = np.array(["a", "b", "c", "d"], dtype=object)
        tm.assert_numpy_array_equal(cat1.__array__(), exp)
        tm.assert_index_equal(res.categories, cat.categories)

            

Reported by Pylint.

Access to a protected member _codes of a client class
Error

Line: 74 Column: 16

                      cat1 = cat.copy()
        orig_codes = cat1._codes
        cat1.sort_values(inplace=True)
        assert cat1._codes is orig_codes
        exp = np.array(["a", "b", "c", "d"], dtype=object)
        tm.assert_numpy_array_equal(cat1.__array__(), exp)
        tm.assert_index_equal(res.categories, cat.categories)

        # reverse

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

from pandas import (
    Categorical,
    Index,
)
import pandas._testing as tm


            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              import pandas._testing as tm


class TestCategoricalSort:
    def test_argsort(self):
        c = Categorical([5, 3, 1, 4, 2], ordered=True)

        expected = np.array([2, 4, 1, 3, 0])
        tm.assert_numpy_array_equal(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 5

              

class TestCategoricalSort:
    def test_argsort(self):
        c = Categorical([5, 3, 1, 4, 2], ordered=True)

        expected = np.array([2, 4, 1, 3, 0])
        tm.assert_numpy_array_equal(
            c.argsort(ascending=True), expected, check_dtype=False

            

Reported by Pylint.

Method could be a function
Error

Line: 12 Column: 5

              

class TestCategoricalSort:
    def test_argsort(self):
        c = Categorical([5, 3, 1, 4, 2], ordered=True)

        expected = np.array([2, 4, 1, 3, 0])
        tm.assert_numpy_array_equal(
            c.argsort(ascending=True), expected, check_dtype=False

            

Reported by Pylint.

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

Line: 13 Column: 9

              
class TestCategoricalSort:
    def test_argsort(self):
        c = Categorical([5, 3, 1, 4, 2], ordered=True)

        expected = np.array([2, 4, 1, 3, 0])
        tm.assert_numpy_array_equal(
            c.argsort(ascending=True), expected, check_dtype=False
        )

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 25 Column: 5

                          c.argsort(ascending=False), expected, check_dtype=False
        )

    def test_numpy_argsort(self):
        c = Categorical([5, 3, 1, 4, 2], ordered=True)

        expected = np.array([2, 4, 1, 3, 0])
        tm.assert_numpy_array_equal(np.argsort(c), expected, check_dtype=False)


            

Reported by Pylint.

Method could be a function
Error

Line: 25 Column: 5

                          c.argsort(ascending=False), expected, check_dtype=False
        )

    def test_numpy_argsort(self):
        c = Categorical([5, 3, 1, 4, 2], ordered=True)

        expected = np.array([2, 4, 1, 3, 0])
        tm.assert_numpy_array_equal(np.argsort(c), expected, check_dtype=False)


            

Reported by Pylint.

pandas/tests/indexes/datetimes/test_unique.py
16 issues
Unable to import 'pytest'
Error

Line: 6 Column: 1

                  timedelta,
)

import pytest

from pandas import (
    DatetimeIndex,
    NaT,
    Timestamp,

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from datetime import (
    datetime,
    timedelta,
)

import pytest

from pandas import (
    DatetimeIndex,

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 1

                      (
            DatetimeIndex(["2017", "2017"], tz="US/Eastern"),
            DatetimeIndex(["2017"], tz="US/Eastern"),
        ),
    ],
)
def test_unique(arr, expected):
    result = arr.unique()
    tm.assert_index_equal(result, expected)

            

Reported by Pylint.

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

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

                  tm.assert_index_equal(result, expected)
    # GH#21737
    # Ensure the underlying data is consistent
    assert result[0] == expected[0]


def test_index_unique(rand_series_with_duplicate_datetimeindex):
    dups = rand_series_with_duplicate_datetimeindex
    index = dups.index

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 34 Column: 1

                  assert result[0] == expected[0]


def test_index_unique(rand_series_with_duplicate_datetimeindex):
    dups = rand_series_with_duplicate_datetimeindex
    index = dups.index

    uniques = index.unique()
    expected = DatetimeIndex(

            

Reported by Pylint.

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

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

                          datetime(2000, 1, 5),
        ]
    )
    assert uniques.dtype == "M8[ns]"  # sanity
    tm.assert_index_equal(uniques, expected)
    assert index.nunique() == 4

    # GH#2563
    assert isinstance(uniques, DatetimeIndex)

            

Reported by Bandit.

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

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

                  )
    assert uniques.dtype == "M8[ns]"  # sanity
    tm.assert_index_equal(uniques, expected)
    assert index.nunique() == 4

    # GH#2563
    assert isinstance(uniques, DatetimeIndex)

    dups_local = index.tz_localize("US/Eastern")

            

Reported by Bandit.

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

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

                  assert index.nunique() == 4

    # GH#2563
    assert isinstance(uniques, DatetimeIndex)

    dups_local = index.tz_localize("US/Eastern")
    dups_local.name = "foo"
    result = dups_local.unique()
    expected = DatetimeIndex(expected, name="foo")

            

Reported by Bandit.

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

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

                  result = dups_local.unique()
    expected = DatetimeIndex(expected, name="foo")
    expected = expected.tz_localize("US/Eastern")
    assert result.tz is not None
    assert result.name == "foo"
    tm.assert_index_equal(result, expected)

    # NaT, note this is excluded
    arr = [1370745748 + t for t in range(20)] + [NaT.value]

            

Reported by Bandit.

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

                  expected = DatetimeIndex(expected, name="foo")
    expected = expected.tz_localize("US/Eastern")
    assert result.tz is not None
    assert result.name == "foo"
    tm.assert_index_equal(result, expected)

    # NaT, note this is excluded
    arr = [1370745748 + t for t in range(20)] + [NaT.value]
    idx = DatetimeIndex(arr * 3)

            

Reported by Bandit.

pandas/io/formats/latex.py
16 issues
Using possibly undefined loop variable 'pad'
Error

Line: 162 Column: 56

                              for pad in reversed(x):
                    if pad:
                        break
                return [x[0]] + [i if i else " " * len(pad) for i in x[1:]]

            gen = (pad_empties(i) for i in out)

            # Add empty spaces for each column level
            clevels = self.frame.columns.nlevels

            

Reported by Pylint.

Access to a protected member _values of a client class
Error

Line: 779 Column: 18

                              return "r"
            return "l"

        dtypes = self.frame.dtypes._values
        return "".join(map(get_col_type, dtypes))

    def _get_index_format(self) -> str:
        """Get index column format."""
        return "l" * self.frame.index.nlevels if self.fmt.index else ""

            

Reported by Pylint.

Too many instance attributes (8/7)
Error

Line: 55 Column: 1

                  return full_caption, short_caption


class RowStringConverter(ABC):
    r"""Converter for dataframe rows into LaTeX strings.

    Parameters
    ----------
    formatter : `DataFrameFormatter`

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 130 Column: 5

                      return self.frame.index.nlevels

    @property
    def column_levels(self) -> int:
        return self.frame.columns.nlevels

    @property
    def header_levels(self) -> int:
        nlevels = self.column_levels

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 134 Column: 5

                      return self.frame.columns.nlevels

    @property
    def header_levels(self) -> int:
        nlevels = self.column_levels
        if self.fmt.has_index_names and self.fmt.show_index_names:
            nlevels += 1
        return nlevels


            

Reported by Pylint.

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

Line: 158 Column: 13

              
            # index.format will sparsify repeated entries with empty strings
            # so pad these with some empty space
            def pad_empties(x):
                for pad in reversed(x):
                    if pad:
                        break
                return [x[0]] + [i if i else " " * len(pad) for i in x[1:]]


            

Reported by Pylint.

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

Line: 223 Column: 13

                          else:
                row2.append(coltext)

        for c in row[self.index_levels :]:
            # if next col has text, write the previous
            if c.strip():
                if coltext:
                    append_col()
                coltext = c

            

Reported by Pylint.

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

Line: 251 Column: 21

                      for j in range(self.index_levels):
            if row[j].strip():
                nrow = 1
                for r in self.strrows[i + 1 :]:
                    if not r[j].strip():
                        nrow += 1
                    else:
                        break
                if nrow > 1:

            

Reported by Pylint.

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

Line: 268 Column: 13

                      Create clines after multirow-blocks are finished.
        """
        lst = []
        for cl in self.clinebuf:
            if cl[0] == i:
                lst.append(f"\n\\cline{{{cl[1]:d}-{icol:d}}}")
                # remove entries that have been written to buffer
                self.clinebuf = [x for x in self.clinebuf if x[0] != i]
        return "".join(lst)

            

Reported by Pylint.

Too many instance attributes (9/7)
Error

Line: 302 Column: 1

                              yield self.get_strrow(row_num)


class TableBuilderAbstract(ABC):
    """
    Abstract table builder producing string representation of LaTeX table.

    Parameters
    ----------

            

Reported by Pylint.

pandas/plotting/_misc.py
16 issues
Unused argument 'colLabels'
Error

Line: 6 Column: 37

              from pandas.plotting._core import _get_plot_backend


def table(ax, data, rowLabels=None, colLabels=None, **kwargs):
    """
    Helper function to convert DataFrame and Series to matplotlib.table.

    Parameters
    ----------

            

Reported by Pylint.

Unused argument 'rowLabels'
Error

Line: 6 Column: 21

              from pandas.plotting._core import _get_plot_backend


def table(ax, data, rowLabels=None, colLabels=None, **kwargs):
    """
    Helper function to convert DataFrame and Series to matplotlib.table.

    Parameters
    ----------

            

Reported by Pylint.

__init__ method from base class 'dict' is not called
Error

Line: 501 Column: 5

                  _ALIASES = {"x_compat": "xaxis.compat"}
    _DEFAULT_KEYS = ["xaxis.compat"]

    def __init__(self, deprecated=False):
        self._deprecated = deprecated
        super().__setitem__("xaxis.compat", False)

    def __getitem__(self, key):
        key = self._get_canonical_key(key)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from contextlib import contextmanager

from pandas.plotting._core import _get_plot_backend


def table(ax, data, rowLabels=None, colLabels=None, **kwargs):
    """
    Helper function to convert DataFrame and Series to matplotlib.table.


            

Reported by Pylint.

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

Line: 6 Column: 1

              from pandas.plotting._core import _get_plot_backend


def table(ax, data, rowLabels=None, colLabels=None, **kwargs):
    """
    Helper function to convert DataFrame and Series to matplotlib.table.

    Parameters
    ----------

            

Reported by Pylint.

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

Line: 6 Column: 1

              from pandas.plotting._core import _get_plot_backend


def table(ax, data, rowLabels=None, colLabels=None, **kwargs):
    """
    Helper function to convert DataFrame and Series to matplotlib.table.

    Parameters
    ----------

            

Reported by Pylint.

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

Line: 6 Column: 1

              from pandas.plotting._core import _get_plot_backend


def table(ax, data, rowLabels=None, colLabels=None, **kwargs):
    """
    Helper function to convert DataFrame and Series to matplotlib.table.

    Parameters
    ----------

            

Reported by Pylint.

Too many arguments (10/5)
Error

Line: 72 Column: 1

                  plot_backend.deregister()


def scatter_matrix(
    frame,
    alpha=0.5,
    figsize=None,
    ax=None,
    grid=False,

            

Reported by Pylint.

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

Line: 72 Column: 1

                  plot_backend.deregister()


def scatter_matrix(
    frame,
    alpha=0.5,
    figsize=None,
    ax=None,
    grid=False,

            

Reported by Pylint.

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

Line: 143 Column: 1

                  )


def radviz(frame, class_column, ax=None, color=None, colormap=None, **kwds):
    """
    Plot a multidimensional dataset in 2D.

    Each Series in the DataFrame is represented as a evenly distributed
    slice on a circle. Each data point is rendered in the circle according to

            

Reported by Pylint.

pandas/tests/indexes/base_class/test_indexing.py
16 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

from pandas import Index
import pandas._testing as tm


class TestGetSliceBounds:
    @pytest.mark.parametrize("kind", ["getitem", "loc", None])

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

from pandas import Index
import pandas._testing as tm


class TestGetSliceBounds:
    @pytest.mark.parametrize("kind", ["getitem", "loc", None])

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              import pandas._testing as tm


class TestGetSliceBounds:
    @pytest.mark.parametrize("kind", ["getitem", "loc", None])
    @pytest.mark.parametrize("side, expected", [("left", 4), ("right", 5)])
    def test_get_slice_bounds_within(self, kind, side, expected):
        index = Index(list("abcdef"))
        with tm.assert_produces_warning(FutureWarning, match="'kind' argument"):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 11 Column: 5

              class TestGetSliceBounds:
    @pytest.mark.parametrize("kind", ["getitem", "loc", None])
    @pytest.mark.parametrize("side, expected", [("left", 4), ("right", 5)])
    def test_get_slice_bounds_within(self, kind, side, expected):
        index = Index(list("abcdef"))
        with tm.assert_produces_warning(FutureWarning, match="'kind' argument"):
            result = index.get_slice_bound("e", kind=kind, side=side)
        assert result == expected


            

Reported by Pylint.

Method could be a function
Error

Line: 11 Column: 5

              class TestGetSliceBounds:
    @pytest.mark.parametrize("kind", ["getitem", "loc", None])
    @pytest.mark.parametrize("side, expected", [("left", 4), ("right", 5)])
    def test_get_slice_bounds_within(self, kind, side, expected):
        index = Index(list("abcdef"))
        with tm.assert_produces_warning(FutureWarning, match="'kind' argument"):
            result = index.get_slice_bound("e", kind=kind, side=side)
        assert result == expected


            

Reported by Pylint.

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

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

                      index = Index(list("abcdef"))
        with tm.assert_produces_warning(FutureWarning, match="'kind' argument"):
            result = index.get_slice_bound("e", kind=kind, side=side)
        assert result == expected

    @pytest.mark.parametrize("kind", ["getitem", "loc", None])
    @pytest.mark.parametrize("side", ["left", "right"])
    @pytest.mark.parametrize(
        "data, bound, expected", [(list("abcdef"), "x", 6), (list("bcdefg"), "a", 0)]

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 21 Column: 5

                  @pytest.mark.parametrize("side", ["left", "right"])
    @pytest.mark.parametrize(
        "data, bound, expected", [(list("abcdef"), "x", 6), (list("bcdefg"), "a", 0)]
    )
    def test_get_slice_bounds_outside(self, kind, side, expected, data, bound):
        index = Index(data)
        with tm.assert_produces_warning(FutureWarning, match="'kind' argument"):
            result = index.get_slice_bound(bound, kind=kind, side=side)
        assert result == expected

            

Reported by Pylint.

Too many arguments (6/5)
Error

Line: 21 Column: 5

                  @pytest.mark.parametrize("side", ["left", "right"])
    @pytest.mark.parametrize(
        "data, bound, expected", [(list("abcdef"), "x", 6), (list("bcdefg"), "a", 0)]
    )
    def test_get_slice_bounds_outside(self, kind, side, expected, data, bound):
        index = Index(data)
        with tm.assert_produces_warning(FutureWarning, match="'kind' argument"):
            result = index.get_slice_bound(bound, kind=kind, side=side)
        assert result == expected

            

Reported by Pylint.

Method could be a function
Error

Line: 21 Column: 5

                  @pytest.mark.parametrize("side", ["left", "right"])
    @pytest.mark.parametrize(
        "data, bound, expected", [(list("abcdef"), "x", 6), (list("bcdefg"), "a", 0)]
    )
    def test_get_slice_bounds_outside(self, kind, side, expected, data, bound):
        index = Index(data)
        with tm.assert_produces_warning(FutureWarning, match="'kind' argument"):
            result = index.get_slice_bound(bound, kind=kind, side=side)
        assert result == expected

            

Reported by Pylint.

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

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

                      index = Index(data)
        with tm.assert_produces_warning(FutureWarning, match="'kind' argument"):
            result = index.get_slice_bound(bound, kind=kind, side=side)
        assert result == expected

    def test_get_slice_bounds_invalid_side(self):
        with pytest.raises(ValueError, match="Invalid value for side kwarg"):
            Index([]).get_slice_bound("a", side="middle")


            

Reported by Bandit.