The following issues were found
asv_bench/benchmarks/indexing_engines.py
14 issues
Line: 10
Column: 1
import numpy as np
from pandas._libs import index as libindex
def _get_numeric_engines():
engine_names = [
("Int64Engine", np.int64),
Reported by Pylint.
Line: 51
Column: 9
"non_monotonic": np.array([1, 2, 3] * N, dtype=dtype),
}[index_type]
self.data = engine(lambda: arr, len(arr))
# code belows avoids populating the mapping etc. while timing.
self.data.get_loc(2)
def time_get_loc(self, engine_and_dtype, index_type):
self.data.get_loc(2)
Reported by Pylint.
Line: 55
Column: 28
# code belows avoids populating the mapping etc. while timing.
self.data.get_loc(2)
def time_get_loc(self, engine_and_dtype, index_type):
self.data.get_loc(2)
class ObjectEngineIndexing:
Reported by Pylint.
Line: 55
Column: 46
# code belows avoids populating the mapping etc. while timing.
self.data.get_loc(2)
def time_get_loc(self, engine_and_dtype, index_type):
self.data.get_loc(2)
class ObjectEngineIndexing:
Reported by Pylint.
Line: 73
Column: 9
"non_monotonic": np.array(list("abc") * N, dtype=object),
}[index_type]
self.data = libindex.ObjectEngine(lambda: arr, len(arr))
# code belows avoids populating the mapping etc. while timing.
self.data.get_loc("b")
def time_get_loc(self, index_type):
self.data.get_loc("b")
Reported by Pylint.
Line: 77
Column: 28
# code belows avoids populating the mapping etc. while timing.
self.data.get_loc("b")
def time_get_loc(self, index_type):
self.data.get_loc("b")
Reported by Pylint.
Line: 33
Column: 1
]
class NumericEngineIndexing:
params = [
_get_numeric_engines(),
["monotonic_incr", "monotonic_decr", "non_monotonic"],
]
Reported by Pylint.
Line: 41
Column: 5
]
param_names = ["engine_and_dtype", "index_type"]
def setup(self, engine_and_dtype, index_type):
engine, dtype = engine_and_dtype
N = 10 ** 5
values = list([1] * N + [2] * N + [3] * N)
arr = {
"monotonic_incr": np.array(values, dtype=dtype),
Reported by Pylint.
Line: 43
Column: 9
def setup(self, engine_and_dtype, index_type):
engine, dtype = engine_and_dtype
N = 10 ** 5
values = list([1] * N + [2] * N + [3] * N)
arr = {
"monotonic_incr": np.array(values, dtype=dtype),
"monotonic_decr": np.array(list(reversed(values)), dtype=dtype),
"non_monotonic": np.array([1, 2, 3] * N, dtype=dtype),
Reported by Pylint.
Line: 55
Column: 5
# code belows avoids populating the mapping etc. while timing.
self.data.get_loc(2)
def time_get_loc(self, engine_and_dtype, index_type):
self.data.get_loc(2)
class ObjectEngineIndexing:
Reported by Pylint.
pandas/core/reshape/api.py
14 issues
Line: 3
Column: 1
# flake8: noqa
from pandas.core.reshape.concat import concat
from pandas.core.reshape.melt import (
lreshape,
melt,
wide_to_long,
)
from pandas.core.reshape.merge import (
Reported by Pylint.
Line: 4
Column: 1
# flake8: noqa
from pandas.core.reshape.concat import concat
from pandas.core.reshape.melt import (
lreshape,
melt,
wide_to_long,
)
from pandas.core.reshape.merge import (
Reported by Pylint.
Line: 4
Column: 1
# flake8: noqa
from pandas.core.reshape.concat import concat
from pandas.core.reshape.melt import (
lreshape,
melt,
wide_to_long,
)
from pandas.core.reshape.merge import (
Reported by Pylint.
Line: 4
Column: 1
# flake8: noqa
from pandas.core.reshape.concat import concat
from pandas.core.reshape.melt import (
lreshape,
melt,
wide_to_long,
)
from pandas.core.reshape.merge import (
Reported by Pylint.
Line: 9
Column: 1
melt,
wide_to_long,
)
from pandas.core.reshape.merge import (
merge,
merge_asof,
merge_ordered,
)
from pandas.core.reshape.pivot import (
Reported by Pylint.
Line: 9
Column: 1
melt,
wide_to_long,
)
from pandas.core.reshape.merge import (
merge,
merge_asof,
merge_ordered,
)
from pandas.core.reshape.pivot import (
Reported by Pylint.
Line: 9
Column: 1
melt,
wide_to_long,
)
from pandas.core.reshape.merge import (
merge,
merge_asof,
merge_ordered,
)
from pandas.core.reshape.pivot import (
Reported by Pylint.
Line: 14
Column: 1
merge_asof,
merge_ordered,
)
from pandas.core.reshape.pivot import (
crosstab,
pivot,
pivot_table,
)
from pandas.core.reshape.reshape import get_dummies
Reported by Pylint.
Line: 14
Column: 1
merge_asof,
merge_ordered,
)
from pandas.core.reshape.pivot import (
crosstab,
pivot,
pivot_table,
)
from pandas.core.reshape.reshape import get_dummies
Reported by Pylint.
Line: 14
Column: 1
merge_asof,
merge_ordered,
)
from pandas.core.reshape.pivot import (
crosstab,
pivot,
pivot_table,
)
from pandas.core.reshape.reshape import get_dummies
Reported by Pylint.
pandas/tests/frame/indexing/test_take.py
14 issues
Line: 1
Column: 1
import pytest
import pandas._testing as tm
class TestDataFrameTake:
def test_take(self, float_frame):
# homogeneous
order = [3, 1, 2, 0]
Reported by Pylint.
Line: 1
Column: 1
import pytest
import pandas._testing as tm
class TestDataFrameTake:
def test_take(self, float_frame):
# homogeneous
order = [3, 1, 2, 0]
Reported by Pylint.
Line: 6
Column: 1
import pandas._testing as tm
class TestDataFrameTake:
def test_take(self, float_frame):
# homogeneous
order = [3, 1, 2, 0]
for df in [float_frame]:
Reported by Pylint.
Line: 7
Column: 5
class TestDataFrameTake:
def test_take(self, float_frame):
# homogeneous
order = [3, 1, 2, 0]
for df in [float_frame]:
result = df.take(order, axis=0)
Reported by Pylint.
Line: 7
Column: 5
class TestDataFrameTake:
def test_take(self, float_frame):
# homogeneous
order = [3, 1, 2, 0]
for df in [float_frame]:
result = df.take(order, axis=0)
Reported by Pylint.
Line: 10
Column: 13
def test_take(self, float_frame):
# homogeneous
order = [3, 1, 2, 0]
for df in [float_frame]:
result = df.take(order, axis=0)
expected = df.reindex(df.index.take(order))
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 23
Column: 13
# negative indices
order = [2, 1, -1]
for df in [float_frame]:
result = df.take(order, axis=0)
expected = df.reindex(df.index.take(order))
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 48
Column: 5
with pytest.raises(IndexError, match=msg):
df.take([3, 1, 2, -5], axis=1)
def test_take_mixed_type(self, float_string_frame):
# mixed-dtype
order = [4, 1, 2, 0, 3]
for df in [float_string_frame]:
Reported by Pylint.
Line: 48
Column: 5
with pytest.raises(IndexError, match=msg):
df.take([3, 1, 2, -5], axis=1)
def test_take_mixed_type(self, float_string_frame):
# mixed-dtype
order = [4, 1, 2, 0, 3]
for df in [float_string_frame]:
Reported by Pylint.
Line: 52
Column: 13
# mixed-dtype
order = [4, 1, 2, 0, 3]
for df in [float_string_frame]:
result = df.take(order, axis=0)
expected = df.reindex(df.index.take(order))
tm.assert_frame_equal(result, expected)
Reported by Pylint.
pandas/tests/arrays/floating/test_repr.py
14 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas.core.arrays.floating import (
Float32Dtype,
Float64Dtype,
)
Reported by Pylint.
Line: 14
Column: 5
def test_dtypes(dtype):
# smoke tests on auto dtype construction
np.dtype(dtype.type).kind == "f"
assert dtype.name is not None
@pytest.mark.parametrize(
"dtype, expected",
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas.core.arrays.floating import (
Float32Dtype,
Float64Dtype,
)
Reported by Pylint.
Line: 11
Column: 1
)
def test_dtypes(dtype):
# smoke tests on auto dtype construction
np.dtype(dtype.type).kind == "f"
assert dtype.name is not None
Reported by Pylint.
Line: 15
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# smoke tests on auto dtype construction
np.dtype(dtype.type).kind == "f"
assert dtype.name is not None
@pytest.mark.parametrize(
"dtype, expected",
[(Float32Dtype(), "Float32Dtype()"), (Float64Dtype(), "Float64Dtype()")],
Reported by Bandit.
Line: 21
Column: 1
@pytest.mark.parametrize(
"dtype, expected",
[(Float32Dtype(), "Float32Dtype()"), (Float64Dtype(), "Float64Dtype()")],
)
def test_repr_dtype(dtype, expected):
assert repr(dtype) == expected
def test_repr_array():
Reported by Pylint.
Line: 23
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
[(Float32Dtype(), "Float32Dtype()"), (Float64Dtype(), "Float64Dtype()")],
)
def test_repr_dtype(dtype, expected):
assert repr(dtype) == expected
def test_repr_array():
result = repr(pd.array([1.0, None, 3.0]))
expected = "<FloatingArray>\n[1.0, <NA>, 3.0]\nLength: 3, dtype: Float64"
Reported by Bandit.
Line: 26
Column: 1
assert repr(dtype) == expected
def test_repr_array():
result = repr(pd.array([1.0, None, 3.0]))
expected = "<FloatingArray>\n[1.0, <NA>, 3.0]\nLength: 3, dtype: Float64"
assert result == expected
Reported by Pylint.
Line: 29
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_repr_array():
result = repr(pd.array([1.0, None, 3.0]))
expected = "<FloatingArray>\n[1.0, <NA>, 3.0]\nLength: 3, dtype: Float64"
assert result == expected
def test_repr_array_long():
data = pd.array([1.0, 2.0, None] * 1000)
expected = """<FloatingArray>
Reported by Bandit.
Line: 32
Column: 1
assert result == expected
def test_repr_array_long():
data = pd.array([1.0, 2.0, None] * 1000)
expected = """<FloatingArray>
[ 1.0, 2.0, <NA>, 1.0, 2.0, <NA>, 1.0, 2.0, <NA>, 1.0,
...
<NA>, 1.0, 2.0, <NA>, 1.0, 2.0, <NA>, 1.0, 2.0, <NA>]
Reported by Pylint.
pandas/core/indexers/objects.py
14 issues
Line: 8
Column: 1
import numpy as np
from pandas._libs.window.indexers import calculate_variable_window_bounds
from pandas.util._decorators import Appender
from pandas.core.dtypes.common import ensure_platform_int
from pandas.tseries.offsets import Nano
Reported by Pylint.
Line: 8
Column: 1
import numpy as np
from pandas._libs.window.indexers import calculate_variable_window_bounds
from pandas.util._decorators import Appender
from pandas.core.dtypes.common import ensure_platform_int
from pandas.tseries.offsets import Nano
Reported by Pylint.
Line: 327
Column: 13
start_arrays = []
end_arrays = []
window_indicies_start = 0
for key, indices in self.groupby_indicies.items():
index_array: np.ndarray | None
if self.index_array is not None:
index_array = self.index_array.take(ensure_platform_int(indices))
else:
Reported by Pylint.
Line: 15
Column: 1
from pandas.tseries.offsets import Nano
get_window_bounds_doc = """
Computes the bounds of a window.
Parameters
----------
num_values : int, default 0
Reported by Pylint.
Line: 40
Column: 1
"""
class BaseIndexer:
"""Base class for window bounds calculations."""
def __init__(
self, index_array: np.ndarray | None = None, window_size: int = 0, **kwargs
):
Reported by Pylint.
Line: 59
Column: 5
setattr(self, key, value)
@Appender(get_window_bounds_doc)
def get_window_bounds(
self,
num_values: int = 0,
min_periods: int | None = None,
center: bool | None = None,
closed: str | None = None,
Reported by Pylint.
Line: 70
Column: 1
raise NotImplementedError
class FixedWindowIndexer(BaseIndexer):
"""Creates window boundaries that are of fixed length."""
@Appender(get_window_bounds_doc)
def get_window_bounds(
self,
Reported by Pylint.
Line: 100
Column: 1
return start, end
class VariableWindowIndexer(BaseIndexer):
"""Creates window boundaries that are of variable length, namely for time series."""
@Appender(get_window_bounds_doc)
def get_window_bounds(
self,
Reported by Pylint.
Line: 126
Column: 1
)
class VariableOffsetWindowIndexer(BaseIndexer):
"""Calculate window boundaries based on a non-fixed offset such as a BusinessDay"""
def __init__(
self,
index_array: np.ndarray | None = None,
Reported by Pylint.
Line: 208
Column: 1
return start, end
class ExpandingIndexer(BaseIndexer):
"""Calculate expanding window bounds, mimicking df.expanding()"""
@Appender(get_window_bounds_doc)
def get_window_bounds(
self,
Reported by Pylint.
pandas/tests/arrays/categorical/test_subclass.py
14 issues
Line: 1
Column: 1
from pandas import Categorical
import pandas._testing as tm
class TestCategoricalSubclassing:
def test_constructor(self):
sc = tm.SubclassedCategorical(["a", "b", "c"])
assert isinstance(sc, tm.SubclassedCategorical)
tm.assert_categorical_equal(sc, Categorical(["a", "b", "c"]))
Reported by Pylint.
Line: 5
Column: 1
import pandas._testing as tm
class TestCategoricalSubclassing:
def test_constructor(self):
sc = tm.SubclassedCategorical(["a", "b", "c"])
assert isinstance(sc, tm.SubclassedCategorical)
tm.assert_categorical_equal(sc, Categorical(["a", "b", "c"]))
Reported by Pylint.
Line: 6
Column: 5
class TestCategoricalSubclassing:
def test_constructor(self):
sc = tm.SubclassedCategorical(["a", "b", "c"])
assert isinstance(sc, tm.SubclassedCategorical)
tm.assert_categorical_equal(sc, Categorical(["a", "b", "c"]))
def test_from_codes(self):
Reported by Pylint.
Line: 6
Column: 5
class TestCategoricalSubclassing:
def test_constructor(self):
sc = tm.SubclassedCategorical(["a", "b", "c"])
assert isinstance(sc, tm.SubclassedCategorical)
tm.assert_categorical_equal(sc, Categorical(["a", "b", "c"]))
def test_from_codes(self):
Reported by Pylint.
Line: 7
Column: 9
class TestCategoricalSubclassing:
def test_constructor(self):
sc = tm.SubclassedCategorical(["a", "b", "c"])
assert isinstance(sc, tm.SubclassedCategorical)
tm.assert_categorical_equal(sc, Categorical(["a", "b", "c"]))
def test_from_codes(self):
sc = tm.SubclassedCategorical.from_codes([1, 0, 2], ["a", "b", "c"])
Reported by Pylint.
Line: 8
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
class TestCategoricalSubclassing:
def test_constructor(self):
sc = tm.SubclassedCategorical(["a", "b", "c"])
assert isinstance(sc, tm.SubclassedCategorical)
tm.assert_categorical_equal(sc, Categorical(["a", "b", "c"]))
def test_from_codes(self):
sc = tm.SubclassedCategorical.from_codes([1, 0, 2], ["a", "b", "c"])
assert isinstance(sc, tm.SubclassedCategorical)
Reported by Bandit.
Line: 11
Column: 5
assert isinstance(sc, tm.SubclassedCategorical)
tm.assert_categorical_equal(sc, Categorical(["a", "b", "c"]))
def test_from_codes(self):
sc = tm.SubclassedCategorical.from_codes([1, 0, 2], ["a", "b", "c"])
assert isinstance(sc, tm.SubclassedCategorical)
exp = Categorical.from_codes([1, 0, 2], ["a", "b", "c"])
tm.assert_categorical_equal(sc, exp)
Reported by Pylint.
Line: 11
Column: 5
assert isinstance(sc, tm.SubclassedCategorical)
tm.assert_categorical_equal(sc, Categorical(["a", "b", "c"]))
def test_from_codes(self):
sc = tm.SubclassedCategorical.from_codes([1, 0, 2], ["a", "b", "c"])
assert isinstance(sc, tm.SubclassedCategorical)
exp = Categorical.from_codes([1, 0, 2], ["a", "b", "c"])
tm.assert_categorical_equal(sc, exp)
Reported by Pylint.
Line: 12
Column: 9
tm.assert_categorical_equal(sc, Categorical(["a", "b", "c"]))
def test_from_codes(self):
sc = tm.SubclassedCategorical.from_codes([1, 0, 2], ["a", "b", "c"])
assert isinstance(sc, tm.SubclassedCategorical)
exp = Categorical.from_codes([1, 0, 2], ["a", "b", "c"])
tm.assert_categorical_equal(sc, exp)
def test_map(self):
Reported by Pylint.
Line: 13
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_from_codes(self):
sc = tm.SubclassedCategorical.from_codes([1, 0, 2], ["a", "b", "c"])
assert isinstance(sc, tm.SubclassedCategorical)
exp = Categorical.from_codes([1, 0, 2], ["a", "b", "c"])
tm.assert_categorical_equal(sc, exp)
def test_map(self):
sc = tm.SubclassedCategorical(["a", "b", "c"])
Reported by Bandit.
pandas/tests/frame/methods/test_reindex_like.py
13 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import DataFrame
import pandas._testing as tm
class TestDataFrameReindexLike:
def test_reindex_like(self, float_frame):
Reported by Pylint.
Line: 22
Column: 49
("backfill", [0, 1, 2, 2]),
],
)
def test_reindex_like_methods(self, method, expected_values):
df = DataFrame({"x": list(range(5))})
result = df.reindex_like(df, method=method, tolerance=0)
tm.assert_frame_equal(df, result)
result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0])
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import DataFrame
import pandas._testing as tm
class TestDataFrameReindexLike:
def test_reindex_like(self, float_frame):
Reported by Pylint.
Line: 8
Column: 1
import pandas._testing as tm
class TestDataFrameReindexLike:
def test_reindex_like(self, float_frame):
other = float_frame.reindex(index=float_frame.index[:10], columns=["C", "B"])
tm.assert_frame_equal(other, float_frame.reindex_like(other))
Reported by Pylint.
Line: 9
Column: 5
class TestDataFrameReindexLike:
def test_reindex_like(self, float_frame):
other = float_frame.reindex(index=float_frame.index[:10], columns=["C", "B"])
tm.assert_frame_equal(other, float_frame.reindex_like(other))
@pytest.mark.parametrize(
Reported by Pylint.
Line: 9
Column: 5
class TestDataFrameReindexLike:
def test_reindex_like(self, float_frame):
other = float_frame.reindex(index=float_frame.index[:10], columns=["C", "B"])
tm.assert_frame_equal(other, float_frame.reindex_like(other))
@pytest.mark.parametrize(
Reported by Pylint.
Line: 20
Column: 5
("nearest", [0, 1, 1, 2]),
("pad", [np.nan, 0, 1, 1]),
("backfill", [0, 1, 2, 2]),
],
)
def test_reindex_like_methods(self, method, expected_values):
df = DataFrame({"x": list(range(5))})
result = df.reindex_like(df, method=method, tolerance=0)
Reported by Pylint.
Line: 20
Column: 5
("nearest", [0, 1, 1, 2]),
("pad", [np.nan, 0, 1, 1]),
("backfill", [0, 1, 2, 2]),
],
)
def test_reindex_like_methods(self, method, expected_values):
df = DataFrame({"x": list(range(5))})
result = df.reindex_like(df, method=method, tolerance=0)
Reported by Pylint.
Line: 23
Column: 9
],
)
def test_reindex_like_methods(self, method, expected_values):
df = DataFrame({"x": list(range(5))})
result = df.reindex_like(df, method=method, tolerance=0)
tm.assert_frame_equal(df, result)
result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0])
tm.assert_frame_equal(df, result)
Reported by Pylint.
Line: 30
Column: 5
result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0])
tm.assert_frame_equal(df, result)
def test_reindex_like_subclass(self):
# https://github.com/pandas-dev/pandas/issues/31925
class MyDataFrame(DataFrame):
pass
expected = DataFrame()
Reported by Pylint.
pandas/core/array_algos/replace.py
13 issues
Line: 44
Column: 1
return regex
def compare_or_regex_search(
a: ArrayLike, b: Scalar | Pattern, regex: bool, mask: np.ndarray
) -> ArrayLike | bool:
"""
Compare two array-like inputs of the same shape or two scalar values
Reported by Pylint.
Line: 44
Column: 1
return regex
def compare_or_regex_search(
a: ArrayLike, b: Scalar | Pattern, regex: bool, mask: np.ndarray
) -> ArrayLike | bool:
"""
Compare two array-like inputs of the same shape or two scalar values
Reported by Pylint.
Line: 67
Column: 5
if isna(b):
return ~mask
def _check_comparison_types(
result: ArrayLike | bool, a: ArrayLike, b: Scalar | Pattern
):
"""
Raises an error if the two arrays (a,b) cannot be compared.
Otherwise, returns the comparison result as expected.
Reported by Pylint.
Line: 67
Column: 5
if isna(b):
return ~mask
def _check_comparison_types(
result: ArrayLike | bool, a: ArrayLike, b: Scalar | Pattern
):
"""
Raises an error if the two arrays (a,b) cannot be compared.
Otherwise, returns the comparison result as expected.
Reported by Pylint.
Line: 84
Column: 9
)
if not regex:
op = lambda x: operator.eq(x, b)
else:
op = np.vectorize(
lambda x: bool(re.search(b, x))
if isinstance(x, str) and isinstance(b, (str, Pattern))
else False
Reported by Pylint.
Line: 86
Column: 9
if not regex:
op = lambda x: operator.eq(x, b)
else:
op = np.vectorize(
lambda x: bool(re.search(b, x))
if isinstance(x, str) and isinstance(b, (str, Pattern))
else False
)
Reported by Pylint.
Line: 96
Column: 5
if isinstance(a, np.ndarray):
a = a[mask]
if is_numeric_v_string_like(a, b):
# GH#29553 avoid deprecation warnings from numpy
return np.zeros(a.shape, dtype=bool)
elif is_datetimelike_v_numeric(a, b):
# GH#29553 avoid deprecation warnings from numpy
Reported by Pylint.
Line: 118
Column: 1
return result
def replace_regex(values: ArrayLike, rx: re.Pattern, value, mask: np.ndarray | None):
"""
Parameters
----------
values : ArrayLike
Object dtype.
Reported by Pylint.
Line: 137
Column: 9
# whose replacement is not a string (numeric, nan, object)
if isna(value) or not isinstance(value, str):
def re_replacer(s):
if is_re(rx) and isinstance(s, str):
return value if rx.search(s) is not None else s
else:
return s
Reported by Pylint.
Line: 138
Column: 13
if isna(value) or not isinstance(value, str):
def re_replacer(s):
if is_re(rx) and isinstance(s, str):
return value if rx.search(s) is not None else s
else:
return s
else:
Reported by Pylint.
pandas/tests/indexes/base_class/test_constructors.py
13 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import (
Index,
MultiIndex,
)
import pandas._testing as tm
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import (
Index,
MultiIndex,
)
import pandas._testing as tm
Reported by Pylint.
Line: 11
Column: 1
import pandas._testing as tm
class TestIndexConstructor:
# Tests for the Index constructor, specifically for cases that do
# not return a subclass
@pytest.mark.parametrize("value", [1, np.int64(1)])
def test_constructor_corner(self, value):
Reported by Pylint.
Line: 16
Column: 5
# not return a subclass
@pytest.mark.parametrize("value", [1, np.int64(1)])
def test_constructor_corner(self, value):
# corner case
msg = (
r"Index\(\.\.\.\) must be called with a collection of some "
f"kind, {value} was passed"
)
Reported by Pylint.
Line: 16
Column: 5
# not return a subclass
@pytest.mark.parametrize("value", [1, np.int64(1)])
def test_constructor_corner(self, value):
# corner case
msg = (
r"Index\(\.\.\.\) must be called with a collection of some "
f"kind, {value} was passed"
)
Reported by Pylint.
Line: 26
Column: 5
Index(value)
@pytest.mark.parametrize("index_vals", [[("A", 1), "B"], ["B", ("A", 1)]])
def test_construction_list_mixed_tuples(self, index_vals):
# see gh-10697: if we are constructing from a mixed list of tuples,
# make sure that we are independent of the sorting order.
index = Index(index_vals)
assert isinstance(index, Index)
assert not isinstance(index, MultiIndex)
Reported by Pylint.
Line: 26
Column: 5
Index(value)
@pytest.mark.parametrize("index_vals", [[("A", 1), "B"], ["B", ("A", 1)]])
def test_construction_list_mixed_tuples(self, index_vals):
# see gh-10697: if we are constructing from a mixed list of tuples,
# make sure that we are independent of the sorting order.
index = Index(index_vals)
assert isinstance(index, Index)
assert not isinstance(index, MultiIndex)
Reported by Pylint.
Line: 30
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# see gh-10697: if we are constructing from a mixed list of tuples,
# make sure that we are independent of the sorting order.
index = Index(index_vals)
assert isinstance(index, Index)
assert not isinstance(index, MultiIndex)
def test_constructor_wrong_kwargs(self):
# GH #19348
with pytest.raises(TypeError, match="Unexpected keyword arguments {'foo'}"):
Reported by Bandit.
Line: 31
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# make sure that we are independent of the sorting order.
index = Index(index_vals)
assert isinstance(index, Index)
assert not isinstance(index, MultiIndex)
def test_constructor_wrong_kwargs(self):
# GH #19348
with pytest.raises(TypeError, match="Unexpected keyword arguments {'foo'}"):
with tm.assert_produces_warning(FutureWarning):
Reported by Bandit.
Line: 33
Column: 5
assert isinstance(index, Index)
assert not isinstance(index, MultiIndex)
def test_constructor_wrong_kwargs(self):
# GH #19348
with pytest.raises(TypeError, match="Unexpected keyword arguments {'foo'}"):
with tm.assert_produces_warning(FutureWarning):
Index([], foo="bar")
Reported by Pylint.
pandas/core/array_algos/take.py
13 issues
Line: 12
Column: 1
import numpy as np
from pandas._libs import (
algos as libalgos,
lib,
)
from pandas._typing import ArrayLike
Reported by Pylint.
Line: 12
Column: 1
import numpy as np
from pandas._libs import (
algos as libalgos,
lib,
)
from pandas._typing import ArrayLike
Reported by Pylint.
Line: 1
Column: 1
from __future__ import annotations
import functools
from typing import (
TYPE_CHECKING,
cast,
overload,
)
Reported by Pylint.
Line: 217
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
"""
# This is only called from one place in DataFrame._reindex_multi,
# so we know indexer is well-behaved.
assert indexer is not None
assert indexer[0] is not None
assert indexer[1] is not None
row_idx, col_idx = indexer
Reported by Bandit.
Line: 218
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# This is only called from one place in DataFrame._reindex_multi,
# so we know indexer is well-behaved.
assert indexer is not None
assert indexer[0] is not None
assert indexer[1] is not None
row_idx, col_idx = indexer
row_idx = ensure_platform_int(row_idx)
Reported by Bandit.
Line: 219
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# so we know indexer is well-behaved.
assert indexer is not None
assert indexer[0] is not None
assert indexer[1] is not None
row_idx, col_idx = indexer
row_idx = ensure_platform_int(row_idx)
col_idx = ensure_platform_int(col_idx)
Reported by Bandit.
Line: 324
Column: 1
return func
def _view_wrapper(f, arr_dtype=None, out_dtype=None, fill_wrap=None):
def wrapper(
arr: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=np.nan
):
if arr_dtype is not None:
arr = arr.view(arr_dtype)
Reported by Pylint.
Line: 339
Column: 1
return wrapper
def _convert_wrapper(f, conv_dtype):
def wrapper(
arr: np.ndarray, indexer: np.ndarray, out: np.ndarray, fill_value=np.nan
):
if conv_dtype == object:
# GH#39755 avoid casting dt64/td64 to integers
Reported by Pylint.
Line: 465
Column: 1
}
def _take_nd_object(
arr: np.ndarray,
indexer: np.ndarray, # np.ndarray[np.intp]
out: np.ndarray,
axis: int,
fill_value,
Reported by Pylint.
Line: 510
Column: 5
out[row_mask, :] = fill_value
if col_needs:
out[:, col_mask] = fill_value
for i in range(len(row_idx)):
u_ = row_idx[i]
for j in range(len(col_idx)):
v = col_idx[j]
out[i, j] = arr[u_, v]
Reported by Pylint.