The following issues were found

pandas/tests/indexes/multi/test_monotonic.py
104 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

from pandas import (
    Index,
    MultiIndex,
)



            

Reported by Pylint.

Access to a protected member _is_strictly_monotonic_increasing of a client class
Error

Line: 13 Column: 12

              def test_is_monotonic_increasing():
    i = MultiIndex.from_product([np.arange(10), np.arange(10)], names=["one", "two"])
    assert i.is_monotonic is True
    assert i._is_strictly_monotonic_increasing is True
    assert Index(i.values).is_monotonic is True
    assert i._is_strictly_monotonic_increasing is True

    i = MultiIndex.from_product(
        [np.arange(10, 0, -1), np.arange(10)], names=["one", "two"]

            

Reported by Pylint.

Access to a protected member _is_strictly_monotonic_increasing of a client class
Error

Line: 15 Column: 12

                  assert i.is_monotonic is True
    assert i._is_strictly_monotonic_increasing is True
    assert Index(i.values).is_monotonic is True
    assert i._is_strictly_monotonic_increasing is True

    i = MultiIndex.from_product(
        [np.arange(10, 0, -1), np.arange(10)], names=["one", "two"]
    )
    assert i.is_monotonic is False

            

Reported by Pylint.

Access to a protected member _is_strictly_monotonic_increasing of a client class
Error

Line: 21 Column: 12

                      [np.arange(10, 0, -1), np.arange(10)], names=["one", "two"]
    )
    assert i.is_monotonic is False
    assert i._is_strictly_monotonic_increasing is False
    assert Index(i.values).is_monotonic is False
    assert Index(i.values)._is_strictly_monotonic_increasing is False

    i = MultiIndex.from_product(
        [np.arange(10), np.arange(10, 0, -1)], names=["one", "two"]

            

Reported by Pylint.

Access to a protected member _is_strictly_monotonic_increasing of a client class
Error

Line: 23 Column: 12

                  assert i.is_monotonic is False
    assert i._is_strictly_monotonic_increasing is False
    assert Index(i.values).is_monotonic is False
    assert Index(i.values)._is_strictly_monotonic_increasing is False

    i = MultiIndex.from_product(
        [np.arange(10), np.arange(10, 0, -1)], names=["one", "two"]
    )
    assert i.is_monotonic is False

            

Reported by Pylint.

Access to a protected member _is_strictly_monotonic_increasing of a client class
Error

Line: 29 Column: 12

                      [np.arange(10), np.arange(10, 0, -1)], names=["one", "two"]
    )
    assert i.is_monotonic is False
    assert i._is_strictly_monotonic_increasing is False
    assert Index(i.values).is_monotonic is False
    assert Index(i.values)._is_strictly_monotonic_increasing is False

    i = MultiIndex.from_product([[1.0, np.nan, 2.0], ["a", "b", "c"]])
    assert i.is_monotonic is False

            

Reported by Pylint.

Access to a protected member _is_strictly_monotonic_increasing of a client class
Error

Line: 31 Column: 12

                  assert i.is_monotonic is False
    assert i._is_strictly_monotonic_increasing is False
    assert Index(i.values).is_monotonic is False
    assert Index(i.values)._is_strictly_monotonic_increasing is False

    i = MultiIndex.from_product([[1.0, np.nan, 2.0], ["a", "b", "c"]])
    assert i.is_monotonic is False
    assert i._is_strictly_monotonic_increasing is False
    assert Index(i.values).is_monotonic is False

            

Reported by Pylint.

Access to a protected member _is_strictly_monotonic_increasing of a client class
Error

Line: 35 Column: 12

              
    i = MultiIndex.from_product([[1.0, np.nan, 2.0], ["a", "b", "c"]])
    assert i.is_monotonic is False
    assert i._is_strictly_monotonic_increasing is False
    assert Index(i.values).is_monotonic is False
    assert Index(i.values)._is_strictly_monotonic_increasing is False

    # string ordering
    i = MultiIndex(

            

Reported by Pylint.

Access to a protected member _is_strictly_monotonic_increasing of a client class
Error

Line: 37 Column: 12

                  assert i.is_monotonic is False
    assert i._is_strictly_monotonic_increasing is False
    assert Index(i.values).is_monotonic is False
    assert Index(i.values)._is_strictly_monotonic_increasing is False

    # string ordering
    i = MultiIndex(
        levels=[["foo", "bar", "baz", "qux"], ["one", "two", "three"]],
        codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],

            

Reported by Pylint.

Access to a protected member _is_strictly_monotonic_increasing of a client class
Error

Line: 47 Column: 12

                  )
    assert i.is_monotonic is False
    assert Index(i.values).is_monotonic is False
    assert i._is_strictly_monotonic_increasing is False
    assert Index(i.values)._is_strictly_monotonic_increasing is False

    i = MultiIndex(
        levels=[["bar", "baz", "foo", "qux"], ["mom", "next", "zenith"]],
        codes=[[0, 0, 0, 1, 1, 2, 2, 3, 3, 3], [0, 1, 2, 0, 1, 1, 2, 0, 1, 2]],

            

Reported by Pylint.

pandas/plotting/_matplotlib/converter.py
104 issues
No name 'lib' in module 'pandas._libs'
Error

Line: 24 Column: 1

              import matplotlib.units as units
import numpy as np

from pandas._libs import lib
from pandas._libs.tslibs import (
    Timestamp,
    to_offset,
)
from pandas._libs.tslibs.dtypes import FreqGroup

            

Reported by Pylint.

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

Line: 29 Column: 1

                  Timestamp,
    to_offset,
)
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas._libs.tslibs.offsets import BaseOffset

