The following issues were found

pandas/tests/groupby/test_nth.py
80 issues
Unable to import 'pytest'
Error

Line: 2 Column: 1

              import numpy as np
import pytest

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

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import pytest

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

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 1

              import pandas._testing as tm


def test_first_last_nth(df):
    # tests for first / last / nth
    grouped = df.groupby("A")
    first = grouped.first()
    expected = df.loc[[1, 0], ["B", "C", "D"]]
    expected.index = Index(["bar", "foo"], name="A")

            

Reported by Pylint.

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

Line: 16 Column: 1

              import pandas._testing as tm


def test_first_last_nth(df):
    # tests for first / last / nth
    grouped = df.groupby("A")
    first = grouped.first()
    expected = df.loc[[1, 0], ["B", "C", "D"]]
    expected.index = Index(["bar", "foo"], name="A")

            

Reported by Pylint.

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

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

                  grouped["B"].nth(0)

    df.loc[df["A"] == "foo", "B"] = np.nan
    assert isna(grouped["B"].first()["foo"])
    assert isna(grouped["B"].last()["foo"])
    assert isna(grouped["B"].nth(0)["foo"])

    # v0.14.0 whatsnew
    df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=["A", "B"])

            

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

              
    df.loc[df["A"] == "foo", "B"] = np.nan
    assert isna(grouped["B"].first()["foo"])
    assert isna(grouped["B"].last()["foo"])
    assert isna(grouped["B"].nth(0)["foo"])

    # v0.14.0 whatsnew
    df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=["A", "B"])
    g = df.groupby("A")

            

Reported by Bandit.

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

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

                  df.loc[df["A"] == "foo", "B"] = np.nan
    assert isna(grouped["B"].first()["foo"])
    assert isna(grouped["B"].last()["foo"])
    assert isna(grouped["B"].nth(0)["foo"])

    # v0.14.0 whatsnew
    df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=["A", "B"])
    g = df.groupby("A")
    result = g.first()

            

Reported by Bandit.

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

Line: 54 Column: 5

              
    # v0.14.0 whatsnew
    df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=["A", "B"])
    g = df.groupby("A")
    result = g.first()
    expected = df.iloc[[1, 2]].set_index("A")
    tm.assert_frame_equal(result, expected)

    expected = df.iloc[[1, 2]].set_index("A")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 65 Column: 1

              

@pytest.mark.parametrize("method", ["first", "last"])
def test_first_last_with_na_object(method, nulls_fixture):
    # https://github.com/pandas-dev/pandas/issues/32123
    groups = DataFrame({"a": [1, 1, 2, 2], "b": [1, 2, 3, nulls_fixture]}).groupby("a")
    result = getattr(groups, method)()

    if method == "first":

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 83 Column: 1

              

@pytest.mark.parametrize("index", [0, -1])
def test_nth_with_na_object(index, nulls_fixture):
    # https://github.com/pandas-dev/pandas/issues/32123
    groups = DataFrame({"a": [1, 1, 2, 2], "b": [1, 2, 3, nulls_fixture]}).groupby("a")
    result = groups.nth(index)

    if index == 0:

            

Reported by Pylint.

pandas/tests/strings/test_strings.py
80 issues
Unable to import 'pytest'
Error

Line: 7 Column: 1

              )

import numpy as np
import pytest

