The following issues were found
pandas/core/internals/__init__.py
4 issues
Line: 26
Column: 5
__all__ = [
"Block",
"CategoricalBlock",
"NumericBlock",
"DatetimeTZBlock",
"ExtensionBlock",
"ObjectBlock",
"make_block",
Reported by Pylint.
Line: 1
Column: 1
from pandas.core.internals.api import make_block
from pandas.core.internals.array_manager import (
ArrayManager,
SingleArrayManager,
)
from pandas.core.internals.base import (
DataManager,
SingleDataManager,
)
Reported by Pylint.
Line: 45
Column: 5
def __getattr__(name: str):
import warnings
if name == "CategoricalBlock":
warnings.warn(
"CategoricalBlock is deprecated and will be removed in a future version. "
"Use ExtensionBlock instead.",
Reported by Pylint.
Line: 54
Column: 9
DeprecationWarning,
stacklevel=2,
)
from pandas.core.internals.blocks import CategoricalBlock
return CategoricalBlock
raise AttributeError(f"module 'pandas.core.internals' has no attribute '{name}'")
Reported by Pylint.
pandas/tests/arithmetic/test_array_ops.py
4 issues
Line: 4
Column: 1
import operator
import numpy as np
import pytest
import pandas._testing as tm
from pandas.core.ops.array_ops import (
comparison_op,
na_logical_op,
Reported by Pylint.
Line: 1
Column: 1
import operator
import numpy as np
import pytest
import pandas._testing as tm
from pandas.core.ops.array_ops import (
comparison_op,
na_logical_op,
Reported by Pylint.
Line: 13
Column: 1
)
def test_na_logical_op_2d():
left = np.arange(8).reshape(4, 2)
right = left.astype(object)
right[0, 0] = np.nan
# Check that we fall back to the vec_binop branch
Reported by Pylint.
Line: 27
Column: 1
tm.assert_numpy_array_equal(result, expected)
def test_object_comparison_2d():
left = np.arange(9).reshape(3, 3).astype(object)
right = left.T
result = comparison_op(left, right, operator.eq)
expected = np.eye(3).astype(bool)
Reported by Pylint.
pandas/core/dtypes/inference.py
4 issues
Line: 10
Column: 1
import numpy as np
from pandas._libs import lib
from pandas._typing import ArrayLike
is_bool = lib.is_bool
is_integer = lib.is_integer
Reported by Pylint.
Line: 419
Column: 9
"""
try:
from dataclasses import is_dataclass
return is_dataclass(item) and not isinstance(item, type)
except ImportError:
return False
Reported by Pylint.
Line: 419
Column: 9
"""
try:
from dataclasses import is_dataclass
return is_dataclass(item) and not isinstance(item, type)
except ImportError:
return False
Reported by Pylint.
Line: 447
Column: 5
return False
dtype = arr.dtype
if dtype == np.dtype(bool):
return True
elif dtype == np.dtype("object"):
return lib.is_bool_array(arr.ravel("K"))
return False
Reported by Pylint.
pandas/tests/dtypes/cast/test_maybe_box_native.py
4 issues
Line: 4
Column: 1
from datetime import datetime
import numpy as np
import pytest
from pandas.core.dtypes.cast import maybe_box_native
from pandas import (
Interval,
Reported by Pylint.
Line: 1
Column: 1
from datetime import datetime
import numpy as np
import pytest
from pandas.core.dtypes.cast import maybe_box_native
from pandas import (
Interval,
Reported by Pylint.
Line: 35
Column: 1
(Timedelta(1, "D"), Timedelta),
(Interval(0, 1), Interval),
(Period("4Q2005"), Period),
],
)
def test_maybe_box_native(obj, expected_dtype):
boxed_obj = maybe_box_native(obj)
result_dtype = type(boxed_obj)
assert result_dtype is expected_dtype
Reported by Pylint.
Line: 40
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_maybe_box_native(obj, expected_dtype):
boxed_obj = maybe_box_native(obj)
result_dtype = type(boxed_obj)
assert result_dtype is expected_dtype
Reported by Bandit.
pandas/core/groupby/categorical.py
4 issues
Line: 1
Column: 1
from __future__ import annotations
import numpy as np
from pandas.core.algorithms import unique1d
from pandas.core.arrays.categorical import (
Categorical,
CategoricalDtype,
recode_for_categories,
Reported by Pylint.
Line: 14
Column: 1
from pandas.core.indexes.api import CategoricalIndex
def recode_for_groupby(
c: Categorical, sort: bool, observed: bool
) -> tuple[Categorical, Categorical | None]:
"""
Code the categories to ensure we can groupby for categoricals.
Reported by Pylint.
Line: 91
Column: 1
return c.reorder_categories(cat.categories), None
def recode_from_groupby(
c: Categorical, sort: bool, ci: CategoricalIndex
) -> CategoricalIndex:
"""
Reverse the codes_to_groupby to account for sort / observed.
Reported by Pylint.
Line: 91
Column: 1
return c.reorder_categories(cat.categories), None
def recode_from_groupby(
c: Categorical, sort: bool, ci: CategoricalIndex
) -> CategoricalIndex:
"""
Reverse the codes_to_groupby to account for sort / observed.
Reported by Pylint.
pandas/tests/arrays/boolean/test_indexing.py
4 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
import pandas._testing as tm
@pytest.mark.parametrize("na", [None, np.nan, pd.NA])
def test_setitem_missing_values(na):
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
import pandas._testing as tm
@pytest.mark.parametrize("na", [None, np.nan, pd.NA])
def test_setitem_missing_values(na):
Reported by Pylint.
Line: 9
Column: 1
@pytest.mark.parametrize("na", [None, np.nan, pd.NA])
def test_setitem_missing_values(na):
arr = pd.array([True, False, None], dtype="boolean")
expected = pd.array([True, None, None], dtype="boolean")
arr[1] = na
tm.assert_extension_array_equal(arr, expected)
Reported by Pylint.
Line: 9
Column: 1
@pytest.mark.parametrize("na", [None, np.nan, pd.NA])
def test_setitem_missing_values(na):
arr = pd.array([True, False, None], dtype="boolean")
expected = pd.array([True, None, None], dtype="boolean")
arr[1] = na
tm.assert_extension_array_equal(arr, expected)
Reported by Pylint.
pandas/_libs/src/parse_helper.h
4 issues
Line: 52
Column: 13
CWE codes:
126
if (!status) {
/* handle inf/-inf infinity/-infinity */
if (strlen(data) == 3) {
if (0 == strcasecmp(data, "inf")) {
*result = HUGE_VAL;
*maybe_int = 0;
} else {
goto parsingerror;
Reported by FlawFinder.
Line: 59
Column: 20
CWE codes:
126
} else {
goto parsingerror;
}
} else if (strlen(data) == 4) {
if (0 == strcasecmp(data, "-inf")) {
*result = -HUGE_VAL;
*maybe_int = 0;
} else if (0 == strcasecmp(data, "+inf")) {
*result = HUGE_VAL;
Reported by FlawFinder.
Line: 69
Column: 20
CWE codes:
126
} else {
goto parsingerror;
}
} else if (strlen(data) == 8) {
if (0 == strcasecmp(data, "infinity")) {
*result = HUGE_VAL;
*maybe_int = 0;
} else {
goto parsingerror;
Reported by FlawFinder.
Line: 76
Column: 20
CWE codes:
126
} else {
goto parsingerror;
}
} else if (strlen(data) == 9) {
if (0 == strcasecmp(data, "-infinity")) {
*result = -HUGE_VAL;
*maybe_int = 0;
} else if (0 == strcasecmp(data, "+infinity")) {
*result = HUGE_VAL;
Reported by FlawFinder.
pandas/core/indexing.py
3 issues
Line: 794
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
retval = getattr(retval, self.name)._getitem_axis(key, axis=i)
# We should never have retval.ndim < self.ndim, as that should
# be handled by the _getitem_lowerdim call above.
assert retval.ndim == self.ndim
return retval
def _getitem_lowerdim(self, tup: tuple):
Reported by Bandit.
Line: 1645
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
Setitem column-wise.
"""
# Above we only set take_split_path to True for 2D cases
assert self.ndim == 2
if not isinstance(indexer, tuple):
indexer = _tuplify(self.ndim, indexer)
if len(indexer) > self.ndim:
raise IndexError("too many indices for array")
Reported by Bandit.
Line: 2170
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
@property
def _axes_are_unique(self) -> bool:
# Only relevant for self.ndim == 2
assert self.ndim == 2
return self.obj.index.is_unique and self.obj.columns.is_unique
def __getitem__(self, key):
if self.ndim == 2 and not self._axes_are_unique:
Reported by Bandit.
pandas/core/flags.py
3 issues
Line: 92
Column: 17
if not value:
for ax in obj.axes:
ax._maybe_check_unique()
self._allows_duplicate_labels = value
def __getitem__(self, key):
if key not in self._keys:
Reported by Pylint.
Line: 1
Column: 1
import weakref
class Flags:
"""
Flags that apply to pandas objects.
.. versionadded:: 1.2.0
Reported by Pylint.
Line: 91
Column: 17
raise ValueError("This flag's object has been deleted.")
if not value:
for ax in obj.axes:
ax._maybe_check_unique()
self._allows_duplicate_labels = value
def __getitem__(self, key):
Reported by Pylint.
pandas/core/dtypes/generic.py
3 issues
Line: 4
Column: 1
""" define generic base classes for pandas objects """
from __future__ import annotations
from typing import (
TYPE_CHECKING,
Type,
cast,
)
Reported by Pylint.
Line: 44
Column: 16
# https://github.com/python/mypy/issues/1006
# error: 'classmethod' used with a non-method
@classmethod # type: ignore[misc]
def _check(cls, inst) -> bool:
return getattr(inst, attr, "_typ") in comp
dct = {"__instancecheck__": _check, "__subclasscheck__": _check}
meta = type("ABCBase", (type,), dct)
return meta(name, (), dct)
Reported by Pylint.
Line: 39
Column: 1
# define abstract base classes to enable isinstance type checking on our
# objects
def create_pandas_abc_type(name, attr, comp):
# https://github.com/python/mypy/issues/1006
# error: 'classmethod' used with a non-method
@classmethod # type: ignore[misc]
def _check(cls, inst) -> bool:
Reported by Pylint.