The following issues were found
pandas/tests/indexes/base_class/test_setops.py
50 issues
Line: 4
Column: 1
from datetime import datetime
import numpy as np
import pytest
import pandas as pd
from pandas import (
Index,
Series,
Reported by Pylint.
Line: 37
Column: 18
result = idx.intersection(idx[1:][::-1])
tm.assert_index_equal(result, expected)
result = idx._union(idx[1:], sort=None)
expected = idx
tm.assert_numpy_array_equal(result, expected.values)
result = idx.union(idx[1:], sort=None)
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 46
Column: 18
# if other is not monotonic increasing, _union goes through
# a different route
result = idx._union(idx[1:][::-1], sort=None)
tm.assert_numpy_array_equal(result, expected.values)
result = idx.union(idx[1:][::-1], sort=None)
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 93
Column: 3
@pytest.mark.xfail(reason="GH#25151 need to decide on True behavior")
def test_union_sort_other_incomparable_true(self):
# TODO decide on True behaviour
# sort=True
idx = Index([1, pd.Timestamp("2000")])
with pytest.raises(TypeError, match=".*"):
idx.union(idx[:1], sort=True)
Reported by Pylint.
Line: 101
Column: 3
@pytest.mark.xfail(reason="GH#25151 need to decide on True behavior")
def test_intersection_equal_sort_true(self):
# TODO decide on True behaviour
idx = Index(["c", "a", "b"])
sorted_ = Index(["a", "b", "c"])
tm.assert_index_equal(idx.intersection(idx, sort=True), sorted_)
def test_intersection_base(self, sort):
Reported by Pylint.
Line: 1
Column: 1
from datetime import datetime
import numpy as np
import pytest
import pandas as pd
from pandas import (
Index,
Series,
Reported by Pylint.
Line: 15
Column: 1
from pandas.core.algorithms import safe_sort
class TestIndexSetOps:
@pytest.mark.parametrize(
"method", ["union", "intersection", "difference", "symmetric_difference"]
)
def test_setops_disallow_true(self, method):
idx1 = Index(["a", "b"])
Reported by Pylint.
Line: 18
Column: 5
class TestIndexSetOps:
@pytest.mark.parametrize(
"method", ["union", "intersection", "difference", "symmetric_difference"]
)
def test_setops_disallow_true(self, method):
idx1 = Index(["a", "b"])
idx2 = Index(["b", "c"])
with pytest.raises(ValueError, match="The 'sort' keyword only takes"):
Reported by Pylint.
Line: 18
Column: 5
class TestIndexSetOps:
@pytest.mark.parametrize(
"method", ["union", "intersection", "difference", "symmetric_difference"]
)
def test_setops_disallow_true(self, method):
idx1 = Index(["a", "b"])
idx2 = Index(["b", "c"])
with pytest.raises(ValueError, match="The 'sort' keyword only takes"):
Reported by Pylint.
Line: 26
Column: 5
with pytest.raises(ValueError, match="The 'sort' keyword only takes"):
getattr(idx1, method)(idx2, sort=True)
def test_setops_preserve_object_dtype(self):
idx = Index([1, 2, 3], dtype=object)
result = idx.intersection(idx[1:])
expected = idx[1:]
tm.assert_index_equal(result, expected)
Reported by Pylint.
pandas/core/sorting.py
49 issues
Line: 15
Column: 1
import numpy as np
from pandas._libs import (
algos,
hashtable,
lib,
)
from pandas._libs.hashtable import unique_label_indices
Reported by Pylint.
Line: 15
Column: 1
import numpy as np
from pandas._libs import (
algos,
hashtable,
lib,
)
from pandas._libs.hashtable import unique_label_indices
Reported by Pylint.
Line: 15
Column: 1
import numpy as np
from pandas._libs import (
algos,
hashtable,
lib,
)
from pandas._libs.hashtable import unique_label_indices
Reported by Pylint.
Line: 20
Column: 1
hashtable,
lib,
)
from pandas._libs.hashtable import unique_label_indices
from pandas._typing import (
IndexKeyFunc,
Shape,
npt,
)
Reported by Pylint.
Line: 20
Column: 1
hashtable,
lib,
)
from pandas._libs.hashtable import unique_label_indices
from pandas._typing import (
IndexKeyFunc,
Shape,
npt,
)
Reported by Pylint.
Line: 192
Column: 34
def get_compressed_ids(
labels, sizes: Shape
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.int64]]:
"""
Group_index is offsets into cartesian product of all possible labels. This
space can be huge, so this function compresses it, by computing offsets
(comp_ids) into the list of unique labels (obs_group_ids).
Reported by Pylint.
Line: 192
Column: 12
def get_compressed_ids(
labels, sizes: Shape
) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.int64]]:
"""
Group_index is offsets into cartesian product of all possible labels. This
space can be huge, so this function compresses it, by computing offsets
(comp_ids) into the list of unique labels (obs_group_ids).
Reported by Pylint.
Line: 243
Column: 15
def decons_obs_group_ids(
comp_ids: npt.NDArray[np.intp], obs_ids, shape, labels, xnull: bool
):
"""
Reconstruct labels from observed group ids.
Parameters
Reported by Pylint.
Line: 270
Column: 6
def indexer_from_factorized(
labels, shape: Shape, compress: bool = True
) -> npt.NDArray[np.intp]:
ids = get_group_index(labels, shape, sort=True, xnull=False)
if not compress:
ngroups = (ids.size and ids.max()) + 1
else:
Reported by Pylint.
Line: 284
Column: 6
def lexsort_indexer(
keys, orders=None, na_position: str = "last", key: Callable | None = None
) -> npt.NDArray[np.intp]:
"""
Performs lexical sorting on a set of keys
Parameters
----------
Reported by Pylint.
pandas/tests/io/excel/test_style.py
49 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import DataFrame
import pandas._testing as tm
from pandas.io.excel import ExcelWriter
from pandas.io.formats.excel import ExcelFormatter
Reported by Pylint.
Line: 75
Column: 14
df = DataFrame(np.random.randn(11, 3))
with tm.ensure_clean(".xlsx" if engine != "xlwt" else ".xls") as path:
with ExcelWriter(path, engine=engine) as writer:
df.to_excel(writer, sheet_name="frame")
df.style.to_excel(writer, sheet_name="unstyled")
styled = df.style.apply(style, axis=None)
styled.to_excel(writer, sheet_name="styled")
ExcelFormatter(styled, style_converter=custom_converter).write(
Reported by Pylint.
Line: 26
Column: 3
)
def test_styler_to_excel(request, engine):
def style(df):
# TODO: RGB colors not supported in xlwt
return DataFrame(
[
["font-weight: bold", "", ""],
["", "color: blue", ""],
["", "", "text-decoration: underline"],
Reported by Pylint.
Line: 54
Column: 3
)
)
)
# TODO: should find a better way to check equality
assert cell1.alignment.__dict__ == cell2.alignment.__dict__
assert cell1.border.__dict__ == cell2.border.__dict__
assert cell1.fill.__dict__ == cell2.fill.__dict__
assert cell1.font.__dict__ == cell2.font.__dict__
assert cell1.number_format == cell2.number_format
Reported by Pylint.
Line: 104
Column: 3
# (2) check styling with default converter
# TODO: openpyxl (as at 2.4) prefixes colors with 00, xlsxwriter with FF
alpha = "00" if engine == "openpyxl" else "FF"
n_cells = 0
for col1, col2 in zip(wb["frame"].columns, wb["styled"].columns):
assert len(col1) == len(col2)
Reported by Pylint.
Line: 112
Column: 3
assert len(col1) == len(col2)
for cell1, cell2 in zip(col1, col2):
ref = f"{cell2.column}{cell2.row:d}"
# TODO: this isn't as strong a test as ideal; we should
# confirm that differences are exclusive
if ref == "B2":
assert not cell1.font.bold
assert cell2.font.bold
elif ref == "C3":
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import DataFrame
import pandas._testing as tm
from pandas.io.excel import ExcelWriter
from pandas.io.formats.excel import ExcelFormatter
Reported by Pylint.
Line: 22
Column: 1
),
"xlsxwriter",
"openpyxl",
],
)
def test_styler_to_excel(request, engine):
def style(df):
# TODO: RGB colors not supported in xlwt
return DataFrame(
Reported by Pylint.
Line: 22
Column: 1
),
"xlsxwriter",
"openpyxl",
],
)
def test_styler_to_excel(request, engine):
def style(df):
# TODO: RGB colors not supported in xlwt
return DataFrame(
Reported by Pylint.
Line: 22
Column: 1
),
"xlsxwriter",
"openpyxl",
],
)
def test_styler_to_excel(request, engine):
def style(df):
# TODO: RGB colors not supported in xlwt
return DataFrame(
Reported by Pylint.
pandas/tests/base/test_constructors.py
49 issues
Line: 5
Column: 1
import sys
import numpy as np
import pytest
from pandas.compat import PYPY
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 86
Column: 13
msg = "You cannot access the property foo"
with pytest.raises(TypeError, match=msg):
delegate.foo()
@pytest.mark.skipif(PYPY, reason="not relevant for PyPy")
def test_memory_usage(self):
# Delegate does not implement memory_usage.
# Check that we fall back to in-built `__sizeof__`
Reported by Pylint.
Line: 51
Column: 13
def bar(self, *args, **kwargs):
"""a test bar method"""
pass
class Delegate(PandasDelegate, PandasObject):
def __init__(self, obj):
self.obj = obj
Reported by Pylint.
Line: 65
Column: 9
# the _delegate_* methods need to be overridden to not raise
# a TypeError
self.Delegate._add_delegate_accessors(
delegate=self.Delegator,
accessors=self.Delegator._properties,
typ="property",
)
self.Delegate._add_delegate_accessors(
Reported by Pylint.
Line: 67
Column: 23
self.Delegate._add_delegate_accessors(
delegate=self.Delegator,
accessors=self.Delegator._properties,
typ="property",
)
self.Delegate._add_delegate_accessors(
delegate=self.Delegator, accessors=self.Delegator._methods, typ="method"
)
Reported by Pylint.
Line: 70
Column: 9
accessors=self.Delegator._properties,
typ="property",
)
self.Delegate._add_delegate_accessors(
delegate=self.Delegator, accessors=self.Delegator._methods, typ="method"
)
delegate = self.Delegate(self.Delegator())
Reported by Pylint.
Line: 71
Column: 48
typ="property",
)
self.Delegate._add_delegate_accessors(
delegate=self.Delegator, accessors=self.Delegator._methods, typ="method"
)
delegate = self.Delegate(self.Delegator())
msg = "You cannot access the property foo"
Reported by Pylint.
Line: 78
Column: 13
msg = "You cannot access the property foo"
with pytest.raises(TypeError, match=msg):
delegate.foo
msg = "The property foo cannot be set"
with pytest.raises(TypeError, match=msg):
delegate.foo = 5
Reported by Pylint.
Line: 82
Column: 13
msg = "The property foo cannot be set"
with pytest.raises(TypeError, match=msg):
delegate.foo = 5
msg = "You cannot access the property foo"
with pytest.raises(TypeError, match=msg):
delegate.foo()
Reported by Pylint.
Line: 105
Column: 9
t = T()
assert not hasattr(t, "__frozen")
t.a = "test"
assert t.a == "test"
t._freeze()
assert "__frozen" in dir(t)
assert getattr(t, "__frozen")
Reported by Pylint.
pandas/tests/frame/methods/test_dropna.py
49 issues
Line: 5
Column: 1
import dateutil
import numpy as np
import pytest
import pandas as pd
from pandas import (
DataFrame,
Series,
Reported by Pylint.
Line: 1
Column: 1
import datetime
import dateutil
import numpy as np
import pytest
import pandas as pd
from pandas import (
DataFrame,
Reported by Pylint.
Line: 15
Column: 1
import pandas._testing as tm
class TestDataFrameMissingData:
def test_dropEmptyRows(self, float_frame):
N = len(float_frame.index)
mat = np.random.randn(N)
mat[:5] = np.nan
Reported by Pylint.
Line: 16
Column: 5
class TestDataFrameMissingData:
def test_dropEmptyRows(self, float_frame):
N = len(float_frame.index)
mat = np.random.randn(N)
mat[:5] = np.nan
frame = DataFrame({"foo": mat}, index=float_frame.index)
Reported by Pylint.
Line: 16
Column: 5
class TestDataFrameMissingData:
def test_dropEmptyRows(self, float_frame):
N = len(float_frame.index)
mat = np.random.randn(N)
mat[:5] = np.nan
frame = DataFrame({"foo": mat}, index=float_frame.index)
Reported by Pylint.
Line: 16
Column: 5
class TestDataFrameMissingData:
def test_dropEmptyRows(self, float_frame):
N = len(float_frame.index)
mat = np.random.randn(N)
mat[:5] = np.nan
frame = DataFrame({"foo": mat}, index=float_frame.index)
Reported by Pylint.
Line: 17
Column: 9
class TestDataFrameMissingData:
def test_dropEmptyRows(self, float_frame):
N = len(float_frame.index)
mat = np.random.randn(N)
mat[:5] = np.nan
frame = DataFrame({"foo": mat}, index=float_frame.index)
original = Series(mat, index=float_frame.index, name="foo")
Reported by Pylint.
Line: 32
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
return_value = inplace_frame1.dropna(how="all", inplace=True)
tm.assert_series_equal(smaller_frame["foo"], expected)
tm.assert_series_equal(inplace_frame1["foo"], expected)
assert return_value is None
smaller_frame = frame.dropna(how="all", subset=["foo"])
return_value = inplace_frame2.dropna(how="all", subset=["foo"], inplace=True)
tm.assert_series_equal(smaller_frame["foo"], expected)
tm.assert_series_equal(inplace_frame2["foo"], expected)
Reported by Bandit.
Line: 38
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
return_value = inplace_frame2.dropna(how="all", subset=["foo"], inplace=True)
tm.assert_series_equal(smaller_frame["foo"], expected)
tm.assert_series_equal(inplace_frame2["foo"], expected)
assert return_value is None
def test_dropIncompleteRows(self, float_frame):
N = len(float_frame.index)
mat = np.random.randn(N)
mat[:5] = np.nan
Reported by Bandit.
Line: 40
Column: 5
tm.assert_series_equal(inplace_frame2["foo"], expected)
assert return_value is None
def test_dropIncompleteRows(self, float_frame):
N = len(float_frame.index)
mat = np.random.randn(N)
mat[:5] = np.nan
frame = DataFrame({"foo": mat}, index=float_frame.index)
Reported by Pylint.
pandas/tests/extension/test_period.py
49 issues
Line: 17
Column: 1
"""
import numpy as np
import pytest
from pandas._libs import iNaT
from pandas.core.dtypes.dtypes import PeriodDtype
Reported by Pylint.
Line: 34
Column: 10
@pytest.fixture
def data(dtype):
return PeriodArray(np.arange(1970, 2070), freq=dtype.freq)
@pytest.fixture
def data_for_twos(dtype):
Reported by Pylint.
Line: 39
Column: 19
@pytest.fixture
def data_for_twos(dtype):
return PeriodArray(np.ones(100) * 2, freq=dtype.freq)
@pytest.fixture
def data_for_sorting(dtype):
Reported by Pylint.
Line: 44
Column: 22
@pytest.fixture
def data_for_sorting(dtype):
return PeriodArray([2018, 2019, 2017], freq=dtype.freq)
@pytest.fixture
def data_missing(dtype):
Reported by Pylint.
Line: 49
Column: 18
@pytest.fixture
def data_missing(dtype):
return PeriodArray([iNaT, 2017], freq=dtype.freq)
@pytest.fixture
def data_missing_for_sorting(dtype):
Reported by Pylint.
Line: 54
Column: 30
@pytest.fixture
def data_missing_for_sorting(dtype):
return PeriodArray([2018, iNaT, 2017], freq=dtype.freq)
@pytest.fixture
def data_for_grouping(dtype):
Reported by Pylint.
Line: 59
Column: 23
@pytest.fixture
def data_for_grouping(dtype):
B = 2018
NA = iNaT
A = 2017
C = 2019
return PeriodArray([B, B, NA, NA, A, A, B, C], freq=dtype.freq)
Reported by Pylint.
Line: 102
Column: 44
class TestArithmeticOps(BasePeriodTests, base.BaseArithmeticOpsTests):
implements = {"__sub__", "__rsub__"}
def test_arith_frame_with_scalar(self, data, all_arithmetic_operators):
# frame & scalar
if all_arithmetic_operators in self.implements:
df = pd.DataFrame({"A": data})
self.check_opname(df, all_arithmetic_operators, data[0], exc=None)
else:
Reported by Pylint.
Line: 111
Column: 45
# ... but not the rest.
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)
def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
# we implement substitution...
if all_arithmetic_operators in self.implements:
s = pd.Series(data)
self.check_opname(s, all_arithmetic_operators, s.iloc[0], exc=None)
else:
Reported by Pylint.
Line: 120
Column: 44
# ... but not the rest.
super().test_arith_series_with_scalar(data, all_arithmetic_operators)
def test_arith_series_with_array(self, data, all_arithmetic_operators):
if all_arithmetic_operators in self.implements:
s = pd.Series(data)
self.check_opname(s, all_arithmetic_operators, s.iloc[0], exc=None)
else:
# ... but not the rest.
Reported by Pylint.
pandas/tests/tslibs/test_liboffsets.py
49 issues
Line: 6
Column: 1
"""
from datetime import datetime
import pytest
from pandas._libs.tslibs.ccalendar import (
get_firstbday,
get_lastbday,
)
Reported by Pylint.
Line: 8
Column: 1
import pytest
from pandas._libs.tslibs.ccalendar import (
get_firstbday,
get_lastbday,
)
import pandas._libs.tslibs.offsets as liboffsets
from pandas._libs.tslibs.offsets import roll_qtrday
Reported by Pylint.
Line: 8
Column: 1
import pytest
from pandas._libs.tslibs.ccalendar import (
get_firstbday,
get_lastbday,
)
import pandas._libs.tslibs.offsets as liboffsets
from pandas._libs.tslibs.offsets import roll_qtrday
Reported by Pylint.
Line: 12
Column: 1
get_firstbday,
get_lastbday,
)
import pandas._libs.tslibs.offsets as liboffsets
from pandas._libs.tslibs.offsets import roll_qtrday
from pandas import Timestamp
Reported by Pylint.
Line: 12
Column: 1
get_firstbday,
get_lastbday,
)
import pandas._libs.tslibs.offsets as liboffsets
from pandas._libs.tslibs.offsets import roll_qtrday
from pandas import Timestamp
Reported by Pylint.
Line: 13
Column: 1
get_lastbday,
)
import pandas._libs.tslibs.offsets as liboffsets
from pandas._libs.tslibs.offsets import roll_qtrday
from pandas import Timestamp
@pytest.fixture(params=["start", "end", "business_start", "business_end"])
Reported by Pylint.
Line: 13
Column: 1
get_lastbday,
)
import pandas._libs.tslibs.offsets as liboffsets
from pandas._libs.tslibs.offsets import roll_qtrday
from pandas import Timestamp
@pytest.fixture(params=["start", "end", "business_start", "business_end"])
Reported by Pylint.
Line: 58
Column: 33
(0, "business_start", datetime(2017, 11, 1)),
],
)
def test_shift_month_dt(months, day_opt, expected):
dt = datetime(2017, 11, 30)
assert liboffsets.shift_month(dt, months, day_opt=day_opt) == expected
@pytest.mark.parametrize(
Reported by Pylint.
Line: 72
Column: 33
(-1, 31, Timestamp("1929-04-30")),
],
)
def test_shift_month_ts(months, day_opt, expected):
ts = Timestamp("1929-05-05")
assert liboffsets.shift_month(ts, months, day_opt=day_opt) == expected
def test_shift_month_error():
Reported by Pylint.
Line: 79
Column: 5
def test_shift_month_error():
dt = datetime(2017, 11, 15)
day_opt = "this should raise"
with pytest.raises(ValueError, match=day_opt):
liboffsets.shift_month(dt, 3, day_opt=day_opt)
Reported by Pylint.
pandas/tests/extension/base/ops.py
48 issues
Line: 3
Column: 1
from __future__ import annotations
import pytest
import pandas as pd
import pandas._testing as tm
from pandas.core import ops
from pandas.tests.extension.base.base import BaseExtensionTests
Reported by Pylint.
Line: 29
Column: 39
expected = obj.combine(other, op)
return expected
def _check_op(self, s, op, other, op_name, exc=NotImplementedError):
if exc is None:
result = op(s, other)
expected = self._combine(s, other, op)
assert isinstance(result, type(s))
self.assert_equal(result, expected)
Reported by Pylint.
Line: 1
Column: 1
from __future__ import annotations
import pytest
import pandas as pd
import pandas._testing as tm
from pandas.core import ops
from pandas.tests.extension.base.base import BaseExtensionTests
Reported by Pylint.
Line: 11
Column: 1
from pandas.tests.extension.base.base import BaseExtensionTests
class BaseOpsUtil(BaseExtensionTests):
def get_op_from_name(self, op_name):
return tm.get_op_from_name(op_name)
def check_opname(self, s, op_name, other, exc=Exception):
op = self.get_op_from_name(op_name)
Reported by Pylint.
Line: 12
Column: 5
class BaseOpsUtil(BaseExtensionTests):
def get_op_from_name(self, op_name):
return tm.get_op_from_name(op_name)
def check_opname(self, s, op_name, other, exc=Exception):
op = self.get_op_from_name(op_name)
Reported by Pylint.
Line: 12
Column: 5
class BaseOpsUtil(BaseExtensionTests):
def get_op_from_name(self, op_name):
return tm.get_op_from_name(op_name)
def check_opname(self, s, op_name, other, exc=Exception):
op = self.get_op_from_name(op_name)
Reported by Pylint.
Line: 15
Column: 5
def get_op_from_name(self, op_name):
return tm.get_op_from_name(op_name)
def check_opname(self, s, op_name, other, exc=Exception):
op = self.get_op_from_name(op_name)
self._check_op(s, op, other, op_name, exc)
def _combine(self, obj, other, op):
Reported by Pylint.
Line: 15
Column: 5
def get_op_from_name(self, op_name):
return tm.get_op_from_name(op_name)
def check_opname(self, s, op_name, other, exc=Exception):
op = self.get_op_from_name(op_name)
self._check_op(s, op, other, op_name, exc)
def _combine(self, obj, other, op):
Reported by Pylint.
Line: 16
Column: 9
return tm.get_op_from_name(op_name)
def check_opname(self, s, op_name, other, exc=Exception):
op = self.get_op_from_name(op_name)
self._check_op(s, op, other, op_name, exc)
def _combine(self, obj, other, op):
if isinstance(obj, pd.DataFrame):
Reported by Pylint.
Line: 20
Column: 5
self._check_op(s, op, other, op_name, exc)
def _combine(self, obj, other, op):
if isinstance(obj, pd.DataFrame):
if len(obj.columns) != 1:
raise NotImplementedError
expected = obj.iloc[:, 0].combine(other, op).to_frame()
else:
Reported by Pylint.
pandas/tests/indexes/multi/test_names.py
48 issues
Line: 1
Column: 1
import pytest
import pandas as pd
from pandas import MultiIndex
import pandas._testing as tm
def check_level_names(index, names):
assert [level.name for level in index.levels] == list(names)
Reported by Pylint.
Line: 14
Column: 12
def test_slice_keep_name():
x = MultiIndex.from_tuples([("a", "b"), (1, 2), ("c", "d")], names=["x", "y"])
assert x[1:].names == x.names
def test_index_name_retained():
# GH9857
result = pd.DataFrame({"x": [1, 2, 6], "y": [2, 2, 8], "z": [-5, 0, 5]})
Reported by Pylint.
Line: 34
Column: 20
view = idx.view()
copy = idx.copy()
shallow_copy = idx._view()
# changing names should not change level names on object
new_names = [name + "a" for name in idx.names]
idx.names = new_names
check_level_names(idx, ["firsta", "seconda"])
Reported by Pylint.
Line: 128
Column: 9
# GH19029
idx.names = ["foo", "foo"]
with pytest.raises(ValueError, match="name foo occurs multiple times"):
idx._get_level_number("foo")
def test_get_names_from_levels():
idx = MultiIndex.from_product([["a"], [1, 2]], names=["a", "b"])
Reported by Pylint.
Line: 150
Column: 12
with pytest.raises(RuntimeError, match="set_names"):
new.index.name = "bar"
assert pd.Index._no_setting_name is False
assert pd.Int64Index._no_setting_name is False
assert pd.RangeIndex._no_setting_name is False
@pytest.mark.parametrize("func", ["rename", "set_names"])
Reported by Pylint.
Line: 151
Column: 12
new.index.name = "bar"
assert pd.Index._no_setting_name is False
assert pd.Int64Index._no_setting_name is False
assert pd.RangeIndex._no_setting_name is False
@pytest.mark.parametrize("func", ["rename", "set_names"])
@pytest.mark.parametrize(
Reported by Pylint.
Line: 152
Column: 12
assert pd.Index._no_setting_name is False
assert pd.Int64Index._no_setting_name is False
assert pd.RangeIndex._no_setting_name is False
@pytest.mark.parametrize("func", ["rename", "set_names"])
@pytest.mark.parametrize(
"rename_dict, exp_names",
Reported by Pylint.
Line: 1
Column: 1
import pytest
import pandas as pd
from pandas import MultiIndex
import pandas._testing as tm
def check_level_names(index, names):
assert [level.name for level in index.levels] == list(names)
Reported by Pylint.
Line: 8
Column: 1
import pandas._testing as tm
def check_level_names(index, names):
assert [level.name for level in index.levels] == list(names)
def test_slice_keep_name():
x = MultiIndex.from_tuples([("a", "b"), (1, 2), ("c", "d")], names=["x", "y"])
Reported by Pylint.
Line: 9
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def check_level_names(index, names):
assert [level.name for level in index.levels] == list(names)
def test_slice_keep_name():
x = MultiIndex.from_tuples([("a", "b"), (1, 2), ("c", "d")], names=["x", "y"])
assert x[1:].names == x.names
Reported by Bandit.
pandas/core/ops/__init__.py
48 issues
Line: 14
Column: 1
import numpy as np
from pandas._libs.ops_dispatch import maybe_dispatch_ufunc_to_dunder_op # noqa:F401
from pandas._typing import Level
from pandas.util._decorators import Appender
from pandas.core.dtypes.common import (
is_array_like,
Reported by Pylint.
Line: 14
Column: 1
import numpy as np
from pandas._libs.ops_dispatch import maybe_dispatch_ufunc_to_dunder_op # noqa:F401
from pandas._typing import Level
from pandas.util._decorators import Appender
from pandas.core.dtypes.common import (
is_array_like,
Reported by Pylint.
Line: 153
Column: 3
def align_method_SERIES(left: Series, right, align_asobject: bool = False):
"""align lhs and rhs Series"""
# ToDo: Different from align_method_FRAME, list, tuple and ndarray
# are not coerced here
# because Series has inconsistencies described in #13637
if isinstance(right, ABCSeries):
# avoid repeated alignment
Reported by Pylint.
Line: 179
Column: 13
def flex_wrapper(self, other, level=None, fill_value=None, axis=0):
# validate axis
if axis is not None:
self._get_axis_number(axis)
res_name = get_op_result_name(self, other)
if isinstance(other, ABCSeries):
return self._binop(other, op, level=level, fill_value=fill_value)
Reported by Pylint.
Line: 184
Column: 20
res_name = get_op_result_name(self, other)
if isinstance(other, ABCSeries):
return self._binop(other, op, level=level, fill_value=fill_value)
elif isinstance(other, (np.ndarray, list, tuple)):
if len(other) != len(self):
raise ValueError("Lengths must be equal")
other = self._constructor(other, self.index)
result = self._binop(other, op, level=level, fill_value=fill_value)
Reported by Pylint.
Line: 188
Column: 21
elif isinstance(other, (np.ndarray, list, tuple)):
if len(other) != len(self):
raise ValueError("Lengths must be equal")
other = self._constructor(other, self.index)
result = self._binop(other, op, level=level, fill_value=fill_value)
result.name = res_name
return result
else:
if fill_value is not None:
Reported by Pylint.
Line: 189
Column: 22
if len(other) != len(self):
raise ValueError("Lengths must be equal")
other = self._constructor(other, self.index)
result = self._binop(other, op, level=level, fill_value=fill_value)
result.name = res_name
return result
else:
if fill_value is not None:
self = self.fillna(fill_value)
Reported by Pylint.
Line: 230
Column: 33
def to_series(right):
msg = "Unable to coerce to Series, length must be {req_len}: given {given_len}"
if axis is not None and left._get_axis_name(axis) == "index":
if len(left.index) != len(right):
raise ValueError(
msg.format(req_len=len(left.index), given_len=len(right))
)
right = left._constructor_sliced(right, index=left.index)
Reported by Pylint.
Line: 235
Column: 21
raise ValueError(
msg.format(req_len=len(left.index), given_len=len(right))
)
right = left._constructor_sliced(right, index=left.index)
else:
if len(left.columns) != len(right):
raise ValueError(
msg.format(req_len=len(left.columns), given_len=len(right))
)
Reported by Pylint.
Line: 241
Column: 21
raise ValueError(
msg.format(req_len=len(left.columns), given_len=len(right))
)
right = left._constructor_sliced(right, index=left.columns)
return right
if isinstance(right, np.ndarray):
if right.ndim == 1:
Reported by Pylint.