The following issues were found
pandas/tests/arrays/integer/test_concat.py
6 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
import pandas._testing as tm
@pytest.mark.parametrize(
"to_concat_dtypes, result_dtype",
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(
"to_concat_dtypes, result_dtype",
Reported by Pylint.
Line: 20
Column: 1
(["Int64", "UInt64"], "Float64"),
(["Int64", "boolean"], "Int64"),
(["UInt8", "boolean"], "UInt8"),
],
)
def test_concat_series(to_concat_dtypes, result_dtype):
result = pd.concat([pd.Series([0, 1, pd.NA], dtype=t) for t in to_concat_dtypes])
expected = pd.concat([pd.Series([0, 1, pd.NA], dtype=object)] * 2).astype(
Reported by Pylint.
Line: 52
Column: 1
(["Int64", "uint64"], "Float64"),
(["Int64", "bool"], "Int64"),
(["UInt8", "bool"], "UInt8"),
],
)
def test_concat_series_with_numpy(to_concat_dtypes, result_dtype):
s1 = pd.Series([0, 1, pd.NA], dtype=to_concat_dtypes[0])
s2 = pd.Series(np.array([0, 1], dtype=to_concat_dtypes[1]))
Reported by Pylint.
Line: 56
Column: 5
)
def test_concat_series_with_numpy(to_concat_dtypes, result_dtype):
s1 = pd.Series([0, 1, pd.NA], dtype=to_concat_dtypes[0])
s2 = pd.Series(np.array([0, 1], dtype=to_concat_dtypes[1]))
result = pd.concat([s1, s2], ignore_index=True)
expected = pd.Series([0, 1, pd.NA, 0, 1], dtype=object).astype(result_dtype)
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 57
Column: 5
def test_concat_series_with_numpy(to_concat_dtypes, result_dtype):
s1 = pd.Series([0, 1, pd.NA], dtype=to_concat_dtypes[0])
s2 = pd.Series(np.array([0, 1], dtype=to_concat_dtypes[1]))
result = pd.concat([s1, s2], ignore_index=True)
expected = pd.Series([0, 1, pd.NA, 0, 1], dtype=object).astype(result_dtype)
tm.assert_series_equal(result, expected)
# order doesn't matter for result
Reported by Pylint.
pandas/_typing.py
6 issues
Line: 119
Column: 5
ArrayLike,
np.random.Generator,
np.random.BitGenerator,
np.random.RandomState,
]
# dtypes
NpDtype = Union[str, np.dtype]
Dtype = Union[
Reported by Pylint.
Line: 13
Column: 1
TextIOWrapper,
)
from mmap import mmap
from os import PathLike
from typing import (
IO,
TYPE_CHECKING,
Any,
AnyStr,
Reported by Pylint.
Line: 204
Column: 3
# indexing
# PositionalIndexer -> valid 1D positional indexer, e.g. can pass
# to ndarray.__getitem__
# TODO: add Ellipsis, see
# https://github.com/python/typing/issues/684#issuecomment-548203158
# https://bugs.python.org/issue41810
PositionalIndexer = Union[int, np.integer, slice, Sequence[int], np.ndarray]
PositionalIndexer2D = Union[
PositionalIndexer, Tuple[PositionalIndexer, PositionalIndexer]
Reported by Pylint.
Line: 1
Column: 1
from datetime import (
datetime,
timedelta,
tzinfo,
)
from io import (
BufferedIOBase,
RawIOBase,
TextIOBase,
Reported by Pylint.
Line: 135
Column: 1
Renamer = Union[Mapping[Hashable, Any], Callable[[Hashable], Hashable]]
# to maintain type information across generic functions and parametrization
T = TypeVar("T")
# used in decorators to preserve the signature of the function it decorates
# see https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators
FuncType = Callable[..., Any]
F = TypeVar("F", bound=FuncType)
Reported by Pylint.
Line: 140
Column: 1
# used in decorators to preserve the signature of the function it decorates
# see https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators
FuncType = Callable[..., Any]
F = TypeVar("F", bound=FuncType)
# types of vectorized key functions for DataFrame::sort_values and
# DataFrame::sort_index, among others
ValueKeyFunc = Optional[Callable[["Series"], Union["Series", AnyArrayLike]]]
IndexKeyFunc = Optional[Callable[["Index"], Union["Index", AnyArrayLike]]]
Reported by Pylint.
pandas/_testing/_warnings.py
6 issues
Line: 77
Column: 5
..warn:: This is *not* thread-safe.
"""
__tracebackhide__ = True
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter(filter_level)
yield w
Reported by Pylint.
Line: 154
Column: 3
if actual_warning.category == ResourceWarning and unclosed in str(
actual_warning.message
):
# FIXME: kludge because pytest.filterwarnings does not
# suppress these, xref GH#38630
continue
extra_warnings.append(
(
Reported by Pylint.
Line: 1
Column: 1
from __future__ import annotations
from contextlib import contextmanager
import re
from typing import (
Sequence,
Type,
cast,
)
Reported by Pylint.
Line: 79
Column: 50
"""
__tracebackhide__ = True
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter(filter_level)
yield w
if expected_warning:
expected_warning = cast(Type[Warning], expected_warning)
Reported by Pylint.
Line: 185
Column: 5
def _assert_raised_with_correct_stacklevel(
actual_warning: warnings.WarningMessage,
) -> None:
from inspect import (
getframeinfo,
stack,
)
caller = getframeinfo(stack()[4][0])
Reported by Pylint.
Line: 196
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
f"File where warning is raised: {actual_warning.filename} != "
f"{caller.filename}. Warning message: {actual_warning.message}"
)
assert actual_warning.filename == caller.filename, msg
Reported by Bandit.
pandas/tests/dtypes/cast/test_infer_datetimelike.py
6 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import (
DataFrame,
NaT,
Series,
Timestamp,
)
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import (
DataFrame,
NaT,
Series,
Timestamp,
)
Reported by Pylint.
Line: 18
Column: 1
# see gh-16362.
([[NaT, "a", "b", 0], [NaT, "b", "c", 1]], 8),
([[NaT, "a", 0], [NaT, "b", 1]], 6),
],
)
def test_maybe_infer_to_datetimelike_df_construct(data, exp_size):
result = DataFrame(np.array(data))
assert result.size == exp_size
Reported by Pylint.
Line: 22
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
)
def test_maybe_infer_to_datetimelike_df_construct(data, exp_size):
result = DataFrame(np.array(data))
assert result.size == exp_size
def test_maybe_infer_to_datetimelike_ser_construct():
# see gh-19671.
result = Series(["M1701", Timestamp("20130101")])
Reported by Bandit.
Line: 25
Column: 1
assert result.size == exp_size
def test_maybe_infer_to_datetimelike_ser_construct():
# see gh-19671.
result = Series(["M1701", Timestamp("20130101")])
assert result.dtype.kind == "O"
Reported by Pylint.
Line: 28
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_maybe_infer_to_datetimelike_ser_construct():
# see gh-19671.
result = Series(["M1701", Timestamp("20130101")])
assert result.dtype.kind == "O"
Reported by Bandit.
pandas/tests/extension/base/base.py
6 issues
Line: 1
Column: 1
import pandas._testing as tm
class BaseExtensionTests:
# classmethod and different signature is needed
# to make inheritance compliant with mypy
@classmethod
def assert_equal(cls, left, right, **kwargs):
return tm.assert_equal(left, right, **kwargs)
Reported by Pylint.
Line: 4
Column: 1
import pandas._testing as tm
class BaseExtensionTests:
# classmethod and different signature is needed
# to make inheritance compliant with mypy
@classmethod
def assert_equal(cls, left, right, **kwargs):
return tm.assert_equal(left, right, **kwargs)
Reported by Pylint.
Line: 8
Column: 5
# classmethod and different signature is needed
# to make inheritance compliant with mypy
@classmethod
def assert_equal(cls, left, right, **kwargs):
return tm.assert_equal(left, right, **kwargs)
@classmethod
def assert_series_equal(cls, left, right, *args, **kwargs):
return tm.assert_series_equal(left, right, *args, **kwargs)
Reported by Pylint.
Line: 12
Column: 5
return tm.assert_equal(left, right, **kwargs)
@classmethod
def assert_series_equal(cls, left, right, *args, **kwargs):
return tm.assert_series_equal(left, right, *args, **kwargs)
@classmethod
def assert_frame_equal(cls, left, right, *args, **kwargs):
return tm.assert_frame_equal(left, right, *args, **kwargs)
Reported by Pylint.
Line: 16
Column: 5
return tm.assert_series_equal(left, right, *args, **kwargs)
@classmethod
def assert_frame_equal(cls, left, right, *args, **kwargs):
return tm.assert_frame_equal(left, right, *args, **kwargs)
@classmethod
def assert_extension_array_equal(cls, left, right, *args, **kwargs):
return tm.assert_extension_array_equal(left, right, *args, **kwargs)
Reported by Pylint.
Line: 20
Column: 5
return tm.assert_frame_equal(left, right, *args, **kwargs)
@classmethod
def assert_extension_array_equal(cls, left, right, *args, **kwargs):
return tm.assert_extension_array_equal(left, right, *args, **kwargs)
Reported by Pylint.
pandas/tests/frame/methods/test_sample.py
6 issues
Line: 171
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
obj = DataFrame({"col1": range(10, 20), "col2": range(20, 30)})
if frame_or_series is Series:
obj = obj["col1"]
result = obj.sample(n=3, random_state=eval(func_str)(arg))
expected = obj.sample(n=3, random_state=com.random_state(eval(func_str)(arg)))
tm.assert_equal(result, expected)
def test_sample_generator(self, frame_or_series):
# GH#38100
Reported by Bandit.
Line: 172
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b307-eval
if frame_or_series is Series:
obj = obj["col1"]
result = obj.sample(n=3, random_state=eval(func_str)(arg))
expected = obj.sample(n=3, random_state=com.random_state(eval(func_str)(arg)))
tm.assert_equal(result, expected)
def test_sample_generator(self, frame_or_series):
# GH#38100
obj = frame_or_series(np.arange(100))
Reported by Bandit.
Line: 65
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_sample_lengths(self, obj):
# Check lengths are right
assert len(obj.sample(n=4) == 4)
assert len(obj.sample(frac=0.34) == 3)
assert len(obj.sample(frac=0.36) == 4)
def test_sample_invalid_random_state(self, obj):
# Check for error when random_state argument invalid.
Reported by Bandit.
Line: 66
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_sample_lengths(self, obj):
# Check lengths are right
assert len(obj.sample(n=4) == 4)
assert len(obj.sample(frac=0.34) == 3)
assert len(obj.sample(frac=0.36) == 4)
def test_sample_invalid_random_state(self, obj):
# Check for error when random_state argument invalid.
msg = (
Reported by Bandit.
Line: 67
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# Check lengths are right
assert len(obj.sample(n=4) == 4)
assert len(obj.sample(frac=0.34) == 3)
assert len(obj.sample(frac=0.36) == 4)
def test_sample_invalid_random_state(self, obj):
# Check for error when random_state argument invalid.
msg = (
"random_state must be an integer, array-like, a BitGenerator, Generator, "
Reported by Bandit.
Line: 183
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# Consecutive calls should advance the seed
result1 = obj.sample(n=50, random_state=rng)
result2 = obj.sample(n=50, random_state=rng)
assert not (result1.index.values == result2.index.values).all()
# Matching generator initialization must give same result
# Consecutive calls should advance the seed
result1 = obj.sample(n=50, random_state=np.random.default_rng(11))
result2 = obj.sample(n=50, random_state=np.random.default_rng(11))
Reported by Bandit.
pandas/tests/indexes/datetimes/methods/test_to_frame.py
5 issues
Line: 1
Column: 1
from pandas import (
DataFrame,
date_range,
)
import pandas._testing as tm
class TestToFrame:
def test_to_frame_datetime_tz(self):
Reported by Pylint.
Line: 8
Column: 1
import pandas._testing as tm
class TestToFrame:
def test_to_frame_datetime_tz(self):
# GH#25809
idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
result = idx.to_frame()
expected = DataFrame(idx, index=idx)
Reported by Pylint.
Line: 8
Column: 1
import pandas._testing as tm
class TestToFrame:
def test_to_frame_datetime_tz(self):
# GH#25809
idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
result = idx.to_frame()
expected = DataFrame(idx, index=idx)
Reported by Pylint.
Line: 9
Column: 5
class TestToFrame:
def test_to_frame_datetime_tz(self):
# GH#25809
idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
result = idx.to_frame()
expected = DataFrame(idx, index=idx)
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 9
Column: 5
class TestToFrame:
def test_to_frame_datetime_tz(self):
# GH#25809
idx = date_range(start="2019-01-01", end="2019-01-30", freq="D", tz="UTC")
result = idx.to_frame()
expected = DataFrame(idx, index=idx)
tm.assert_frame_equal(result, expected)
Reported by Pylint.
pandas/compat/_optional.py
5 issues
Line: 1
Column: 1
from __future__ import annotations
import importlib
import sys
import types
import warnings
from pandas.util.version import Version
Reported by Pylint.
Line: 53
Column: 1
}
def get_version(module: types.ModuleType) -> str:
version = getattr(module, "__version__", None)
if version is None:
# xlrd uses a capitalized attribute name
version = getattr(module, "__VERSION__", None)
Reported by Pylint.
Line: 105
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
is ``'warn'``.
"""
assert errors in {"warn", "raise", "ignore"}
package_name = INSTALL_MAPPING.get(name)
install_name = package_name if package_name is not None else name
msg = (
Reported by Bandit.
Line: 117
Column: 9
try:
module = importlib.import_module(name)
except ImportError:
if errors == "raise":
raise ImportError(msg) from None
else:
return None
# Handle submodules: if we have submodule, grab parent module from sys.modules
Reported by Pylint.
Line: 137
Column: 13
f"Pandas requires version '{minimum_version}' or newer of '{parent}' "
f"(version '{version}' currently installed)."
)
if errors == "warn":
warnings.warn(msg, UserWarning)
return None
elif errors == "raise":
raise ImportError(msg)
Reported by Pylint.
pandas/tests/frame/methods/test_is_homogeneous_dtype.py
5 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas import (
Categorical,
DataFrame,
)
Reported by Pylint.
Line: 57
Column: 12
],
)
def test_is_homogeneous_type(data, expected):
assert data._is_homogeneous_type is expected
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas.util._test_decorators as td
from pandas import (
Categorical,
DataFrame,
)
Reported by Pylint.
Line: 53
Column: 1
(
DataFrame({"A": Categorical(["a", "b"]), "B": Categorical(["b", "c"])}),
False,
),
],
)
def test_is_homogeneous_type(data, expected):
assert data._is_homogeneous_type is expected
Reported by Pylint.
Line: 57
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
],
)
def test_is_homogeneous_type(data, expected):
assert data._is_homogeneous_type is expected
Reported by Bandit.
pandas/tests/dtypes/cast/test_dict_compat.py
5 issues
Line: 1
Column: 1
import numpy as np
from pandas.core.dtypes.cast import dict_compat
from pandas import Timestamp
def test_dict_compat():
data_datetime64 = {np.datetime64("1990-03-15"): 1, np.datetime64("2015-03-15"): 2}
Reported by Pylint.
Line: 8
Column: 1
from pandas import Timestamp
def test_dict_compat():
data_datetime64 = {np.datetime64("1990-03-15"): 1, np.datetime64("2015-03-15"): 2}
data_unchanged = {1: 2, 3: 4, 5: 6}
expected = {Timestamp("1990-3-15"): 1, Timestamp("2015-03-15"): 2}
assert dict_compat(data_datetime64) == expected
assert dict_compat(expected) == expected
Reported by Pylint.
Line: 12
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
data_datetime64 = {np.datetime64("1990-03-15"): 1, np.datetime64("2015-03-15"): 2}
data_unchanged = {1: 2, 3: 4, 5: 6}
expected = {Timestamp("1990-3-15"): 1, Timestamp("2015-03-15"): 2}
assert dict_compat(data_datetime64) == expected
assert dict_compat(expected) == expected
assert dict_compat(data_unchanged) == data_unchanged
Reported by Bandit.
Line: 13
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
data_unchanged = {1: 2, 3: 4, 5: 6}
expected = {Timestamp("1990-3-15"): 1, Timestamp("2015-03-15"): 2}
assert dict_compat(data_datetime64) == expected
assert dict_compat(expected) == expected
assert dict_compat(data_unchanged) == data_unchanged
Reported by Bandit.
Line: 14
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
expected = {Timestamp("1990-3-15"): 1, Timestamp("2015-03-15"): 2}
assert dict_compat(data_datetime64) == expected
assert dict_compat(expected) == expected
assert dict_compat(data_unchanged) == data_unchanged
Reported by Bandit.