from pandas import (
    DataFrame,
    Index,
    MultiIndex,

            

Reported by Pylint.

Using possibly undefined loop variable 's'
Error

Line: 47 Column: 12

                  # desired behavior is to iterate until everything would be nan on the
    # next iter so make sure the last element of the iterator was 'l' in
    # this case since 'wikitravel' is the longest string
    assert s.dropna().values.item() == "l"


def test_iter_empty(any_string_dtype):
    ser = Series([], dtype=any_string_dtype)


            

Reported by Pylint.

Using possibly undefined loop variable 'i'
Error

Line: 72 Column: 16

                      for i, s in enumerate(ser.str):
            pass

    assert not i
    tm.assert_series_equal(ser, s)


def test_iter_object_try_string():
    ser = Series(

            

Reported by Pylint.

Using possibly undefined loop variable 's'
Error

Line: 73 Column: 33

                          pass

    assert not i
    tm.assert_series_equal(ser, s)


def test_iter_object_try_string():
    ser = Series(
        [

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 680 Column: 9

              
    msg = "Can only use .str accessor with string values"
    with pytest.raises(AttributeError, match=msg):
        obj.str


def test_index_str_accessor_multiindex_raises():
    # MultiIndex has mixed dtype, but not allow to use accessor
    idx = MultiIndex.from_tuples([("a", "b"), ("a", "b")])

            

Reported by Pylint.

Comparing against a callable, did you omit the parenthesis?
Error

Line: 686 Column: 12

              def test_index_str_accessor_multiindex_raises():
    # MultiIndex has mixed dtype, but not allow to use accessor
    idx = MultiIndex.from_tuples([("a", "b"), ("a", "b")])
    assert idx.inferred_type == "mixed"

    msg = "Can only use .str accessor with Index, not MultiIndex"
    with pytest.raises(AttributeError, match=msg):
        idx.str


            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 690 Column: 9

              
    msg = "Can only use .str accessor with Index, not MultiIndex"
    with pytest.raises(AttributeError, match=msg):
        idx.str


def test_str_accessor_no_new_attributes(any_string_dtype):
    # https://github.com/pandas-dev/pandas/issues/10673
    ser = Series(list("aabbcde"), dtype=any_string_dtype)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from datetime import (
    datetime,
    timedelta,
)

import numpy as np
import pytest

from pandas import (

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

              import pandas._testing as tm


def assert_series_or_index_equal(left, right):
    if isinstance(left, Series):
        tm.assert_series_equal(left, right)
    else:  # Index
        tm.assert_index_equal(left, right)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 1

                      tm.assert_index_equal(left, right)


def test_iter():
    # GH3638
    strs = "google", "wikimedia", "wikipedia", "wikitravel"
    ser = Series(strs)

    with tm.assert_produces_warning(FutureWarning):

            

Reported by Pylint.

pandas/tests/strings/test_split_partition.py
80 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              from datetime import datetime

import numpy as np
import pytest

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

            

Reported by Pylint.

TODO see GH 18463
Error

Line: 350 Column: 3

                  tm.assert_frame_equal(result, exp)

    # check that these are actually np.nan/pd.NA and not None
    # TODO see GH 18463
    # tm.assert_frame_equal does not differentiate
    if any_string_dtype == "object":
        assert all(np.isnan(x) for x in result.iloc[1])
    else:
        assert all(x is pd.NA for x in result.iloc[1])

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from datetime import datetime

import numpy as np
import pytest

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

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 1

              )


def test_split(any_string_dtype):
    values = Series(["a_b_c", "c_d_e", np.nan, "f_g_h"], dtype=any_string_dtype)

    result = values.str.split("_")
    exp = Series([["a", "b", "c"], ["c", "d", "e"], np.nan, ["f", "g", "h"]])
    tm.assert_series_equal(result, exp)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 38 Column: 1

                  tm.assert_series_equal(result, exp)


def test_split_object_mixed():
    mixed = Series(["a_b_c", np.nan, "d_e_f", True, datetime.today(), None, 1, 2.0])
    result = mixed.str.split("_")
    exp = Series(
        [
            ["a", "b", "c"],

            

Reported by Pylint.

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

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

                          np.nan,
        ]
    )
    assert isinstance(result, Series)
    tm.assert_almost_equal(result, exp)

    result = mixed.str.split("_", expand=False)
    assert isinstance(result, Series)
    tm.assert_almost_equal(result, exp)

            

Reported by Bandit.

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

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

                  tm.assert_almost_equal(result, exp)

    result = mixed.str.split("_", expand=False)
    assert isinstance(result, Series)
    tm.assert_almost_equal(result, exp)


@pytest.mark.parametrize("method", ["split", "rsplit"])
def test_split_n(any_string_dtype, method):

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 62 Column: 1

              

@pytest.mark.parametrize("method", ["split", "rsplit"])
def test_split_n(any_string_dtype, method):
    s = Series(["a b", pd.NA, "b c"], dtype=any_string_dtype)
    expected = Series([["a", "b"], pd.NA, ["b", "c"]])

    result = getattr(s.str, method)(" ", n=None)
    tm.assert_series_equal(result, expected)

            

Reported by Pylint.

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

Line: 63 Column: 5

              
@pytest.mark.parametrize("method", ["split", "rsplit"])
def test_split_n(any_string_dtype, method):
    s = Series(["a b", pd.NA, "b c"], dtype=any_string_dtype)
    expected = Series([["a", "b"], pd.NA, ["b", "c"]])

    result = getattr(s.str, method)(" ", n=None)
    tm.assert_series_equal(result, expected)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 73 Column: 1

                  tm.assert_series_equal(result, expected)


def test_rsplit(any_string_dtype):
    values = Series(["a_b_c", "c_d_e", np.nan, "f_g_h"], dtype=any_string_dtype)
    result = values.str.rsplit("_")
    exp = Series([["a", "b", "c"], ["c", "d", "e"], np.nan, ["f", "g", "h"]])
    tm.assert_series_equal(result, exp)


            

Reported by Pylint.

pandas/core/arrays/period.py
79 issues
No name 'arrays' in module 'pandas._libs'
Error

Line: 14 Column: 1

              
import numpy as np

from pandas._libs.arrays import NDArrayBacked
from pandas._libs.tslibs import (
    BaseOffset,
    NaT,
    NaTType,
    Timedelta,

            

Reported by Pylint.

Unable to import 'pandas._libs.arrays'
Error

Line: 14 Column: 1

              
import numpy as np

from pandas._libs.arrays import NDArrayBacked
from pandas._libs.tslibs import (
    BaseOffset,
    NaT,
    NaTType,
    Timedelta,

            

Reported by Pylint.

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

Line: 15 Column: 1

              import numpy as np

from pandas._libs.arrays import NDArrayBacked
from pandas._libs.tslibs import (
    BaseOffset,
    NaT,
    NaTType,
    Timedelta,
    delta_to_nanoseconds,

            

Reported by Pylint.

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

Line: 15 Column: 1

              import numpy as np

from pandas._libs.arrays import NDArrayBacked
from pandas._libs.tslibs import (
    BaseOffset,
    NaT,
    NaTType,
    Timedelta,
    delta_to_nanoseconds,

            

Reported by Pylint.

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

Line: 27 Column: 1

                  period as libperiod,
    to_offset,
)
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas._libs.tslibs.fields import isleapyear_arr
from pandas._libs.tslibs.offsets import (
    Tick,
    delta_to_tick,
)

            

Reported by Pylint.

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

Line: 28 Column: 1

                  to_offset,
)
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas._libs.tslibs.fields import isleapyear_arr
from pandas._libs.tslibs.offsets import (
    Tick,
    delta_to_tick,
)
from pandas._libs.tslibs.period import (

            

Reported by Pylint.

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

Line: 28 Column: 1

                  to_offset,
)
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas._libs.tslibs.fields import isleapyear_arr
from pandas._libs.tslibs.offsets import (
    Tick,
    delta_to_tick,
)
from pandas._libs.tslibs.period import (

            

Reported by Pylint.

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

Line: 29 Column: 1

              )
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas._libs.tslibs.fields import isleapyear_arr
from pandas._libs.tslibs.offsets import (
    Tick,
    delta_to_tick,
)
from pandas._libs.tslibs.period import (
    DIFFERENT_FREQ,

            

Reported by Pylint.

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

Line: 29 Column: 1

              )
from pandas._libs.tslibs.dtypes import FreqGroup
from pandas._libs.tslibs.fields import isleapyear_arr
from pandas._libs.tslibs.offsets import (
    Tick,
    delta_to_tick,
)
from pandas._libs.tslibs.period import (
    DIFFERENT_FREQ,

            

Reported by Pylint.

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

Line: 33 Column: 1

                  Tick,
    delta_to_tick,
)
from pandas._libs.tslibs.period import (
    DIFFERENT_FREQ,
    IncompatibleFrequency,
    Period,
    get_period_field_arr,
    period_asfreq_arr,

            

Reported by Pylint.

pandas/tests/io/pytables/test_select.py
79 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              from warnings import catch_warnings

import numpy as np
import pytest

from pandas._libs.tslibs import Timestamp

import pandas as pd
from pandas import (

            

Reported by Pylint.

Unused variable 'np_zero'
Error

Line: 268 Column: 9

                      expected = df[df["A"] > 0]

        store.append("df", df, data_columns=True)
        np_zero = np.float64(0)  # noqa
        result = store.select("df", where=["A>np_zero"])
        tm.assert_frame_equal(expected, result)


def test_select_with_many_inputs(setup_path):

            

Reported by Pylint.

Unused argument 'setup_path'
Error

Line: 662 Column: 32

                      tm.assert_frame_equal(result, expected)


def test_frame_select_complex2(setup_path):

    with ensure_clean_path(["params.hdf", "hist.hdf"]) as paths:

        pp, hh = paths


            

Reported by Pylint.

Unused variable 'l'
Error

Line: 686 Column: 9

                      expected = read_hdf(hh, "df", where="l1=[2, 3, 4]")

        # scope with list like
        l = selection.index.tolist()  # noqa
        store = HDFStore(hh)
        result = store.select("df", where="l1=l")
        tm.assert_frame_equal(result, expected)
        store.close()


            

Reported by Pylint.

Unused variable 'index'
Error

Line: 696 Column: 9

                      tm.assert_frame_equal(result, expected)

        # index
        index = selection.index  # noqa
        result = read_hdf(hh, "df", where="l1=index")
        tm.assert_frame_equal(result, expected)

        result = read_hdf(hh, "df", where="l1=selection.index")
        tm.assert_frame_equal(result, expected)

            

Reported by Pylint.

FIXME: 2021-01-20 this is failing with freq None vs 4B on some builds
Error

Line: 842 Column: 3

                      expected = concat([df1, df2], axis=1)
        expected = expected[(expected.A > 0) & (expected.B > 0)]
        tm.assert_frame_equal(result, expected, check_freq=False)
        # FIXME: 2021-01-20 this is failing with freq None vs 4B on some builds

        # multiple (diff selector)
        result = store.select_as_multiple(
            ["df1", "df2"], where="index>df2.index[4]", selector="df2"
        )

            

Reported by Pylint.

Unused variable 'ts'
Error

Line: 931 Column: 9

                  with ensure_clean_store(setup_path) as store:
        store.append("test", df, format="table", data_columns=True)

        ts = Timestamp("2014-01-01")  # noqa
        result = store.select("test", where="real_date > ts")
        expected = df.loc[[1], :]
        tm.assert_frame_equal(expected, result)

        for op in ["<", ">", "=="]:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from warnings import catch_warnings

import numpy as np
import pytest

from pandas._libs.tslibs import Timestamp

import pandas as pd
from pandas import (

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 33 Column: 1

              pytestmark = pytest.mark.single


def test_select_columns_in_where(setup_path):

    # GH 6169
    # recreate multi-indexes when columns is passed
    # in the `where` argument
    index = MultiIndex(

            

Reported by Pylint.

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

Line: 45 Column: 5

                  )

    # With a DataFrame
    df = DataFrame(np.random.randn(10, 3), index=index, columns=["A", "B", "C"])

    with ensure_clean_store(setup_path) as store:
        store.put("df", df, format="table")
        expected = df[["A"]]


            

Reported by Pylint.

pandas/core/nanops.py
79 issues
No name 'lib' in module 'pandas._libs'
Error

Line: 16 Column: 1

              
from pandas._config import get_option

from pandas._libs import (
    NaT,
    NaTType,
    Timedelta,
    iNaT,
    lib,

            

Reported by Pylint.

bad operand type for unary ~: NoneType
Error

Line: 332 Column: 35

                              np.putmask(values, mask, fill_value)
            else:
                # np.where will promote if needed
                values = np.where(~mask, values, fill_value)

    # return a platform independent precision dtype
    dtype_max = dtype
    if is_integer_dtype(dtype) or is_bool_dtype(dtype):
        dtype_max = np.dtype(np.int64)

            

Reported by Pylint.

bad operand type for unary ~: NoneType
Error

Line: 332 Column: 35

                              np.putmask(values, mask, fill_value)
            else:
                # np.where will promote if needed
                values = np.where(~mask, values, fill_value)

    # return a platform independent precision dtype
    dtype_max = dtype
    if is_integer_dtype(dtype) or is_bool_dtype(dtype):
        dtype_max = np.dtype(np.int64)

            

Reported by Pylint.

Unable to import 'scipy.stats'
Error

Line: 1524 Column: 9

              
def get_corr_func(method):
    if method == "kendall":
        from scipy.stats import kendalltau

        def func(a, b):
            return kendalltau(a, b)[0]

        return func

            

Reported by Pylint.

Unable to import 'scipy.stats'
Error

Line: 1531 Column: 9

              
        return func
    elif method == "spearman":
        from scipy.stats import spearmanr

        def func(a, b):
            return spearmanr(a, b)[0]

        return func

            

Reported by Pylint.

Using the global statement
Error

Line: 66 Column: 5

              
def set_use_bottleneck(v: bool = True) -> None:
    # set/unset to use bottleneck
    global _USE_BOTTLENECK
    if _BOTTLENECK_INSTALLED:
        _USE_BOTTLENECK = v


set_use_bottleneck(get_option("compute.use_bottleneck"))

            

Reported by Pylint.

TODO(GH-18976) update all the nanops methods to
Error

Line: 136 Column: 3

                              # We are empty, returning NA for our type
                # Only applies for the default `min_count` of None
                # since that affects how empty arrays are handled.
                # TODO(GH-18976) update all the nanops methods to
                # correctly handle empty inputs and remove this check.
                # It *may* just be `var`
                return _na_for_min_count(values, axis)

            if _USE_BOTTLENECK and skipna and _bn_ok_dtype(values.dtype, bn_name):

            

Reported by Pylint.

Unused variable 'dtype'
Error

Line: 999 Column: 23

                      mask: np.ndarray | None = None,
    ) -> Dtype:

        values, mask, dtype, dtype_max, fill_value = _get_values(
            values, skipna, fill_value_typ=fill_value_typ, mask=mask
        )

        if (axis is not None and values.shape[axis] == 0) or values.size == 0:
            try:

            

Reported by Pylint.

Unused variable 'fill_value'
Error

Line: 999 Column: 41

                      mask: np.ndarray | None = None,
    ) -> Dtype:

        values, mask, dtype, dtype_max, fill_value = _get_values(
            values, skipna, fill_value_typ=fill_value_typ, mask=mask
        )

        if (axis is not None and values.shape[axis] == 0) or values.size == 0:
            try:

            

Reported by Pylint.

Comparing against a callable, did you omit the parenthesis?
Error

Line: 1750 Column: 12

                      # We need to define mask before masking NaTs
        mask = isna(values)

        if accum_func == np.minimum.accumulate:
            # Note: the accum_func comparison fails as an "is" comparison
            y = values.view("i8")
            y[mask] = lib.i8max
            changed = True
        else:

            

Reported by Pylint.

pandas/tests/series/test_logical_ops.py
79 issues
Unable to import 'pytest'
Error

Line: 5 Column: 1

              import operator

import numpy as np
import pytest

from pandas import (
    DataFrame,
    Index,
    Series,

            

Reported by Pylint.

TODO: unused
Error

Line: 52 Column: 3

                  def test_logical_operators_int_dtype_with_int_dtype(self):
        # GH#9016: support bitwise op for integer types

        # TODO: unused
        # s_0101 = Series([0, 1, 0, 1])

        s_0123 = Series(range(4), dtype="int64")
        s_3333 = Series([3] * 4)
        s_4444 = Series([4] * 4)

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 94 Column: 13

              
        msg = "Cannot perform.+with a dtyped.+array and scalar of type"
        with pytest.raises(TypeError, match=msg):
            s_0123 & np.NaN
        with pytest.raises(TypeError, match=msg):
            s_0123 & 3.14
        msg = "unsupported operand type.+for &:"
        with pytest.raises(TypeError, match=msg):
            s_0123 & [0.1, 4, 3.14, 2]

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 96 Column: 13

                      with pytest.raises(TypeError, match=msg):
            s_0123 & np.NaN
        with pytest.raises(TypeError, match=msg):
            s_0123 & 3.14
        msg = "unsupported operand type.+for &:"
        with pytest.raises(TypeError, match=msg):
            s_0123 & [0.1, 4, 3.14, 2]
        with pytest.raises(TypeError, match=msg):
            s_0123 & np.array([0.1, 4, 3.14, 2])

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 99 Column: 13

                          s_0123 & 3.14
        msg = "unsupported operand type.+for &:"
        with pytest.raises(TypeError, match=msg):
            s_0123 & [0.1, 4, 3.14, 2]
        with pytest.raises(TypeError, match=msg):
            s_0123 & np.array([0.1, 4, 3.14, 2])
        with pytest.raises(TypeError, match=msg):
            s_0123 & Series([0.1, 4, -3.14, 2])


            

Reported by Pylint.

Expression "s_0123 & np.array([0.1, 4, 3.14, 2])" is assigned to nothing
Error

Line: 101 Column: 13

                      with pytest.raises(TypeError, match=msg):
            s_0123 & [0.1, 4, 3.14, 2]
        with pytest.raises(TypeError, match=msg):
            s_0123 & np.array([0.1, 4, 3.14, 2])
        with pytest.raises(TypeError, match=msg):
            s_0123 & Series([0.1, 4, -3.14, 2])

    def test_logical_operators_int_dtype_with_str(self):
        s_1111 = Series([1] * 4, dtype="int8")

            

Reported by Pylint.

Expression "s_0123 & Series([0.1, 4, -3.14, 2])" is assigned to nothing
Error

Line: 103 Column: 13

                      with pytest.raises(TypeError, match=msg):
            s_0123 & np.array([0.1, 4, 3.14, 2])
        with pytest.raises(TypeError, match=msg):
            s_0123 & Series([0.1, 4, -3.14, 2])

    def test_logical_operators_int_dtype_with_str(self):
        s_1111 = Series([1] * 4, dtype="int8")
        msg = "Cannot perform 'and_' with a dtyped.+array and scalar of type"
        with pytest.raises(TypeError, match=msg):

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 109 Column: 13

                      s_1111 = Series([1] * 4, dtype="int8")
        msg = "Cannot perform 'and_' with a dtyped.+array and scalar of type"
        with pytest.raises(TypeError, match=msg):
            s_1111 & "a"
        with pytest.raises(TypeError, match="unsupported operand.+for &"):
            s_1111 & ["a", "b", "c", "d"]

    def test_logical_operators_int_dtype_with_bool(self):
        # GH#9016: support bitwise op for integer types

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 111 Column: 13

                      with pytest.raises(TypeError, match=msg):
            s_1111 & "a"
        with pytest.raises(TypeError, match="unsupported operand.+for &"):
            s_1111 & ["a", "b", "c", "d"]

    def test_logical_operators_int_dtype_with_bool(self):
        # GH#9016: support bitwise op for integer types
        s_0123 = Series(range(4), dtype="int64")


            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 142 Column: 13

              
        s_abNd = Series(["a", "b", np.NaN, "d"])
        with pytest.raises(TypeError, match="unsupported.* 'int' and 'str'"):
            s_0123 & s_abNd

    def test_logical_operators_bool_dtype_with_int(self):
        index = list("bca")

        s_tft = Series([True, False, True], index=index)

            

Reported by Pylint.

pandas/tests/frame/indexing/test_getitem.py
79 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              import re

import numpy as np
import pytest

from pandas import (
    Categorical,
    CategoricalDtype,
    CategoricalIndex,

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 33 Column: 13

                      df = DataFrame(-1, index=range(3), columns=mi)

        with pytest.raises(KeyError, match="notevenone"):
            df["notevenone"]

    def test_getitem_periodindex(self):
        rng = period_range("1/1/2000", periods=5)
        df = DataFrame(np.random.randn(10, 5), columns=rng)


            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 84 Column: 13

              
        # Check that we get the correct value in the KeyError
        with pytest.raises(KeyError, match=r"\['y'\] not in index"):
            df[["x", "y", "z"]]

    def test_getitem_list_duplicates(self):
        # GH#1943
        df = DataFrame(np.random.randn(4, 4), columns=list("AABC"))
        df.columns.name = "foo"

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 101 Column: 13

                      df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=["a", "a", "b"])
        msg = "\"None of [Index(['baf'], dtype='object')] are in the [columns]\""
        with pytest.raises(KeyError, match=re.escape(msg)):
            df[["baf"]]

    @pytest.mark.parametrize(
        "idx_type",
        [
            list,

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 145 Column: 13

              
        idx = idx_type(keys + [missing])
        with pytest.raises(KeyError, match="not in index"):
            frame[idx]

    def test_getitem_iloc_generator(self):
        # GH#39614
        df = DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
        indexer = (x for x in [1, 2])

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 254 Column: 13

                      #         name='B')
        msg = "Unordered Categoricals can only compare equality or not"
        with pytest.raises(TypeError, match=msg):
            df4[df4.index < 2]
        with pytest.raises(TypeError, match=msg):
            df4[df4.index > 1]

    @pytest.mark.parametrize(
        "data1,data2,expected_data",

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 256 Column: 13

                      with pytest.raises(TypeError, match=msg):
            df4[df4.index < 2]
        with pytest.raises(TypeError, match=msg):
            df4[df4.index > 1]

    @pytest.mark.parametrize(
        "data1,data2,expected_data",
        (
            (

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 305 Column: 17

                      msg = "cannot reindex on an axis with duplicate labels"
        with pytest.raises(ValueError, match=msg):
            with tm.assert_produces_warning(FutureWarning, match="non-unique"):
                df[df.A > 6]

    def test_getitem_boolean_series_with_duplicate_columns(self, df_dup_cols):
        # boolean indexing
        # GH#4879
        df = DataFrame(

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 320 Column: 9

                      result = df[df.C > 6]

        tm.assert_frame_equal(result, expected)
        result.dtypes
        str(result)

    def test_getitem_boolean_frame_with_duplicate_columns(self, df_dup_cols):

        # where

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 337 Column: 9

                      result = df[df > 6]

        tm.assert_frame_equal(result, expected)
        result.dtypes
        str(result)

    def test_getitem_empty_frame_with_boolean(self):
        # Test for issue GH#11859


            

Reported by Pylint.

pandas/tests/tseries/offsets/test_week.py
79 issues
Unable to import 'pytest'
Error

Line: 12 Column: 1

                  timedelta,
)

import pytest

from pandas._libs.tslibs import Timestamp
from pandas._libs.tslibs.offsets import (
    Day,
    LastWeekOfMonth,

            

Reported by Pylint.

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

Line: 15 Column: 1

              import pytest

from pandas._libs.tslibs import Timestamp
from pandas._libs.tslibs.offsets import (
    Day,
    LastWeekOfMonth,
    Week,
    WeekOfMonth,
)

            

Reported by Pylint.

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

Line: 15 Column: 1

              import pytest

from pandas._libs.tslibs import Timestamp
from pandas._libs.tslibs.offsets import (
    Day,
    LastWeekOfMonth,
    Week,
    WeekOfMonth,
)

            

Reported by Pylint.

Statement seems to have no effect
Error

Line: 150 Column: 13

                      offset = Week(weekday=1)
        other = Day()
        with pytest.raises(TypeError, match="Cannot add"):
            offset + other


class TestWeekOfMonth(Base):
    _offset = WeekOfMonth
    offset1 = _offset()

            

Reported by Pylint.

Missing class docstring
Error

Line: 30 Column: 1

              )


class TestWeek(Base):
    _offset = Week
    d = Timestamp(datetime(2008, 1, 2))
    offset1 = _offset()
    offset2 = _offset(2)


            

Reported by Pylint.

Method could be a function
Error

Line: 36 Column: 5

                  offset1 = _offset()
    offset2 = _offset(2)

    def test_repr(self):
        assert repr(Week(weekday=0)) == "<Week: weekday=0>"
        assert repr(Week(n=-1, weekday=0)) == "<-1 * Week: weekday=0>"
        assert repr(Week(n=-2, weekday=0)) == "<-2 * Weeks: weekday=0>"

    def test_corner(self):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 36 Column: 5

                  offset1 = _offset()
    offset2 = _offset(2)

    def test_repr(self):
        assert repr(Week(weekday=0)) == "<Week: weekday=0>"
        assert repr(Week(n=-1, weekday=0)) == "<-1 * Week: weekday=0>"
        assert repr(Week(n=-2, weekday=0)) == "<-2 * Weeks: weekday=0>"

    def test_corner(self):

            

Reported by Pylint.

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

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

                  offset2 = _offset(2)

    def test_repr(self):
        assert repr(Week(weekday=0)) == "<Week: weekday=0>"
        assert repr(Week(n=-1, weekday=0)) == "<-1 * Week: weekday=0>"
        assert repr(Week(n=-2, weekday=0)) == "<-2 * Weeks: weekday=0>"

    def test_corner(self):
        with pytest.raises(ValueError, match="Day must be"):

            

Reported by Bandit.

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

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

              
    def test_repr(self):
        assert repr(Week(weekday=0)) == "<Week: weekday=0>"
        assert repr(Week(n=-1, weekday=0)) == "<-1 * Week: weekday=0>"
        assert repr(Week(n=-2, weekday=0)) == "<-2 * Weeks: weekday=0>"

    def test_corner(self):
        with pytest.raises(ValueError, match="Day must be"):
            Week(weekday=7)

            

Reported by Bandit.

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

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

                  def test_repr(self):
        assert repr(Week(weekday=0)) == "<Week: weekday=0>"
        assert repr(Week(n=-1, weekday=0)) == "<-1 * Week: weekday=0>"
        assert repr(Week(n=-2, weekday=0)) == "<-2 * Weeks: weekday=0>"

    def test_corner(self):
        with pytest.raises(ValueError, match="Day must be"):
            Week(weekday=7)


            

Reported by Bandit.

pandas/tests/extension/json/test_json.py
78 issues
Unable to import 'pytest'
Error

Line: 4 Column: 1

              import collections
import operator

import pytest

import pandas as pd
import pandas._testing as tm
from pandas.tests.extension import base
from pandas.tests.extension.json.array import (

            

Reported by Pylint.

No value for argument 'data_missing' in method call
Error

Line: 154 Column: 9

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


class TestConstructors(BaseJSON, base.BaseConstructorsTests):
    @pytest.mark.skip(reason="not implemented constructor from dtype")
    def test_from_dtype(self, data):

            

Reported by Pylint.

No value for argument 'obj' in method call
Error

Line: 192 Column: 16

                  def test_unstack(self, data, index):
        # The base test has NaN for the expected NA value.
        # this matches otherwise
        return super().test_unstack(data, index)


class TestGetitem(BaseJSON, base.BaseGetitemTests):
    pass


            

Reported by Pylint.

No value for argument 'as_frame' in method call
Error

Line: 269 Column: 9

                      # Fails with
        # *** ValueError: operands could not be broadcast together
        # with shapes (4,) (4,) (0,)
        super().test_where_series(data, na_value)

    @pytest.mark.skip(reason="Can't compare dicts.")
    def test_searchsorted(self, data_for_sorting):
        super().test_searchsorted(data_for_sorting)


            

Reported by Pylint.

No value for argument 'as_series' in method call
Error

Line: 273 Column: 9

              
    @pytest.mark.skip(reason="Can't compare dicts.")
    def test_searchsorted(self, data_for_sorting):
        super().test_searchsorted(data_for_sorting)

    @pytest.mark.skip(reason="Can't compare dicts.")
    def test_equals(self, data, na_value, as_series):
        pass


            

Reported by Pylint.

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

Line: 24 Column: 5

              @pytest.fixture
def data():
    """Length-100 PeriodArray for semantics test."""
    data = make_data()

    # Why the while loop? NumPy is unable to construct an ndarray from
    # equal-length ndarrays. Many of our operations involve coercing the
    # EA to an ndarray of objects. To avoid random test failures, we ensure
    # that our data is coercible to an ndarray. Several tests deal with only

            

Reported by Pylint.

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

Line: 55 Column: 14

              

@pytest.fixture
def na_value(dtype):
    return dtype.na_value


@pytest.fixture
def na_cmp():

            

Reported by Pylint.

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

Line: 130 Column: 9

                  def test_custom_asserts(self):
        # This would always trigger the KeyError from trying to put
        # an array of equal-length UserDicts inside an ndarray.
        data = JSONArray(
            [
                collections.UserDict({"a": 1}),
                collections.UserDict({"b": 2}),
                collections.UserDict({"c": 3}),
            ]

            

Reported by Pylint.

Parameters differ from overridden 'test_contains' method
Error

Line: 151 Column: 5

              
    @pytest.mark.xfail(
        reason="comparison method not implemented for JSONArray (GH-37867)"
    )
    def test_contains(self, data):
        # GH-37867
        super().test_contains(data)



            

Reported by Pylint.

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

Line: 152 Column: 29

                  @pytest.mark.xfail(
        reason="comparison method not implemented for JSONArray (GH-37867)"
    )
    def test_contains(self, data):
        # GH-37867
        super().test_contains(data)


class TestConstructors(BaseJSON, base.BaseConstructorsTests):

            

Reported by Pylint.