The following issues were found
pandas/tests/tslibs/test_libfrequencies.py
6 issues
Line: 1
Column: 1
import pytest
from pandas._libs.tslibs.parsing import get_rule_month
from pandas.tseries import offsets
@pytest.mark.parametrize(
"obj,expected",
Reported by Pylint.
Line: 3
Column: 1
import pytest
from pandas._libs.tslibs.parsing import get_rule_month
from pandas.tseries import offsets
@pytest.mark.parametrize(
"obj,expected",
Reported by Pylint.
Line: 3
Column: 1
import pytest
from pandas._libs.tslibs.parsing import get_rule_month
from pandas.tseries import offsets
@pytest.mark.parametrize(
"obj,expected",
Reported by Pylint.
Line: 1
Column: 1
import pytest
from pandas._libs.tslibs.parsing import get_rule_month
from pandas.tseries import offsets
@pytest.mark.parametrize(
"obj,expected",
Reported by Pylint.
Line: 25
Column: 1
("A-MAY", "MAY"),
("Y-MAY", "MAY"),
(offsets.YearEnd(month=5).freqstr, "MAY"),
],
)
def test_get_rule_month(obj, expected):
result = get_rule_month(obj)
assert result == expected
Reported by Pylint.
Line: 29
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test_get_rule_month(obj, expected):
result = get_rule_month(obj)
assert result == expected
Reported by Bandit.
pandas/tests/io/pytables/test_subclass.py
6 issues
Line: 1
Column: 1
import numpy as np
from pandas import (
DataFrame,
Series,
)
import pandas._testing as tm
from pandas.tests.io.pytables.common import ensure_clean_path
Reported by Pylint.
Line: 16
Column: 1
)
class TestHDFStoreSubclass:
# GH 33748
def test_supported_for_subclass_dataframe(self):
data = {"a": [1, 2], "b": [3, 4]}
sdf = tm.SubclassedDataFrame(data, dtype=np.intp)
Reported by Pylint.
Line: 18
Column: 5
class TestHDFStoreSubclass:
# GH 33748
def test_supported_for_subclass_dataframe(self):
data = {"a": [1, 2], "b": [3, 4]}
sdf = tm.SubclassedDataFrame(data, dtype=np.intp)
expected = DataFrame(data, dtype=np.intp)
Reported by Pylint.
Line: 18
Column: 5
class TestHDFStoreSubclass:
# GH 33748
def test_supported_for_subclass_dataframe(self):
data = {"a": [1, 2], "b": [3, 4]}
sdf = tm.SubclassedDataFrame(data, dtype=np.intp)
expected = DataFrame(data, dtype=np.intp)
Reported by Pylint.
Line: 35
Column: 5
result = read_hdf(path, "df")
tm.assert_frame_equal(result, expected)
def test_supported_for_subclass_series(self):
data = [1, 2, 3]
sser = tm.SubclassedSeries(data, dtype=np.intp)
expected = Series(data, dtype=np.intp)
Reported by Pylint.
Line: 35
Column: 5
result = read_hdf(path, "df")
tm.assert_frame_equal(result, expected)
def test_supported_for_subclass_series(self):
data = [1, 2, 3]
sser = tm.SubclassedSeries(data, dtype=np.intp)
expected = Series(data, dtype=np.intp)
Reported by Pylint.
pandas/tests/io/excel/conftest.py
6 issues
Line: 1
Column: 1
import pytest
import pandas.util._test_decorators as td
import pandas._testing as tm
from pandas.io.parsers import read_csv
Reported by Pylint.
Line: 34
Column: 5
Obtain the reference data from read_csv with the Python engine.
"""
filepath = datapath("io", "data", "csv", "test1.csv")
df_ref = read_csv(filepath, index_col=0, parse_dates=True, engine="python")
return df_ref
@pytest.fixture(params=[".xls", ".xlsx", ".xlsm", ".ods", ".xlsb"])
def read_ext(request):
Reported by Pylint.
Line: 1
Column: 1
import pytest
import pandas.util._test_decorators as td
import pandas._testing as tm
from pandas.io.parsers import read_csv
Reported by Pylint.
Line: 19
Column: 1
@pytest.fixture
def tsframe():
return tm.makeTimeDataFrame()[:5]
@pytest.fixture(params=[True, False])
def merge_cells(request):
Reported by Pylint.
Line: 24
Column: 1
@pytest.fixture(params=[True, False])
def merge_cells(request):
return request.param
@pytest.fixture
def df_ref(datapath):
Reported by Pylint.
Line: 65
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
flist = proc.open_files()
yield
flist2 = proc.open_files()
assert flist == flist2
Reported by Bandit.
pandas/tests/series/methods/test_infer_objects.py
6 issues
Line: 1
Column: 1
import numpy as np
from pandas import Series
import pandas._testing as tm
class TestInferObjects:
def test_infer_objects_series(self):
# GH#11221
Reported by Pylint.
Line: 7
Column: 1
import pandas._testing as tm
class TestInferObjects:
def test_infer_objects_series(self):
# GH#11221
actual = Series(np.array([1, 2, 3], dtype="O")).infer_objects()
expected = Series([1, 2, 3])
tm.assert_series_equal(actual, expected)
Reported by Pylint.
Line: 7
Column: 1
import pandas._testing as tm
class TestInferObjects:
def test_infer_objects_series(self):
# GH#11221
actual = Series(np.array([1, 2, 3], dtype="O")).infer_objects()
expected = Series([1, 2, 3])
tm.assert_series_equal(actual, expected)
Reported by Pylint.
Line: 8
Column: 5
class TestInferObjects:
def test_infer_objects_series(self):
# GH#11221
actual = Series(np.array([1, 2, 3], dtype="O")).infer_objects()
expected = Series([1, 2, 3])
tm.assert_series_equal(actual, expected)
Reported by Pylint.
Line: 8
Column: 5
class TestInferObjects:
def test_infer_objects_series(self):
# GH#11221
actual = Series(np.array([1, 2, 3], dtype="O")).infer_objects()
expected = Series([1, 2, 3])
tm.assert_series_equal(actual, expected)
Reported by Pylint.
Line: 22
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
actual = Series(np.array([1, 2, 3, None, "a"], dtype="O")).infer_objects()
expected = Series([1, 2, 3, None, "a"])
assert actual.dtype == "object"
tm.assert_series_equal(actual, expected)
Reported by Bandit.
pandas/tests/series/methods/test_combine.py
6 issues
Line: 15
Column: 34
expected = Series([i * 10 + 3 for i in range(5)])
tm.assert_series_equal(result, expected)
result = ser.combine(22, lambda x, y: min(x, y))
expected = Series([min(i * 10, 22) for i in range(5)])
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 1
Column: 1
from pandas import Series
import pandas._testing as tm
class TestCombine:
def test_combine_scalar(self):
# GH#21248
# Note - combine() with another Series is tested elsewhere because
# it is used when testing operators
Reported by Pylint.
Line: 5
Column: 1
import pandas._testing as tm
class TestCombine:
def test_combine_scalar(self):
# GH#21248
# Note - combine() with another Series is tested elsewhere because
# it is used when testing operators
ser = Series([i * 10 for i in range(5)])
Reported by Pylint.
Line: 5
Column: 1
import pandas._testing as tm
class TestCombine:
def test_combine_scalar(self):
# GH#21248
# Note - combine() with another Series is tested elsewhere because
# it is used when testing operators
ser = Series([i * 10 for i in range(5)])
Reported by Pylint.
Line: 6
Column: 5
class TestCombine:
def test_combine_scalar(self):
# GH#21248
# Note - combine() with another Series is tested elsewhere because
# it is used when testing operators
ser = Series([i * 10 for i in range(5)])
result = ser.combine(3, lambda x, y: x + y)
Reported by Pylint.
Line: 6
Column: 5
class TestCombine:
def test_combine_scalar(self):
# GH#21248
# Note - combine() with another Series is tested elsewhere because
# it is used when testing operators
ser = Series([i * 10 for i in range(5)])
result = ser.combine(3, lambda x, y: x + y)
Reported by Pylint.
pandas/tests/io/parser/common/test_float.py
6 issues
Line: 8
Column: 1
from io import StringIO
import numpy as np
import pytest
from pandas.compat import is_platform_linux
from pandas import DataFrame
import pandas._testing as tm
Reported by Pylint.
Line: 16
Column: 1
import pandas._testing as tm
def test_float_parser(all_parsers):
# see gh-9565
parser = all_parsers
data = "45e-1,4.5,45.,inf,-inf"
result = parser.read_csv(StringIO(data), header=None)
Reported by Pylint.
Line: 26
Column: 1
tm.assert_frame_equal(result, expected)
def test_scientific_no_exponent(all_parsers_all_precisions):
# see gh-12215
df = DataFrame.from_dict({"w": ["2e"], "x": ["3E"], "y": ["42e"], "z": ["632E"]})
data = df.to_csv(index=False)
parser, precision = all_parsers_all_precisions
if parser == "pyarrow":
Reported by Pylint.
Line: 28
Column: 5
def test_scientific_no_exponent(all_parsers_all_precisions):
# see gh-12215
df = DataFrame.from_dict({"w": ["2e"], "x": ["3E"], "y": ["42e"], "z": ["632E"]})
data = df.to_csv(index=False)
parser, precision = all_parsers_all_precisions
if parser == "pyarrow":
pytest.skip()
Reported by Pylint.
Line: 39
Column: 1
@pytest.mark.parametrize("neg_exp", [-617, -100000, -99999999999999999])
def test_very_negative_exponent(all_parsers_all_precisions, neg_exp):
# GH#38753
parser, precision = all_parsers_all_precisions
if parser == "pyarrow":
pytest.skip()
data = f"data\n10E{neg_exp}"
Reported by Pylint.
Line: 51
Column: 1
@pytest.mark.parametrize("exp", [999999999999999999, -999999999999999999])
def test_too_many_exponent_digits(all_parsers_all_precisions, exp, request):
# GH#38753
parser, precision = all_parsers_all_precisions
data = f"data\n10E{exp}"
result = parser.read_csv(StringIO(data), float_precision=precision)
if precision == "round_trip":
Reported by Pylint.
pandas/tests/io/parser/test_multi_thread.py
6 issues
Line: 10
Column: 1
from multiprocessing.pool import ThreadPool
import numpy as np
import pytest
import pandas as pd
from pandas import DataFrame
import pandas._testing as tm
Reported by Pylint.
Line: 30
Column: 5
-------
df : DataFrame
"""
df = DataFrame(np.random.rand(num_rows, 5), columns=list("abcde"))
df["foo"] = "foo"
df["bar"] = "bar"
df["baz"] = "baz"
df["date"] = pd.date_range("20000101 09:00:00", periods=num_rows, freq="s")
df["int"] = np.arange(num_rows, dtype="int64")
Reported by Pylint.
Line: 40
Column: 1
@pytest.mark.slow
def test_multi_thread_string_io_read_csv(all_parsers):
# see gh-11786
parser = all_parsers
max_row_range = 10000
num_files = 100
Reported by Pylint.
Line: 127
Column: 9
header = results[0].columns
for r in results[1:]:
r.columns = header
final_dataframe = pd.concat(results)
return final_dataframe
Reported by Pylint.
Line: 135
Column: 1
@pytest.mark.slow
def test_multi_thread_path_multipart_read_csv(all_parsers):
# see gh-11786
num_tasks = 4
num_rows = 100000
parser = all_parsers
Reported by Pylint.
Line: 142
Column: 5
parser = all_parsers
file_name = "__thread_pool_reader__.csv"
df = _construct_dataframe(num_rows)
with tm.ensure_clean(file_name) as path:
df.to_csv(path)
final_dataframe = _generate_multi_thread_dataframe(
Reported by Pylint.
scripts/no_bool_in_generic.py
6 issues
Line: 49
Column: 1
return to_replace
def replace_bool_with_bool_t(to_replace, content: str) -> str:
new_lines = []
for n, line in enumerate(content.splitlines(), start=1):
if n in to_replace:
for col_offset in reversed(to_replace[n]):
Reported by Pylint.
Line: 52
Column: 9
def replace_bool_with_bool_t(to_replace, content: str) -> str:
new_lines = []
for n, line in enumerate(content.splitlines(), start=1):
if n in to_replace:
for col_offset in reversed(to_replace[n]):
line = line[:col_offset] + "bool_t" + line[col_offset + 4 :]
new_lines.append(line)
return "\n".join(new_lines)
Reported by Pylint.
Line: 60
Column: 1
return "\n".join(new_lines)
def check_for_bool_in_generic(content: str) -> tuple[bool, str]:
tree = ast.parse(content)
to_replace = visit(tree)
if not to_replace:
mutated = False
Reported by Pylint.
Line: 72
Column: 1
return mutated, replace_bool_with_bool_t(to_replace, content)
def main(argv: Sequence[str] | None = None) -> None:
parser = argparse.ArgumentParser()
parser.add_argument("paths", nargs="*")
args = parser.parse_args(argv)
for path in args.paths:
Reported by Pylint.
Line: 78
Column: 46
args = parser.parse_args(argv)
for path in args.paths:
with open(path, encoding="utf-8") as fd:
content = fd.read()
mutated, new_content = check_for_bool_in_generic(content)
if mutated:
with open(path, "w", encoding="utf-8") as fd:
fd.write(new_content)
Reported by Pylint.
Line: 82
Column: 55
content = fd.read()
mutated, new_content = check_for_bool_in_generic(content)
if mutated:
with open(path, "w", encoding="utf-8") as fd:
fd.write(new_content)
if __name__ == "__main__":
main()
Reported by Pylint.
pandas/tests/dtypes/cast/test_construct_object_arr.py
6 issues
Line: 1
Column: 1
import pytest
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
@pytest.mark.parametrize("datum1", [1, 2.0, "3", (4, 5), [6, 7], None])
@pytest.mark.parametrize("datum2", [8, 9.0, "10", (11, 12), [13, 14], None])
def test_cast_1d_array(datum1, datum2):
data = [datum1, datum2]
Reported by Pylint.
Line: 1
Column: 1
import pytest
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
@pytest.mark.parametrize("datum1", [1, 2.0, "3", (4, 5), [6, 7], None])
@pytest.mark.parametrize("datum2", [8, 9.0, "10", (11, 12), [13, 14], None])
def test_cast_1d_array(datum1, datum2):
data = [datum1, datum2]
Reported by Pylint.
Line: 8
Column: 1
@pytest.mark.parametrize("datum1", [1, 2.0, "3", (4, 5), [6, 7], None])
@pytest.mark.parametrize("datum2", [8, 9.0, "10", (11, 12), [13, 14], None])
def test_cast_1d_array(datum1, datum2):
data = [datum1, datum2]
result = construct_1d_object_array_from_listlike(data)
# Direct comparison fails: https://github.com/numpy/numpy/issues/10218
assert result.dtype == "object"
Reported by Pylint.
Line: 13
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
result = construct_1d_object_array_from_listlike(data)
# Direct comparison fails: https://github.com/numpy/numpy/issues/10218
assert result.dtype == "object"
assert list(result) == data
@pytest.mark.parametrize("val", [1, 2.0, None])
def test_cast_1d_array_invalid_scalar(val):
Reported by Bandit.
Line: 14
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# Direct comparison fails: https://github.com/numpy/numpy/issues/10218
assert result.dtype == "object"
assert list(result) == data
@pytest.mark.parametrize("val", [1, 2.0, None])
def test_cast_1d_array_invalid_scalar(val):
with pytest.raises(TypeError, match="has no len()"):
Reported by Bandit.
Line: 18
Column: 1
@pytest.mark.parametrize("val", [1, 2.0, None])
def test_cast_1d_array_invalid_scalar(val):
with pytest.raises(TypeError, match="has no len()"):
construct_1d_object_array_from_listlike(val)
Reported by Pylint.
pandas/plotting/_matplotlib/style.py
6 issues
Line: 1
Column: 1
from __future__ import annotations
import itertools
from typing import (
TYPE_CHECKING,
Collection,
Iterator,
Sequence,
Union,
Reported by Pylint.
Line: 119
Column: 5
If both `colormap` and `color` are provided.
Parameter `color` will override.
"""
if color is None and colormap is not None:
return _get_colors_from_colormap(colormap, num_colors=num_colors)
elif color is not None:
if colormap is not None:
warnings.warn(
"'color' and 'colormap' cannot be used simultaneously. Using 'color'"
Reported by Pylint.
Line: 201
Column: 9
"""
Yield colors from string of several letters or from collection of colors.
"""
for x in color:
if _is_single_color(x):
yield x
else:
raise ValueError(f"Invalid color {x}")
Reported by Pylint.
Line: 219
Column: 5
def _get_colors_from_color_type(color_type: str, num_colors: int) -> list[Color]:
"""Get colors from user input color type."""
if color_type == "default":
return _get_default_colors(num_colors)
elif color_type == "random":
return _get_random_colors(num_colors)
else:
raise ValueError("color_type must be either 'default' or 'random'")
Reported by Pylint.
Line: 229
Column: 5
def _get_default_colors(num_colors: int) -> list[Color]:
"""Get `num_colors` of default colors from matplotlib rc params."""
import matplotlib.pyplot as plt
colors = [c["color"] for c in plt.rcParams["axes.prop_cycle"]]
return colors[0:num_colors]
Reported by Pylint.
Line: 243
Column: 5
def _random_color(column: int) -> list[float]:
"""Get a random color represented as a list of length 3"""
# GH17525 use common._random_state to avoid resetting the seed
rs = com.random_state(column)
return rs.rand(3).tolist()
def _is_single_string_color(color: Color) -> bool:
"""Check if `color` is a single string color.
Reported by Pylint.