from pandas.core.dtypes.common import (
    is_float,
    is_float_dtype,

            

Reported by Pylint.

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

Line: 30 Column: 1

                  to_offset,
)
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas._libs.tslibs.offsets import BaseOffset

from pandas.core.dtypes.common import (
    is_float,
    is_float_dtype,
    is_integer,

            

Reported by Pylint.

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

Line: 30 Column: 1

                  to_offset,
)
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas._libs.tslibs.offsets import BaseOffset

from pandas.core.dtypes.common import (
    is_float,
    is_float_dtype,
    is_integer,

            

Reported by Pylint.

Parameters differ from overridden 'convert' method
Error

Line: 157 Column: 5

              
class TimeConverter(units.ConversionInterface):
    @staticmethod
    def convert(value, unit, axis):
        valid_types = (str, pydt.time)
        if isinstance(value, valid_types) or is_integer(value) or is_float(value):
            return time2num(value)
        if isinstance(value, Index):
            return value.map(time2num)

            

Reported by Pylint.

Redefining name 'units' from outer scope (line 21)
Error

Line: 227 Column: 25

              
class PeriodConverter(dates.DateConverter):
    @staticmethod
    def convert(values, units, axis):
        if is_nested_list_like(values):
            values = [PeriodConverter._convert_1d(v, units, axis) for v in values]
        else:
            values = PeriodConverter._convert_1d(values, units, axis)
        return values

            

Reported by Pylint.

Parameters differ from overridden 'convert' method
Error

Line: 227 Column: 5

              
class PeriodConverter(dates.DateConverter):
    @staticmethod
    def convert(values, units, axis):
        if is_nested_list_like(values):
            values = [PeriodConverter._convert_1d(v, units, axis) for v in values]
        else:
            values = PeriodConverter._convert_1d(values, units, axis)
        return values

            

Reported by Pylint.

Unused argument 'units'
Error

Line: 235 Column: 29

                      return values

    @staticmethod
    def _convert_1d(values, units, axis):
        if not hasattr(axis, "freq"):
            raise TypeError("Axis must have `freq` set to convert to Periods")
        valid_types = (str, datetime, Period, pydt.date, pydt.time, np.datetime64)
        if isinstance(values, valid_types) or is_integer(values) or is_float(values):
            return get_datevalue(values, axis.freq)

            

Reported by Pylint.

Redefining name 'units' from outer scope (line 21)
Error

Line: 235 Column: 29

                      return values

    @staticmethod
    def _convert_1d(values, units, axis):
        if not hasattr(axis, "freq"):
            raise TypeError("Axis must have `freq` set to convert to Periods")
        valid_types = (str, datetime, Period, pydt.date, pydt.time, np.datetime64)
        if isinstance(values, valid_types) or is_integer(values) or is_float(values):
            return get_datevalue(values, axis.freq)

            

Reported by Pylint.

Parameters differ from overridden 'convert' method
Error

Line: 273 Column: 5

              # Datetime Conversion
class DatetimeConverter(dates.DateConverter):
    @staticmethod
    def convert(values, unit, axis):
        # values might be a 1-d array, or a list-like of arrays.
        if is_nested_list_like(values):
            values = [DatetimeConverter._convert_1d(v, unit, axis) for v in values]
        else:
            values = DatetimeConverter._convert_1d(values, unit, axis)

            

Reported by Pylint.

versioneer.py
104 issues
Unable to import 'cx_Freeze.dist'
Error

Line: 1641 Column: 9

                  cmds["build_ext"] = cmd_build_ext

    if "cx_Freeze" in sys.modules:  # cx_freeze enabled?
        from cx_Freeze.dist import build_exe as _build_exe

        # nczeczulin reports that py2exe won't like the pep440-style string
        # as FILEVERSION, but it can be used for PRODUCTVERSION, e.g.
        # setup(console=[{
        #   "version": versioneer.get_version().split("+", 1)[0], # FILEVERSION

            

Reported by Pylint.

Unable to import 'py2exe.distutils_buildexe'
Error

Line: 1678 Column: 9

                      del cmds["build_py"]

    if "py2exe" in sys.modules:  # py2exe enabled?
        from py2exe.distutils_buildexe import py2exe as _py2exe

        class cmd_py2exe(_py2exe):
            def run(self):
                root = get_root()
                cfg = get_config_from_root(root)

            

Reported by Pylint.

Attribute 'VCS' defined outside __init__
Error

Line: 349 Column: 5

                      return None

    cfg = VersioneerConfig()
    cfg.VCS = VCS
    cfg.style = get(parser, "style") or ""
    cfg.versionfile_source = get(parser, "versionfile_source")
    cfg.versionfile_build = get(parser, "versionfile_build")
    cfg.tag_prefix = get(parser, "tag_prefix")
    if cfg.tag_prefix in ("''", '""'):

            

Reported by Pylint.

Attribute 'style' defined outside __init__
Error

Line: 350 Column: 5

              
    cfg = VersioneerConfig()
    cfg.VCS = VCS
    cfg.style = get(parser, "style") or ""
    cfg.versionfile_source = get(parser, "versionfile_source")
    cfg.versionfile_build = get(parser, "versionfile_build")
    cfg.tag_prefix = get(parser, "tag_prefix")
    if cfg.tag_prefix in ("''", '""'):
        cfg.tag_prefix = ""

            

Reported by Pylint.

Attribute 'versionfile_source' defined outside __init__
Error

Line: 351 Column: 5

                  cfg = VersioneerConfig()
    cfg.VCS = VCS
    cfg.style = get(parser, "style") or ""
    cfg.versionfile_source = get(parser, "versionfile_source")
    cfg.versionfile_build = get(parser, "versionfile_build")
    cfg.tag_prefix = get(parser, "tag_prefix")
    if cfg.tag_prefix in ("''", '""'):
        cfg.tag_prefix = ""
    cfg.parentdir_prefix = get(parser, "parentdir_prefix")

            

Reported by Pylint.

Attribute 'versionfile_build' defined outside __init__
Error

Line: 352 Column: 5

                  cfg.VCS = VCS
    cfg.style = get(parser, "style") or ""
    cfg.versionfile_source = get(parser, "versionfile_source")
    cfg.versionfile_build = get(parser, "versionfile_build")
    cfg.tag_prefix = get(parser, "tag_prefix")
    if cfg.tag_prefix in ("''", '""'):
        cfg.tag_prefix = ""
    cfg.parentdir_prefix = get(parser, "parentdir_prefix")
    cfg.verbose = get(parser, "verbose")

            

Reported by Pylint.

Attribute 'tag_prefix' defined outside __init__
Error

Line: 353 Column: 5

                  cfg.style = get(parser, "style") or ""
    cfg.versionfile_source = get(parser, "versionfile_source")
    cfg.versionfile_build = get(parser, "versionfile_build")
    cfg.tag_prefix = get(parser, "tag_prefix")
    if cfg.tag_prefix in ("''", '""'):
        cfg.tag_prefix = ""
    cfg.parentdir_prefix = get(parser, "parentdir_prefix")
    cfg.verbose = get(parser, "verbose")
    return cfg

            

Reported by Pylint.

Attribute 'tag_prefix' defined outside __init__
Error

Line: 355 Column: 9

                  cfg.versionfile_build = get(parser, "versionfile_build")
    cfg.tag_prefix = get(parser, "tag_prefix")
    if cfg.tag_prefix in ("''", '""'):
        cfg.tag_prefix = ""
    cfg.parentdir_prefix = get(parser, "parentdir_prefix")
    cfg.verbose = get(parser, "verbose")
    return cfg



            

Reported by Pylint.

Attribute 'parentdir_prefix' defined outside __init__
Error

Line: 356 Column: 5

                  cfg.tag_prefix = get(parser, "tag_prefix")
    if cfg.tag_prefix in ("''", '""'):
        cfg.tag_prefix = ""
    cfg.parentdir_prefix = get(parser, "parentdir_prefix")
    cfg.verbose = get(parser, "verbose")
    return cfg


class NotThisMethod(Exception):

            

Reported by Pylint.

Attribute 'verbose' defined outside __init__
Error

Line: 357 Column: 5

                  if cfg.tag_prefix in ("''", '""'):
        cfg.tag_prefix = ""
    cfg.parentdir_prefix = get(parser, "parentdir_prefix")
    cfg.verbose = get(parser, "verbose")
    return cfg


class NotThisMethod(Exception):
    """Exception raised if a method is not valid for the current scenario."""

            

Reported by Pylint.

pandas/tests/series/indexing/test_indexing.py
104 issues
Unable to import 'pytest'
Error

Line: 6 Column: 1

              import re

import numpy as np
import pytest

from pandas import (
    DataFrame,
    IndexSlice,
    MultiIndex,

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 27 Column: 9

              
    msg = "index 5 is out of bounds for axis 0 with size 5"
    with pytest.raises(IndexError, match=msg):
        s[5]
    with pytest.raises(IndexError, match=msg):
        s[5] = 0

    with pytest.raises(KeyError, match=r"^'c'$"):
        s["c"]

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 32 Column: 9

                      s[5] = 0

    with pytest.raises(KeyError, match=r"^'c'$"):
        s["c"]

    s = s.sort_index()

    with pytest.raises(IndexError, match=msg):
        s[5]

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 37 Column: 9

                  s = s.sort_index()

    with pytest.raises(IndexError, match=msg):
        s[5]
    msg = r"index 5 is out of bounds for axis (0|1) with size 5|^5$"
    with pytest.raises(IndexError, match=msg):
        s[5] = 0



            

Reported by Pylint.

Expression "indexer_sl(ser)[1]" is assigned to nothing
Error

Line: 145 Column: 9

              def test_getitem_ambiguous_keyerror(indexer_sl):
    ser = Series(range(10), index=list(range(0, 20, 2)))
    with pytest.raises(KeyError, match=r"^1$"):
        indexer_sl(ser)[1]


def test_getitem_dups_with_missing(indexer_sl):
    # breaks reindex, so need to use .loc internally
    # GH 4246

            

Reported by Pylint.

Expression "indexer_sl(ser)[['foo', 'bar', 'bah', 'bam']]" is assigned to nothing
Error

Line: 153 Column: 9

                  # GH 4246
    ser = Series([1, 2, 3, 4], ["foo", "bar", "foo", "bah"])
    with pytest.raises(KeyError, match=re.escape("['bam'] not in index")):
        indexer_sl(ser)[["foo", "bar", "bah", "bam"]]


def test_setitem_ambiguous_keyerror(indexer_sl):
    s = Series(range(10), index=list(range(0, 20, 2)))


            

Reported by Pylint.

Unused argument 'string_series'
Error

Line: 166 Column: 35

                  tm.assert_series_equal(s2, expected)


def test_setitem(datetime_series, string_series):
    datetime_series[datetime_series.index[5]] = np.NaN
    datetime_series[[1, 2, 17]] = np.NaN
    datetime_series[6] = np.NaN
    assert np.isnan(datetime_series[6])
    assert np.isnan(datetime_series[2])

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 188 Column: 9

                  # invalid tuples, e.g. td.ts[:, None] vs. td.ts[:, 2]
    msg = "key of type tuple not found and not a MultiIndex"
    with pytest.raises(KeyError, match=msg):
        datetime_series[:, 2]
    with pytest.raises(KeyError, match=msg):
        datetime_series[:, 2] = 2

    # weird lists. [slice(0, 5)] will work but not two slices
    with tm.assert_produces_warning(FutureWarning):

            

Reported by Pylint.

Expression "datetime_series[[5, slice(None, None)]]" is assigned to nothing
Error

Line: 202 Column: 9

                  # OK
    msg = r"unhashable type(: 'slice')?"
    with pytest.raises(TypeError, match=msg):
        datetime_series[[5, slice(None, None)]]
    with pytest.raises(TypeError, match=msg):
        datetime_series[[5, slice(None, None)]] = 2


def test_slice(string_series, object_series):

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 249 Column: 5

                  assert return_value is None
    s = Series([1], index=[(2, 2, 2)])
    df["val"] = 0
    df
    df["val"].update(s)

    expected = DataFrame(
        {"a": [1, 2, 3], "b": [1, 2, 3], "c": [1, 2, 3], "val": [0, 1, 0]}
    )

            

Reported by Pylint.

pandas/tests/series/indexing/test_datetime.py
104 issues
Unable to import 'pytest'
Error

Line: 15 Column: 1

                  tzutc,
)
import numpy as np
import pytest
import pytz

from pandas._libs import index as libindex

import pandas as pd

            

Reported by Pylint.

Unable to import 'pytz'
Error

Line: 16 Column: 1

              )
