The following issues were found
pandas/tests/io/excel/__init__.py
4 issues
Line: 1
Column: 1
import pytest
from pandas.compat._optional import (
get_version,
import_optional_dependency,
)
from pandas.util.version import Version
Reported by Pylint.
Line: 33
Column: 5
if import_optional_dependency("xlrd", errors="ignore") is None:
xlrd_version = None
else:
import xlrd
xlrd_version = Version(get_version(xlrd))
Reported by Pylint.
Line: 1
Column: 1
import pytest
from pandas.compat._optional import (
get_version,
import_optional_dependency,
)
from pandas.util.version import Version
Reported by Pylint.
Line: 31
Column: 5
if import_optional_dependency("xlrd", errors="ignore") is None:
xlrd_version = None
else:
import xlrd
xlrd_version = Version(get_version(xlrd))
Reported by Pylint.
pandas/tests/indexing/test_na_indexing.py
4 issues
Line: 1
Column: 1
import pytest
import pandas as pd
import pandas._testing as tm
@pytest.mark.parametrize(
"values, dtype",
[
Reported by Pylint.
Line: 1
Column: 1
import pytest
import pandas as pd
import pandas._testing as tm
@pytest.mark.parametrize(
"values, dtype",
[
Reported by Pylint.
Line: 25
Column: 1
)
@pytest.mark.parametrize(
"mask", [[True, False, False], [True, True, True], [False, False, False]]
)
@pytest.mark.parametrize("indexer_class", [list, pd.array, pd.Index, pd.Series])
@pytest.mark.parametrize("frame", [True, False])
def test_series_mask_boolean(values, dtype, mask, indexer_class, frame):
# In case len(values) < 3
index = ["a", "b", "c"][: len(values)]
Reported by Pylint.
Line: 66
Column: 1
tm.assert_equal(result, expected)
def test_na_treated_as_false(frame_or_series, indexer_sli):
# https://github.com/pandas-dev/pandas/issues/31503
obj = frame_or_series([1, 2, 3])
mask = pd.array([True, False, None], dtype="boolean")
Reported by Pylint.
pandas/util/_tester.py
4 issues
Line: 16
Column: 9
except ImportError as err:
raise ImportError("Need pytest>=5.0.1 to run tests") from err
try:
import hypothesis # noqa
except ImportError as err:
raise ImportError("Need hypothesis>=3.58 to run tests") from err
cmd = ["--skip-slow", "--skip-network", "--skip-db"]
if extra_args:
if not isinstance(extra_args, list):
Reported by Pylint.
Line: 10
Column: 1
PKG = os.path.dirname(os.path.dirname(__file__))
def test(extra_args=None):
try:
import pytest
except ImportError as err:
raise ImportError("Need pytest>=5.0.1 to run tests") from err
try:
Reported by Pylint.
Line: 12
Column: 9
def test(extra_args=None):
try:
import pytest
except ImportError as err:
raise ImportError("Need pytest>=5.0.1 to run tests") from err
try:
import hypothesis # noqa
except ImportError as err:
Reported by Pylint.
Line: 16
Column: 9
except ImportError as err:
raise ImportError("Need pytest>=5.0.1 to run tests") from err
try:
import hypothesis # noqa
except ImportError as err:
raise ImportError("Need hypothesis>=3.58 to run tests") from err
cmd = ["--skip-slow", "--skip-network", "--skip-db"]
if extra_args:
if not isinstance(extra_args, list):
Reported by Pylint.
pandas/tests/strings/conftest.py
4 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import Series
from pandas.core import strings as strings
_any_string_method = [
("cat", (), {"sep": ","}),
("cat", (Series(list("zyx")),), {"sep": ",", "join": "left"}),
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import Series
from pandas.core import strings as strings
_any_string_method = [
("cat", (), {"sep": ","}),
("cat", (Series(list("zyx")),), {"sep": ",", "join": "left"}),
Reported by Pylint.
Line: 5
Column: 1
import pytest
from pandas import Series
from pandas.core import strings as strings
_any_string_method = [
("cat", (), {"sep": ","}),
("cat", (Series(list("zyx")),), {"sep": ",", "join": "left"}),
("center", (10,), {}),
Reported by Pylint.
Line: 95
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
} - set(ids)
# test that the above list captures all methods of StringMethods
assert not missing_methods
@pytest.fixture(params=_any_string_method, ids=ids)
def any_string_method(request):
"""
Reported by Bandit.
pandas/tests/tseries/offsets/test_easter.py
4 issues
Line: 9
Column: 1
from datetime import datetime
import pytest
from pandas.tests.tseries.offsets.common import (
Base,
assert_offset_equal,
)
Reported by Pylint.
Line: 19
Column: 1
from pandas.tseries.offsets import Easter
class TestEaster(Base):
@pytest.mark.parametrize(
"offset,date,expected",
[
(Easter(), datetime(2010, 1, 1), datetime(2010, 4, 4)),
(Easter(), datetime(2010, 4, 5), datetime(2011, 4, 24)),
Reported by Pylint.
Line: 33
Column: 5
(-Easter(2), datetime(2011, 1, 1), datetime(2009, 4, 12)),
(-Easter(), datetime(2010, 4, 4), datetime(2009, 4, 12)),
(-Easter(2), datetime(2010, 4, 4), datetime(2008, 3, 23)),
],
)
def test_offset(self, offset, date, expected):
assert_offset_equal(offset, date, expected)
Reported by Pylint.
Line: 33
Column: 5
(-Easter(2), datetime(2011, 1, 1), datetime(2009, 4, 12)),
(-Easter(), datetime(2010, 4, 4), datetime(2009, 4, 12)),
(-Easter(2), datetime(2010, 4, 4), datetime(2008, 3, 23)),
],
)
def test_offset(self, offset, date, expected):
assert_offset_equal(offset, date, expected)
Reported by Pylint.
scripts/pandas_errors_documented.py
4 issues
Line: 20
Column: 1
API_PATH = pathlib.Path("doc/source/reference/general_utility_functions.rst").resolve()
def get_defined_errors(content: str) -> set[str]:
errors = set()
for node in ast.walk(ast.parse(content)):
if isinstance(node, ast.ClassDef):
errors.add(node.name)
elif isinstance(node, ast.ImportFrom):
Reported by Pylint.
Line: 31
Column: 1
return errors
def main(argv: Sequence[str] | None = None) -> None:
parser = argparse.ArgumentParser()
parser.add_argument("path")
args = parser.parse_args(argv)
with open(args.path, encoding="utf-8") as f:
file_errors = get_defined_errors(f.read())
Reported by Pylint.
Line: 35
Column: 47
parser = argparse.ArgumentParser()
parser.add_argument("path")
args = parser.parse_args(argv)
with open(args.path, encoding="utf-8") as f:
file_errors = get_defined_errors(f.read())
with open(API_PATH) as f:
doc_errors = {
line.split(".")[1].strip() for line in f.readlines() if "errors" in line
}
Reported by Pylint.
Line: 37
Column: 28
args = parser.parse_args(argv)
with open(args.path, encoding="utf-8") as f:
file_errors = get_defined_errors(f.read())
with open(API_PATH) as f:
doc_errors = {
line.split(".")[1].strip() for line in f.readlines() if "errors" in line
}
missing = file_errors.difference(doc_errors)
if missing:
Reported by Pylint.
pandas/tests/io/pytables/test_pytables_missing.py
4 issues
Line: 1
Column: 1
import pytest
import pandas.util._test_decorators as td
import pandas as pd
import pandas._testing as tm
@td.skip_if_installed("tables")
Reported by Pylint.
Line: 1
Column: 1
import pytest
import pandas.util._test_decorators as td
import pandas as pd
import pandas._testing as tm
@td.skip_if_installed("tables")
Reported by Pylint.
Line: 10
Column: 1
@td.skip_if_installed("tables")
def test_pytables_raises():
df = pd.DataFrame({"A": [1, 2]})
with pytest.raises(ImportError, match="tables"):
with tm.ensure_clean("foo.h5") as path:
df.to_hdf(path, "df")
Reported by Pylint.
Line: 11
Column: 5
@td.skip_if_installed("tables")
def test_pytables_raises():
df = pd.DataFrame({"A": [1, 2]})
with pytest.raises(ImportError, match="tables"):
with tm.ensure_clean("foo.h5") as path:
df.to_hdf(path, "df")
Reported by Pylint.
pandas/tests/series/methods/test_duplicated.py
4 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import Series
import pandas._testing as tm
@pytest.mark.parametrize(
"keep, expected",
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import Series
import pandas._testing as tm
@pytest.mark.parametrize(
"keep, expected",
Reported by Pylint.
Line: 14
Column: 1
("first", Series([False, False, True, False, True], name="name")),
("last", Series([True, True, False, False, False], name="name")),
(False, Series([True, True, True, False, True], name="name")),
],
)
def test_duplicated_keep(keep, expected):
ser = Series(["a", "b", "b", "c", "a"], name="name")
result = ser.duplicated(keep=keep)
Reported by Pylint.
Line: 29
Column: 1
("first", Series([False, False, True, False, True])),
("last", Series([True, True, False, False, False])),
(False, Series([True, True, True, False, True])),
],
)
def test_duplicated_nan_none(keep, expected):
ser = Series([np.nan, 3, 3, None, np.nan], dtype=object)
result = ser.duplicated(keep=keep)
Reported by Pylint.
pandas/core/array_algos/putmask.py
4 issues
Line: 11
Column: 1
import numpy as np
from pandas._libs import lib
from pandas._typing import ArrayLike
from pandas.core.dtypes.cast import (
convert_scalar_for_putitemlike,
find_common_type,
Reported by Pylint.
Line: 153
Column: 3
if getattr(new, "ndim", 0) >= 1:
new = new.astype(values.dtype, copy=False)
# TODO: this prob needs some better checking for 2D cases
nlocs = mask.sum()
if nlocs > 0 and is_list_like(new) and getattr(new, "ndim", 1) == 1:
if nlocs == len(new):
# GH#30567
# If length of ``new`` is less than the length of ``values``,
Reported by Pylint.
Line: 88
Column: 9
# see if we are only masking values that if putted
# will work in the current dtype
try:
nn = new[mask]
except TypeError:
# TypeError: only integer scalar arrays can be converted to a scalar index
pass
else:
# make sure that we have a nullable type if we have nulls
Reported by Pylint.
Line: 111
Column: 17
comp = nn == nn_at
if is_list_like(comp) and comp.all():
nv = values.copy()
nv[mask] = nn_at
return nv
new = np.asarray(new)
Reported by Pylint.
pandas/tests/construction/test_extract_array.py
4 issues
Line: 9
Column: 16
def test_extract_array_rangeindex():
ri = Index(range(5))
expected = ri._values
res = extract_array(ri, extract_numpy=True, extract_range=True)
tm.assert_numpy_array_equal(res, expected)
res = extract_array(ri, extract_numpy=False, extract_range=True)
tm.assert_numpy_array_equal(res, expected)
Reported by Pylint.
Line: 1
Column: 1
from pandas import Index
import pandas._testing as tm
from pandas.core.construction import extract_array
def test_extract_array_rangeindex():
ri = Index(range(5))
expected = ri._values
Reported by Pylint.
Line: 6
Column: 1
from pandas.core.construction import extract_array
def test_extract_array_rangeindex():
ri = Index(range(5))
expected = ri._values
res = extract_array(ri, extract_numpy=True, extract_range=True)
tm.assert_numpy_array_equal(res, expected)
Reported by Pylint.
Line: 7
Column: 5
def test_extract_array_rangeindex():
ri = Index(range(5))
expected = ri._values
res = extract_array(ri, extract_numpy=True, extract_range=True)
tm.assert_numpy_array_equal(res, expected)
res = extract_array(ri, extract_numpy=False, extract_range=True)
Reported by Pylint.