import numpy as np
import pytest
import pytz

from pandas._libs import index as libindex

import pandas as pd
from pandas import (

            

Reported by Pylint.

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

Line: 18 Column: 1

              import pytest
import pytz

from pandas._libs import index as libindex

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

            

Reported by Pylint.

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

Line: 181 Column: 57

                      # see GH#18376, GH#18162
        ts[(ts.index >= lb) & (ts.index <= rb)]

    lb = Timestamp(datetime(1990, 1, 1, 4)).tz_localize(rng.tzinfo)
    rb = Timestamp(datetime(1990, 1, 1, 7)).tz_localize(rng.tzinfo)
    result = ts[(ts.index >= lb) & (ts.index <= rb)]
    expected = ts[4:8]
    tm.assert_series_equal(result, expected)


            

Reported by Pylint.

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

Line: 181 Column: 57

                      # see GH#18376, GH#18162
        ts[(ts.index >= lb) & (ts.index <= rb)]

    lb = Timestamp(datetime(1990, 1, 1, 4)).tz_localize(rng.tzinfo)
    rb = Timestamp(datetime(1990, 1, 1, 7)).tz_localize(rng.tzinfo)
    result = ts[(ts.index >= lb) & (ts.index <= rb)]
    expected = ts[4:8]
    tm.assert_series_equal(result, expected)


            

Reported by Pylint.

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

Line: 182 Column: 57

                      ts[(ts.index >= lb) & (ts.index <= rb)]

    lb = Timestamp(datetime(1990, 1, 1, 4)).tz_localize(rng.tzinfo)
    rb = Timestamp(datetime(1990, 1, 1, 7)).tz_localize(rng.tzinfo)
    result = ts[(ts.index >= lb) & (ts.index <= rb)]
    expected = ts[4:8]
    tm.assert_series_equal(result, expected)

    result = ts[ts.index[4]]

            

Reported by Pylint.

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

Line: 182 Column: 57

                      ts[(ts.index >= lb) & (ts.index <= rb)]

    lb = Timestamp(datetime(1990, 1, 1, 4)).tz_localize(rng.tzinfo)
    rb = Timestamp(datetime(1990, 1, 1, 7)).tz_localize(rng.tzinfo)
    result = ts[(ts.index >= lb) & (ts.index <= rb)]
    expected = ts[4:8]
    tm.assert_series_equal(result, expected)

    result = ts[ts.index[4]]

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 44 Column: 9

                  assert s[datetime(2009, 1, 2)] == 48
    assert s[Timestamp(datetime(2009, 1, 2))] == 48
    with pytest.raises(KeyError, match=r"^'2009-1-3'$"):
        s["2009-1-3"]
    tm.assert_series_equal(
        s["3/6/2009":"2009-06-05"], s[datetime(2009, 3, 6) : datetime(2009, 6, 5)]
    )



            

Reported by Pylint.

TODO: do the same with Timestamps and dt64
Error

Line: 140 Column: 3

                  tm.assert_series_equal(result, expected)

    # But we do not give datetimes a pass on tzawareness compat
    # TODO: do the same with Timestamps and dt64
    msg = "Cannot compare tz-naive and tz-aware datetime-like objects"
    naive = datetime(1990, 1, 1, 4)
    with tm.assert_produces_warning(FutureWarning):
        # GH#36148 will require tzawareness compat
        result = ts[naive]

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 179 Column: 9

                  with pytest.raises(TypeError, match=msg):
        # tznaive vs tzaware comparison is invalid
        # see GH#18376, GH#18162
        ts[(ts.index >= lb) & (ts.index <= rb)]

    lb = Timestamp(datetime(1990, 1, 1, 4)).tz_localize(rng.tzinfo)
    rb = Timestamp(datetime(1990, 1, 1, 7)).tz_localize(rng.tzinfo)
    result = ts[(ts.index >= lb) & (ts.index <= rb)]
    expected = ts[4:8]

            

Reported by Pylint.

pandas/core/dtypes/cast.py
103 issues
No name 'lib' in module 'pandas._libs'
Error

Line: 26 Column: 1

              
import numpy as np

from pandas._libs import lib
from pandas._libs.tslibs import (
    NaT,
    OutOfBoundsDatetime,
    OutOfBoundsTimedelta,
    Timedelta,

            

Reported by Pylint.

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

Line: 27 Column: 1

              import numpy as np

from pandas._libs import lib
from pandas._libs.tslibs import (
    NaT,
    OutOfBoundsDatetime,
    OutOfBoundsTimedelta,
    Timedelta,
    Timestamp,

            

Reported by Pylint.

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

Line: 35 Column: 1

                  Timestamp,
    conversion,
)
from pandas._libs.tslibs.timedeltas import array_to_timedelta64
from pandas._typing import (
    ArrayLike,
    Dtype,
    DtypeObj,
    Scalar,

            

Reported by Pylint.

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

Line: 35 Column: 1

                  Timestamp,
    conversion,
)
from pandas._libs.tslibs.timedeltas import array_to_timedelta64
from pandas._typing import (
    ArrayLike,
    Dtype,
    DtypeObj,
    Scalar,

            

Reported by Pylint.

Access to a protected member _values of a client class
Error

Line: 143 Column: 51

                  return bool(
        isinstance(obj, ABCSeries)
        and is_object_dtype(obj.dtype)
        and any(isinstance(v, ABCSeries) for v in obj._values)
    )


def maybe_box_datetimelike(value: Scalar, dtype: Dtype | None = None) -> Scalar:
    """

            

Reported by Pylint.

TODO: complex? what if result is already non-object?
Error

Line: 267 Column: 3

                                  do_round = True

            else:
                # TODO: complex?  what if result is already non-object?
                dtype = "object"

        dtype = np.dtype(dtype)

    if not isinstance(dtype, np.dtype):

            

Reported by Pylint.

TODO: avoid this special-casing
Error

Line: 390 Column: 3

              
    if isinstance(dtype, ExtensionDtype):
        if not isinstance(dtype, (CategoricalDtype, DatetimeTZDtype)):
            # TODO: avoid this special-casing
            # We have to special case categorical so as not to upcast
            # things like counts back to categorical

            cls = dtype.construct_array_type()
            if same_dtype:

            

Reported by Pylint.

Access to a protected member _from_sequence of a client class
Error

Line: 434 Column: 18

                      return obj

    try:
        result = cls._from_sequence(obj, dtype=dtype)
    except Exception:
        # We can't predict what downstream EA constructors may raise
        result = obj
    return result


            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 435 Column: 12

              
    try:
        result = cls._from_sequence(obj, dtype=dtype)
    except Exception:
        # We can't predict what downstream EA constructors may raise
        result = obj
    return result



            

Reported by Pylint.

TODO: ExtensionDtype.can_hold_na?
Error

Line: 456 Column: 3

                  If we have a dtype that cannot hold NA values, find the best match that can.
    """
    if isinstance(dtype, ExtensionDtype):
        # TODO: ExtensionDtype.can_hold_na?
        return dtype
    elif dtype.kind == "b":
        return np.dtype(object)
    elif dtype.kind in ["i", "u"]:
        return np.dtype(np.float64)

            

Reported by Pylint.

pandas/tests/indexing/test_categorical.py
101 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              import re

import numpy as np
import pytest

from pandas.core.dtypes.common import is_categorical_dtype

import pandas as pd
from pandas import (

            

Reported by Pylint.

Unused argument 'method'
Error

Line: 24 Column: 28

              

class TestCategoricalIndex:
    def setup_method(self, method):

        self.df = DataFrame(
            {
                "A": np.arange(6, dtype="int64"),
            },

            

Reported by Pylint.

Attribute 'df' defined outside __init__
Error

Line: 26 Column: 9

              class TestCategoricalIndex:
    def setup_method(self, method):

        self.df = DataFrame(
            {
                "A": np.arange(6, dtype="int64"),
            },
            index=CategoricalIndex(list("aabbca"), dtype=CDT(list("cab")), name="B"),
        )

            

Reported by Pylint.

Attribute 'df2' defined outside __init__
Error

Line: 32 Column: 9

                          },
            index=CategoricalIndex(list("aabbca"), dtype=CDT(list("cab")), name="B"),
        )
        self.df2 = DataFrame(
            {
                "A": np.arange(6, dtype="int64"),
            },
            index=CategoricalIndex(list("aabbca"), dtype=CDT(list("cabe")), name="B"),
        )

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 62 Column: 13

              
        # value not in the categories
        with pytest.raises(KeyError, match=r"^'d'$"):
            df.loc["d"]

        df2 = df.copy()
        expected = df2.copy()
        expected.index = expected.index.astype(object)
        expected.loc["d"] = 10

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 102 Column: 13

              
    def test_loc_getitem_scalar_non_category(self):
        with pytest.raises(KeyError, match="^1$"):
            self.df.loc[1]

    def test_slicing(self):
        cat = Series(Categorical([1, 2, 3, 4]))
        reverse = cat[::-1]
        exp = np.array([4, 3, 2, 1], dtype=np.int64)

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 300 Column: 13

                      # GH#37901 a label that is in index.categories but not in index
        # listlike containing an element in the categories but not in the values
        with pytest.raises(KeyError, match=re.escape("['e'] not in index")):
            self.df2.loc[["a", "b", "e"]]

    def test_loc_getitem_label_unused_category(self):
        # element in the categories but not in the values
        with pytest.raises(KeyError, match=r"^'e'$"):
            self.df2.loc["e"]

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 305 Column: 13

                  def test_loc_getitem_label_unused_category(self):
        # element in the categories but not in the values
        with pytest.raises(KeyError, match=r"^'e'$"):
            self.df2.loc["e"]

    def test_loc_getitem_non_category(self):
        # not all labels in the categories
        with pytest.raises(KeyError, match=re.escape("['d'] not in index")):
            self.df2.loc[["a", "d"]]

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 310 Column: 13

                  def test_loc_getitem_non_category(self):
        # not all labels in the categories
        with pytest.raises(KeyError, match=re.escape("['d'] not in index")):
            self.df2.loc[["a", "d"]]

    def test_loc_setitem_expansion_label_unused_category(self):
        # assigning with a label that is in the categories but not in the index
        df = self.df2.copy()
        df.loc["e"] = 20

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 342 Column: 13

                      tm.assert_frame_equal(res, exp, check_index_type=True)

        with pytest.raises(KeyError, match=re.escape("['x'] not in index")):
            df.loc[["a", "x"]]

    def test_loc_listlike_dtypes_duplicated_categories_and_codes(self):
        # duplicated categories and codes
        index = CategoricalIndex(["a", "b", "a"])
        df = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=index)

            

Reported by Pylint.

pandas/tests/frame/indexing/test_xs.py
100 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              import re

import numpy as np
import pytest

from pandas import (
    DataFrame,
    Index,
    IndexSlice,

            

Reported by Pylint.

TODO: more descriptive name
Error

Line: 133 Column: 3

              
class TestXSWithMultiIndex:
    def test_xs_doc_example(self):
        # TODO: more descriptive name
        # based on example in advanced.rst
        arrays = [
            ["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"],
            ["one", "two", "one", "two", "one", "two", "one", "two"],
        ]

            

Reported by Pylint.

Redefining name 'four_level_index_dataframe' from outer scope (line 21)
Error

Line: 189 Column: 56

                      with pytest.raises(com.SettingWithCopyError, match=msg):
            result[:] = 10

    def test_xs_setting_with_copy_error_multiple(self, four_level_index_dataframe):
        # this is a copy in 0.14
        df = four_level_index_dataframe
        result = df.xs(("a", 4), level=["one", "four"])

        # setting this will give a SettingWithCopyError

            

Reported by Pylint.

Redefining name 'four_level_index_dataframe' from outer scope (line 21)
Error

Line: 263 Column: 47

                          lambda df: df.xs("a").xs(4, level="four"),
        ],
    )
    def test_xs_level_multiple(self, indexer, four_level_index_dataframe):
        df = four_level_index_dataframe
        expected_values = [[0.4473, 1.4152, 0.2834, 1.00661, 0.1744]]
        expected_index = MultiIndex(
            levels=[["q"], [20.0]], codes=[[0], [0]], names=["two", "three"]
        )

            

Reported by Pylint.

Redefining name 'four_level_index_dataframe' from outer scope (line 21)
Error

Line: 278 Column: 39

                  @pytest.mark.parametrize(
        "indexer", [lambda df: df.xs("a", level=0), lambda df: df.xs("a")]
    )
    def test_xs_level0(self, indexer, four_level_index_dataframe):
        df = four_level_index_dataframe
        expected_values = [
            [-0.5109, -2.3358, -0.4645, 0.05076, 0.364],
            [0.4473, 1.4152, 0.2834, 1.00661, 0.1744],
        ]

            

Reported by Pylint.

Access to a protected member _values of a client class
Error

Line: 366 Column: 60

                      df = DataFrame([[1, 2, 3]], columns=Index(["a", "b", "c"]))
        result = df.xs("a", axis=1, drop_level=False)
        # check that result still views the same data as df
        assert np.shares_memory(result.iloc[:, 0]._values, df.iloc[:, 0]._values)
        # modifying original df also modifies result when having a single block
        df.iloc[0, 0] = 2
        if not using_array_manager:
            expected = DataFrame({"a": [2]})
        else:

            

Reported by Pylint.

Access to a protected member _values of a client class
Error

Line: 366 Column: 33

                      df = DataFrame([[1, 2, 3]], columns=Index(["a", "b", "c"]))
        result = df.xs("a", axis=1, drop_level=False)
        # check that result still views the same data as df
        assert np.shares_memory(result.iloc[:, 0]._values, df.iloc[:, 0]._values)
        # modifying original df also modifies result when having a single block
        df.iloc[0, 0] = 2
        if not using_array_manager:
            expected = DataFrame({"a": [2]})
        else:

            

Reported by Pylint.

TODO(ArrayManager) iloc does not update the array inplace using
Error

Line: 372 Column: 3

                      if not using_array_manager:
            expected = DataFrame({"a": [2]})
        else:
            # TODO(ArrayManager) iloc does not update the array inplace using
            # "split" path
            expected = DataFrame({"a": [1]})
        tm.assert_frame_equal(result, expected)

        # with mixed dataframe, modifying the parent doesn't modify result

            

Reported by Pylint.

TODO the "split" path behaves differently here as with single block
Error

Line: 378 Column: 3

                      tm.assert_frame_equal(result, expected)

        # with mixed dataframe, modifying the parent doesn't modify result
        # TODO the "split" path behaves differently here as with single block
        df = DataFrame([[1, 2.5, "a"]], columns=Index(["a", "b", "c"]))
        result = df.xs("a", axis=1, drop_level=False)
        df.iloc[0, 0] = 2
        expected = DataFrame({"a": [1]})
        tm.assert_frame_equal(result, expected)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import re

import numpy as np
import pytest

from pandas import (
    DataFrame,
    Index,
    IndexSlice,

            

Reported by Pylint.

pandas/tests/io/formats/test_info.py
100 issues
Unable to import 'pytest'
Error

Line: 8 Column: 1

              import textwrap

import numpy as np
import pytest

from pandas.compat import (
    IS64,
    PYPY,
)

            

Reported by Pylint.

Unused variable 'rest'
Error

Line: 174 Column: 37

                  # Here table would contain only header, separator and table lines
    # dframe repr, index summary, memory usage and dtypes are excluded
    table = all_lines[3:-2]
    header, separator, first_line, *rest, last_line = table
    assert header == header_exp
    assert separator == separator_exp
    assert first_line == first_line_exp
    assert last_line == last_line_exp


            

Reported by Pylint.

Redefining built-in 'bytes'
Error

Line: 187 Column: 5

                  buf = StringIO()
    df.info(buf=buf)
    result = buf.getvalue()
    bytes = float(df.memory_usage().sum())
    expected = textwrap.dedent(
        f"""\
    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 2 entries, 0 to 1
    Data columns (total 1 columns):

            

Reported by Pylint.

Expression "DataFrame(1, index=['a'], columns=['A']).index.nbytes" is assigned to nothing
Error

Line: 366 Column: 5

              
    # test for validity
    DataFrame(1, index=["a"], columns=["A"]).memory_usage(index=True)
    DataFrame(1, index=["a"], columns=["A"]).index.nbytes
    df = DataFrame(
        data=1, index=MultiIndex.from_product([["a"], range(1000)]), columns=["A"]
    )
    df.index.nbytes
    df.memory_usage(index=True)

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 370 Column: 5

                  df = DataFrame(
        data=1, index=MultiIndex.from_product([["a"], range(1000)]), columns=["A"]
    )
    df.index.nbytes
    df.memory_usage(index=True)
    df.index.values.nbytes

    mem = df.memory_usage(deep=True).sum()
    assert mem > 0

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 372 Column: 5

                  )
    df.index.nbytes
    df.memory_usage(index=True)
    df.index.values.nbytes

    mem = df.memory_usage(deep=True).sum()
    assert mem > 0



            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from io import StringIO
import re
from string import ascii_uppercase as uppercase
import sys
import textwrap

import numpy as np
import pytest


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 31 Column: 1

                  return DataFrame(np.random.randn(1500, 4), columns=["a", "a", "b", "b"])


def test_info_empty():
    df = DataFrame()
    buf = StringIO()
    df.info(buf=buf)
    result = buf.getvalue()
    expected = textwrap.dedent(

            

Reported by Pylint.

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

Line: 32 Column: 5

              

def test_info_empty():
    df = DataFrame()
    buf = StringIO()
    df.info(buf=buf)
    result = buf.getvalue()
    expected = textwrap.dedent(
        """\

            

Reported by Pylint.

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

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

                      Index: 0 entries
        Empty DataFrame"""
    )
    assert result == expected


def test_info_categorical_column_smoke_test():
    n = 2500
    df = DataFrame({"int64": np.random.randint(100, size=n)})

            

Reported by Bandit.

pandas/tests/indexes/timedeltas/test_indexing.py
100 issues
Unable to import 'pytest'
Error

Line: 8 Column: 1

              import re

import numpy as np
import pytest

from pandas import (
    Index,
    NaT,
    Timedelta,

            

Reported by Pylint.

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

Line: 47 Column: 35

                          result = idx[0:5]
            expected = timedelta_range("1 day", "5 day", freq="D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            result = idx[0:10:2]
            expected = timedelta_range("1 day", "9 day", freq="2D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            

Reported by Pylint.

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

Line: 47 Column: 35

                          result = idx[0:5]
            expected = timedelta_range("1 day", "5 day", freq="D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            result = idx[0:10:2]
            expected = timedelta_range("1 day", "9 day", freq="2D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            

Reported by Pylint.

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

Line: 52 Column: 35

                          result = idx[0:10:2]
            expected = timedelta_range("1 day", "9 day", freq="2D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            result = idx[-20:-5:3]
            expected = timedelta_range("12 day", "24 day", freq="3D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            

Reported by Pylint.

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

Line: 52 Column: 35

                          result = idx[0:10:2]
            expected = timedelta_range("1 day", "9 day", freq="2D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            result = idx[-20:-5:3]
            expected = timedelta_range("12 day", "24 day", freq="3D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            

Reported by Pylint.

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

Line: 57 Column: 35

                          result = idx[-20:-5:3]
            expected = timedelta_range("12 day", "24 day", freq="3D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            result = idx[4::-1]
            expected = TimedeltaIndex(
                ["5 day", "4 day", "3 day", "2 day", "1 day"], freq="-1D", name="idx"
            )

            

Reported by Pylint.

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

Line: 57 Column: 35

                          result = idx[-20:-5:3]
            expected = timedelta_range("12 day", "24 day", freq="3D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            result = idx[4::-1]
            expected = TimedeltaIndex(
                ["5 day", "4 day", "3 day", "2 day", "1 day"], freq="-1D", name="idx"
            )

            

Reported by Pylint.

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

Line: 64 Column: 35

                              ["5 day", "4 day", "3 day", "2 day", "1 day"], freq="-1D", name="idx"
            )
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

    @pytest.mark.parametrize(
        "key",
        [
            Timestamp("1970-01-01"),

            

Reported by Pylint.

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

Line: 213 Column: 35

                          result = idx.take([0, 1, 2])
            expected = timedelta_range("1 day", "3 day", freq="D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            result = idx.take([0, 2, 4])
            expected = timedelta_range("1 day", "5 day", freq="2D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            

Reported by Pylint.

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

Line: 213 Column: 35

                          result = idx.take([0, 1, 2])
            expected = timedelta_range("1 day", "3 day", freq="D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            result = idx.take([0, 2, 4])
            expected = timedelta_range("1 day", "5 day", freq="2D", name="idx")
            tm.assert_index_equal(result, expected)
            assert result.freq == expected.freq

            

Reported by Pylint.