The following issues were found
pandas/tests/indexes/datetimes/test_pickle.py
20 issues
Line: 1
Column: 1
import pytest
from pandas import (
NaT,
date_range,
to_datetime,
)
import pandas._testing as tm
Reported by Pylint.
Line: 29
Column: 15
def test_pickle_after_set_freq(self):
dti = date_range("20130101", periods=3, tz="US/Eastern", name="foo")
dti = dti._with_freq(None)
res = tm.round_trip_pickle(dti)
tm.assert_index_equal(res, dti)
def test_roundtrip_pickle_with_tz(self):
Reported by Pylint.
Line: 29
Column: 15
def test_pickle_after_set_freq(self):
dti = date_range("20130101", periods=3, tz="US/Eastern", name="foo")
dti = dti._with_freq(None)
res = tm.round_trip_pickle(dti)
tm.assert_index_equal(res, dti)
def test_roundtrip_pickle_with_tz(self):
Reported by Pylint.
Line: 29
Column: 15
def test_pickle_after_set_freq(self):
dti = date_range("20130101", periods=3, tz="US/Eastern", name="foo")
dti = dti._with_freq(None)
res = tm.round_trip_pickle(dti)
tm.assert_index_equal(res, dti)
def test_roundtrip_pickle_with_tz(self):
Reported by Pylint.
Line: 1
Column: 1
import pytest
from pandas import (
NaT,
date_range,
to_datetime,
)
import pandas._testing as tm
Reported by Pylint.
Line: 11
Column: 1
import pandas._testing as tm
class TestPickle:
def test_pickle(self):
# GH#4606
idx = to_datetime(["2013-01-01", NaT, "2014-01-06"])
idx_p = tm.round_trip_pickle(idx)
assert idx_p[0] == idx[0]
Reported by Pylint.
Line: 12
Column: 5
class TestPickle:
def test_pickle(self):
# GH#4606
idx = to_datetime(["2013-01-01", NaT, "2014-01-06"])
idx_p = tm.round_trip_pickle(idx)
assert idx_p[0] == idx[0]
assert idx_p[1] is NaT
Reported by Pylint.
Line: 12
Column: 5
class TestPickle:
def test_pickle(self):
# GH#4606
idx = to_datetime(["2013-01-01", NaT, "2014-01-06"])
idx_p = tm.round_trip_pickle(idx)
assert idx_p[0] == idx[0]
assert idx_p[1] is NaT
Reported by Pylint.
Line: 16
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# GH#4606
idx = to_datetime(["2013-01-01", NaT, "2014-01-06"])
idx_p = tm.round_trip_pickle(idx)
assert idx_p[0] == idx[0]
assert idx_p[1] is NaT
assert idx_p[2] == idx[2]
def test_pickle_dont_infer_freq(self):
# GH##11002
Reported by Bandit.
Line: 17
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
idx = to_datetime(["2013-01-01", NaT, "2014-01-06"])
idx_p = tm.round_trip_pickle(idx)
assert idx_p[0] == idx[0]
assert idx_p[1] is NaT
assert idx_p[2] == idx[2]
def test_pickle_dont_infer_freq(self):
# GH##11002
# don't infer freq
Reported by Bandit.
pandas/tests/arrays/boolean/test_reduction.py
20 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
@pytest.fixture
def data():
return pd.array(
Reported by Pylint.
Line: 46
Column: 42
@pytest.mark.parametrize("dropna", [True, False])
def test_reductions_return_types(dropna, data, all_numeric_reductions):
op = all_numeric_reductions
s = pd.Series(data)
if dropna:
s = s.dropna()
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
@pytest.fixture
def data():
return pd.array(
Reported by Pylint.
Line: 8
Column: 1
@pytest.fixture
def data():
return pd.array(
[True, False] * 4 + [np.nan] + [True, False] * 44 + [np.nan] + [True, False],
dtype="boolean",
)
Reported by Pylint.
Line: 25
Column: 1
# GH-33253: all True / all False values buggy with skipna=False
([True, True], True, True, True, True),
([False, False], False, False, False, False),
],
)
def test_any_all(values, exp_any, exp_all, exp_any_noskip, exp_all_noskip):
# the methods return numpy scalars
exp_any = pd.NA if exp_any is pd.NA else np.bool_(exp_any)
exp_all = pd.NA if exp_all is pd.NA else np.bool_(exp_all)
Reported by Pylint.
Line: 35
Column: 9
exp_all_noskip = pd.NA if exp_all_noskip is pd.NA else np.bool_(exp_all_noskip)
for con in [pd.array, pd.Series]:
a = con(values, dtype="boolean")
assert a.any() is exp_any
assert a.all() is exp_all
assert a.any(skipna=False) is exp_any_noskip
assert a.all(skipna=False) is exp_all_noskip
Reported by Pylint.
Line: 36
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
for con in [pd.array, pd.Series]:
a = con(values, dtype="boolean")
assert a.any() is exp_any
assert a.all() is exp_all
assert a.any(skipna=False) is exp_any_noskip
assert a.all(skipna=False) is exp_all_noskip
assert np.any(a.any()) is exp_any
Reported by Bandit.
Line: 37
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
for con in [pd.array, pd.Series]:
a = con(values, dtype="boolean")
assert a.any() is exp_any
assert a.all() is exp_all
assert a.any(skipna=False) is exp_any_noskip
assert a.all(skipna=False) is exp_all_noskip
assert np.any(a.any()) is exp_any
assert np.all(a.all()) is exp_all
Reported by Bandit.
Line: 38
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
a = con(values, dtype="boolean")
assert a.any() is exp_any
assert a.all() is exp_all
assert a.any(skipna=False) is exp_any_noskip
assert a.all(skipna=False) is exp_all_noskip
assert np.any(a.any()) is exp_any
assert np.all(a.all()) is exp_all
Reported by Bandit.
Line: 39
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
assert a.any() is exp_any
assert a.all() is exp_all
assert a.any(skipna=False) is exp_any_noskip
assert a.all(skipna=False) is exp_all_noskip
assert np.any(a.any()) is exp_any
assert np.all(a.all()) is exp_all
Reported by Bandit.
pandas/tests/groupby/test_missing.py
19 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
DataFrame,
Index,
date_range,
)
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
DataFrame,
Index,
date_range,
)
Reported by Pylint.
Line: 14
Column: 1
@pytest.mark.parametrize("func", ["ffill", "bfill"])
def test_groupby_column_index_name_lost_fill_funcs(func):
# GH: 29764 groupby loses index sometimes
df = DataFrame(
[[1, 1.0, -1.0], [1, np.nan, np.nan], [1, 2.0, -2.0]],
columns=Index(["type", "a", "b"], name="idx"),
)
Reported by Pylint.
Line: 16
Column: 5
@pytest.mark.parametrize("func", ["ffill", "bfill"])
def test_groupby_column_index_name_lost_fill_funcs(func):
# GH: 29764 groupby loses index sometimes
df = DataFrame(
[[1, 1.0, -1.0], [1, np.nan, np.nan], [1, 2.0, -2.0]],
columns=Index(["type", "a", "b"], name="idx"),
)
df_grouped = df.groupby(["type"])[["a", "b"]]
result = getattr(df_grouped, func)().columns
Reported by Pylint.
Line: 27
Column: 1
@pytest.mark.parametrize("func", ["ffill", "bfill"])
def test_groupby_fill_duplicate_column_names(func):
# GH: 25610 ValueError with duplicate column names
df1 = DataFrame({"field1": [1, 3, 4], "field2": [1, 3, 4]})
df2 = DataFrame({"field1": [1, np.nan, 4]})
df_grouped = pd.concat([df1, df2], axis=1).groupby(by=["field2"])
expected = DataFrame(
Reported by Pylint.
Line: 39
Column: 1
tm.assert_frame_equal(result, expected)
def test_ffill_missing_arguments():
# GH 14955
df = DataFrame({"a": [1, 2], "b": [1, 1]})
with pytest.raises(ValueError, match="Must specify a fill"):
df.groupby("b").fillna()
Reported by Pylint.
Line: 41
Column: 5
def test_ffill_missing_arguments():
# GH 14955
df = DataFrame({"a": [1, 2], "b": [1, 1]})
with pytest.raises(ValueError, match="Must specify a fill"):
df.groupby("b").fillna()
@pytest.mark.parametrize(
Reported by Pylint.
Line: 48
Column: 1
@pytest.mark.parametrize(
"method, expected", [("ffill", [None, "a", "a"]), ("bfill", ["a", "a", None])]
)
def test_fillna_with_string_dtype(method, expected):
# GH 40250
df = DataFrame({"a": pd.array([None, "a", None], dtype="string"), "b": [0, 0, 0]})
grp = df.groupby("b")
result = grp.fillna(method=method)
Reported by Pylint.
Line: 51
Column: 5
)
def test_fillna_with_string_dtype(method, expected):
# GH 40250
df = DataFrame({"a": pd.array([None, "a", None], dtype="string"), "b": [0, 0, 0]})
grp = df.groupby("b")
result = grp.fillna(method=method)
expected = DataFrame({"a": pd.array(expected, dtype="string")})
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 58
Column: 1
tm.assert_frame_equal(result, expected)
def test_fill_consistency():
# GH9221
# pass thru keyword arguments to the generated wrapper
# are set if the passed kw is None (only)
df = DataFrame(
Reported by Pylint.
pandas/tests/groupby/test_bin_groupby.py
19 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas._libs import (
lib,
reduction as libreduction,
)
import pandas.util._test_decorators as td
Reported by Pylint.
Line: 4
Column: 1
import numpy as np
import pytest
from pandas._libs import (
lib,
reduction as libreduction,
)
import pandas.util._test_decorators as td
Reported by Pylint.
Line: 4
Column: 1
import numpy as np
import pytest
from pandas._libs import (
lib,
reduction as libreduction,
)
import pandas.util._test_decorators as td
Reported by Pylint.
Line: 72
Column: 26
def assert_block_lengths(x):
assert len(x) == len(x._mgr.blocks[0].mgr_locs)
return 0
def cumsum_max(x):
x.cumsum().max()
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas._libs import (
lib,
reduction as libreduction,
)
import pandas.util._test_decorators as td
Reported by Pylint.
Line: 15
Column: 1
import pandas._testing as tm
def test_series_grouper():
obj = Series(np.random.randn(10))
labels = np.array([-1, -1, -1, 0, 0, 0, 1, 1, 1, 1], dtype=np.intp)
grouper = libreduction.SeriesGrouper(obj, np.mean, labels, 2)
Reported by Pylint.
Line: 30
Column: 1
tm.assert_almost_equal(counts, exp_counts)
def test_series_grouper_result_length_difference():
# GH 40014
obj = Series(np.random.randn(10), dtype="float64")
obj.index = obj.index.astype("O")
labels = np.array([-1, -1, -1, 0, 0, 0, 1, 1, 1, 1], dtype=np.intp)
Reported by Pylint.
Line: 46
Column: 1
tm.assert_equal(counts, exp_counts)
def test_series_grouper_requires_nonempty_raises():
# GH#29500
obj = Series(np.random.randn(10))
dummy = obj.iloc[:0]
labels = np.array([-1, -1, -1, 0, 0, 0, 1, 1, 1, 1], dtype=np.intp)
Reported by Pylint.
Line: 56
Column: 1
libreduction.SeriesGrouper(dummy, np.mean, labels, 2)
def test_series_bin_grouper():
obj = Series(np.random.randn(10))
bins = np.array([3, 6], dtype=np.int64)
grouper = libreduction.SeriesBinGrouper(obj, np.mean, bins)
Reported by Pylint.
Line: 71
Column: 1
tm.assert_almost_equal(counts, exp_counts)
def assert_block_lengths(x):
assert len(x) == len(x._mgr.blocks[0].mgr_locs)
return 0
def cumsum_max(x):
Reported by Pylint.
doc/make.py
19 issues
Line: 23
Column: 1
import sys
import webbrowser
import docutils
import docutils.parsers.rst
DOC_PATH = os.path.dirname(os.path.abspath(__file__))
SOURCE_PATH = os.path.join(DOC_PATH, "source")
BUILD_PATH = os.path.join(DOC_PATH, "build")
Reported by Pylint.
Line: 24
Column: 1
import webbrowser
import docutils
import docutils.parsers.rst
DOC_PATH = os.path.dirname(os.path.abspath(__file__))
SOURCE_PATH = os.path.join(DOC_PATH, "source")
BUILD_PATH = os.path.join(DOC_PATH, "build")
REDIRECTS_FILE = os.path.join(DOC_PATH, "redirects.csv")
Reported by Pylint.
Line: 87
Column: 23
elif single_doc.startswith("pandas."):
try:
obj = pandas # noqa: F821
for name in single_doc.split("."):
obj = getattr(obj, name)
except AttributeError as err:
raise ImportError(f"Could not import {single_doc}") from err
else:
Reported by Pylint.
Line: 78
Column: 9
return the corresponding file path
(e.g. reference/api/pandas.DataFrame.head.rst).
"""
base_name, extension = os.path.splitext(single_doc)
if extension in (".rst", ".ipynb"):
if os.path.exists(os.path.join(SOURCE_PATH, single_doc)):
return single_doc
else:
raise FileNotFoundError(f"File {single_doc} not found")
Reported by Pylint.
Line: 206
Column: 24
try:
title = self._get_page_title(row[1])
except Exception:
# the file can be an ipynb and not an rst, or docutils
# may not be able to read the rst because it has some
# sphinx specific stuff
title = "this page"
Reported by Pylint.
Line: 256
Column: 21
ret_code = self._sphinx_build("latex")
os.chdir(os.path.join(BUILD_PATH, "latex"))
if force:
for i in range(3):
self._run_os("pdflatex", "-interaction=nonstopmode", "pandas.tex")
raise SystemExit(
"You should check the file "
'"build/latex/pandas.pdf" for problems.'
)
Reported by Pylint.
Line: 19
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess
import importlib
import os
import shutil
import subprocess
import sys
import webbrowser
import docutils
import docutils.parsers.rst
Reported by Bandit.
Line: 40
Column: 5
script.
"""
def __init__(
self,
num_jobs="auto",
include_api=True,
whatsnew=False,
single_doc=None,
Reported by Pylint.
Line: 69
Column: 5
elif single_doc:
self.single_doc_html = f"reference/api/pandas.{single_doc}.html"
def _process_single_doc(self, single_doc):
"""
Make sure the provided value for --single is a path to an existing
.rst/.ipynb file, or a pandas object that can be imported.
For example, categorial.rst or pandas.DataFrame.head. For the latter,
Reported by Pylint.
Line: 80
Column: 13
"""
base_name, extension = os.path.splitext(single_doc)
if extension in (".rst", ".ipynb"):
if os.path.exists(os.path.join(SOURCE_PATH, single_doc)):
return single_doc
else:
raise FileNotFoundError(f"File {single_doc} not found")
elif single_doc.startswith("pandas."):
Reported by Pylint.
pandas/core/internals/base.py
19 issues
Line: 160
Column: 16
"""
Quick access to the backing array of the Block or SingleArrayManager.
"""
return self.arrays[0] # type: ignore[attr-defined]
def setitem_inplace(self, indexer, value) -> None:
"""
Set values with indexer.
Reported by Pylint.
Line: 28
Column: 3
class DataManager(PandasObject):
# TODO share more methods/attributes
axes: list[Index]
@property
def items(self) -> Index:
Reported by Pylint.
Line: 23
Column: 1
from pandas.core.base import PandasObject
from pandas.core.indexes.api import Index
T = TypeVar("T", bound="DataManager")
class DataManager(PandasObject):
# TODO share more methods/attributes
Reported by Pylint.
Line: 26
Column: 1
T = TypeVar("T", bound="DataManager")
class DataManager(PandasObject):
# TODO share more methods/attributes
axes: list[Index]
Reported by Pylint.
Line: 33
Column: 5
axes: list[Index]
@property
def items(self) -> Index:
raise AbstractMethodError(self)
@final
def __len__(self) -> int:
return len(self.items)
Reported by Pylint.
Line: 41
Column: 5
return len(self.items)
@property
def ndim(self) -> int:
return len(self.axes)
@property
def shape(self) -> Shape:
return tuple(len(ax) for ax in self.axes)
Reported by Pylint.
Line: 45
Column: 5
return len(self.axes)
@property
def shape(self) -> Shape:
return tuple(len(ax) for ax in self.axes)
@final
def _validate_set_axis(self, axis: int, new_labels: Index) -> None:
# Caller is responsible for ensuring we have an Index object.
Reported by Pylint.
Line: 65
Column: 5
f"values have {new_len} elements"
)
def reindex_indexer(
self: T,
new_axis,
indexer,
axis: int,
fill_value=None,
Reported by Pylint.
Line: 65
Column: 5
f"values have {new_len} elements"
)
def reindex_indexer(
self: T,
new_axis,
indexer,
axis: int,
fill_value=None,
Reported by Pylint.
Line: 79
Column: 5
raise AbstractMethodError(self)
@final
def reindex_axis(
self: T,
new_index: Index,
axis: int,
fill_value=None,
consolidate: bool = True,
Reported by Pylint.
pandas/tests/frame/methods/test_matmul.py
19 issues
Line: 4
Column: 1
import operator
import numpy as np
import pytest
from pandas import (
DataFrame,
Index,
Series,
Reported by Pylint.
Line: 84
Column: 13
msg = r"shapes \(10, 4\) and \(5, 3\) not aligned"
with pytest.raises(ValueError, match=msg):
a @ df
with pytest.raises(ValueError, match=msg):
a.tolist() @ df
Reported by Pylint.
Line: 86
Column: 13
with pytest.raises(ValueError, match=msg):
a @ df
with pytest.raises(ValueError, match=msg):
a.tolist() @ df
Reported by Pylint.
Line: 1
Column: 1
import operator
import numpy as np
import pytest
from pandas import (
DataFrame,
Index,
Series,
Reported by Pylint.
Line: 14
Column: 1
import pandas._testing as tm
class TestMatMul:
def test_matmul(self):
# matmul test is for GH#10259
a = DataFrame(
np.random.randn(3, 4), index=["a", "b", "c"], columns=["p", "q", "r", "s"]
)
Reported by Pylint.
Line: 15
Column: 5
class TestMatMul:
def test_matmul(self):
# matmul test is for GH#10259
a = DataFrame(
np.random.randn(3, 4), index=["a", "b", "c"], columns=["p", "q", "r", "s"]
)
b = DataFrame(
Reported by Pylint.
Line: 15
Column: 5
class TestMatMul:
def test_matmul(self):
# matmul test is for GH#10259
a = DataFrame(
np.random.randn(3, 4), index=["a", "b", "c"], columns=["p", "q", "r", "s"]
)
b = DataFrame(
Reported by Pylint.
Line: 17
Column: 9
class TestMatMul:
def test_matmul(self):
# matmul test is for GH#10259
a = DataFrame(
np.random.randn(3, 4), index=["a", "b", "c"], columns=["p", "q", "r", "s"]
)
b = DataFrame(
np.random.randn(4, 2), index=["p", "q", "r", "s"], columns=["one", "two"]
)
Reported by Pylint.
Line: 20
Column: 9
a = DataFrame(
np.random.randn(3, 4), index=["a", "b", "c"], columns=["p", "q", "r", "s"]
)
b = DataFrame(
np.random.randn(4, 2), index=["p", "q", "r", "s"], columns=["one", "two"]
)
# DataFrame @ DataFrame
result = operator.matmul(a, b)
Reported by Pylint.
Line: 38
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# np.array @ DataFrame
result = operator.matmul(a.values, b)
assert isinstance(result, DataFrame)
assert result.columns.equals(b.columns)
assert result.index.equals(Index(range(3)))
expected = np.dot(a.values, b.values)
tm.assert_almost_equal(result.values, expected)
Reported by Bandit.
pandas/tests/frame/methods/test_assign.py
19 issues
Line: 1
Column: 1
import pytest
from pandas import DataFrame
import pandas._testing as tm
class TestAssign:
def test_assign(self):
df = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
Reported by Pylint.
Line: 70
Column: 13
# non-keyword argument
msg = r"assign\(\) takes 1 positional argument but 2 were given"
with pytest.raises(TypeError, match=msg):
df.assign(lambda x: x.A)
msg = "'DataFrame' object has no attribute 'C'"
with pytest.raises(AttributeError, match=msg):
df.assign(C=df.A, D=df.A + df.C)
def test_assign_dependent(self):
Reported by Pylint.
Line: 1
Column: 1
import pytest
from pandas import DataFrame
import pandas._testing as tm
class TestAssign:
def test_assign(self):
df = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
Reported by Pylint.
Line: 7
Column: 1
import pandas._testing as tm
class TestAssign:
def test_assign(self):
df = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
original = df.copy()
result = df.assign(C=df.B / df.A)
expected = df.copy()
Reported by Pylint.
Line: 8
Column: 5
class TestAssign:
def test_assign(self):
df = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
original = df.copy()
result = df.assign(C=df.B / df.A)
expected = df.copy()
expected["C"] = [4, 2.5, 2]
Reported by Pylint.
Line: 8
Column: 5
class TestAssign:
def test_assign(self):
df = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
original = df.copy()
result = df.assign(C=df.B / df.A)
expected = df.copy()
expected["C"] = [4, 2.5, 2]
Reported by Pylint.
Line: 9
Column: 9
class TestAssign:
def test_assign(self):
df = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
original = df.copy()
result = df.assign(C=df.B / df.A)
expected = df.copy()
expected["C"] = [4, 2.5, 2]
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 43
Column: 5
result = df.assign(A=lambda x: x.A + x.B)
tm.assert_frame_equal(result, expected)
def test_assign_multiple(self):
df = DataFrame([[1, 4], [2, 5], [3, 6]], columns=["A", "B"])
result = df.assign(C=[7, 8, 9], D=df.A, E=lambda x: x.B)
expected = DataFrame(
[[1, 4, 7, 1, 4], [2, 5, 8, 2, 5], [3, 6, 9, 3, 6]], columns=list("ABCDE")
)
Reported by Pylint.
Line: 43
Column: 5
result = df.assign(A=lambda x: x.A + x.B)
tm.assert_frame_equal(result, expected)
def test_assign_multiple(self):
df = DataFrame([[1, 4], [2, 5], [3, 6]], columns=["A", "B"])
result = df.assign(C=[7, 8, 9], D=df.A, E=lambda x: x.B)
expected = DataFrame(
[[1, 4, 7, 1, 4], [2, 5, 8, 2, 5], [3, 6, 9, 3, 6]], columns=list("ABCDE")
)
Reported by Pylint.
Line: 44
Column: 9
tm.assert_frame_equal(result, expected)
def test_assign_multiple(self):
df = DataFrame([[1, 4], [2, 5], [3, 6]], columns=["A", "B"])
result = df.assign(C=[7, 8, 9], D=df.A, E=lambda x: x.B)
expected = DataFrame(
[[1, 4, 7, 1, 4], [2, 5, 8, 2, 5], [3, 6, 9, 3, 6]], columns=list("ABCDE")
)
tm.assert_frame_equal(result, expected)
Reported by Pylint.
pandas/tests/base/test_unique.py
19 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas._libs import iNaT
from pandas.core.dtypes.common import (
is_datetime64tz_dtype,
needs_i8_conversion,
)
Reported by Pylint.
Line: 34
Column: 24
elif isinstance(obj, pd.Index):
expected = pd.Index(unique_values, dtype=obj.dtype)
if is_datetime64tz_dtype(obj.dtype):
expected = expected.normalize()
tm.assert_index_equal(result, expected, exact=True)
else:
expected = np.array(unique_values)
tm.assert_numpy_array_equal(result, expected)
Reported by Pylint.
Line: 76
Column: 24
expected = pd.Index(unique_values, dtype=obj.dtype)
if is_datetime64tz_dtype(obj.dtype):
result = result.normalize()
expected = expected.normalize()
tm.assert_index_equal(result, expected, exact=True)
else:
expected = np.array(unique_values, dtype=obj.dtype)
tm.assert_numpy_array_equal(result, expected)
Reported by Pylint.
Line: 28
Column: 40
expected = pd.MultiIndex.from_tuples(unique_values)
expected.names = obj.names
tm.assert_index_equal(result, expected, exact=True)
elif isinstance(obj, pd.Index) and obj._is_backward_compat_public_numeric_index:
expected = NumericIndex(unique_values, dtype=obj.dtype)
tm.assert_index_equal(result, expected, exact=True)
elif isinstance(obj, pd.Index):
expected = pd.Index(unique_values, dtype=obj.dtype)
if is_datetime64tz_dtype(obj.dtype):
Reported by Pylint.
Line: 69
Column: 38
unique_values_not_null = [val for val in unique_values_raw if not pd.isnull(val)]
unique_values = [null_obj] + unique_values_not_null
if isinstance(obj, pd.Index) and obj._is_backward_compat_public_numeric_index:
expected = NumericIndex(unique_values, dtype=obj.dtype)
tm.assert_index_equal(result, expected, exact=True)
elif isinstance(obj, pd.Index):
expected = pd.Index(unique_values, dtype=obj.dtype)
if is_datetime64tz_dtype(obj.dtype):
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas._libs import iNaT
from pandas.core.dtypes.common import (
is_datetime64tz_dtype,
needs_i8_conversion,
)
Reported by Pylint.
Line: 17
Column: 1
from pandas.tests.base.common import allow_na_ops
def test_unique(index_or_series_obj):
obj = index_or_series_obj
obj = np.repeat(obj, range(1, len(obj) + 1))
result = obj.unique()
# dict.fromkeys preserves the order
Reported by Pylint.
Line: 42
Column: 1
@pytest.mark.parametrize("null_obj", [np.nan, None])
def test_unique_null(null_obj, index_or_series_obj):
obj = index_or_series_obj
if not allow_na_ops(obj):
pytest.skip("type doesn't allow for NA operations")
elif len(obj) < 1:
Reported by Pylint.
Line: 83
Column: 1
tm.assert_numpy_array_equal(result, expected)
def test_nunique(index_or_series_obj):
obj = index_or_series_obj
obj = np.repeat(obj, range(1, len(obj) + 1))
expected = len(obj.unique())
assert obj.nunique(dropna=False) == expected
Reported by Pylint.
Line: 87
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
obj = index_or_series_obj
obj = np.repeat(obj, range(1, len(obj) + 1))
expected = len(obj.unique())
assert obj.nunique(dropna=False) == expected
@pytest.mark.parametrize("null_obj", [np.nan, None])
def test_nunique_null(null_obj, index_or_series_obj):
obj = index_or_series_obj
Reported by Bandit.
pandas/tests/frame/methods/test_duplicated.py
19 issues
Line: 4
Column: 1
import re
import numpy as np
import pytest
from pandas import (
DataFrame,
Series,
date_range,
Reported by Pylint.
Line: 1
Column: 1
import re
import numpy as np
import pytest
from pandas import (
DataFrame,
Series,
date_range,
Reported by Pylint.
Line: 15
Column: 1
@pytest.mark.parametrize("subset", ["a", ["a"], ["a", "B"]])
def test_duplicated_with_misspelled_column_name(subset):
# GH 19730
df = DataFrame({"A": [0, 0, 1], "B": [0, 0, 1], "C": [0, 0, 1]})
msg = re.escape("Index(['a'], dtype='object')")
with pytest.raises(KeyError, match=msg):
Reported by Pylint.
Line: 17
Column: 5
@pytest.mark.parametrize("subset", ["a", ["a"], ["a", "B"]])
def test_duplicated_with_misspelled_column_name(subset):
# GH 19730
df = DataFrame({"A": [0, 0, 1], "B": [0, 0, 1], "C": [0, 0, 1]})
msg = re.escape("Index(['a'], dtype='object')")
with pytest.raises(KeyError, match=msg):
df.duplicated(subset)
Reported by Pylint.
Line: 25
Column: 1
@pytest.mark.slow
def test_duplicated_do_not_fail_on_wide_dataframes():
# gh-21524
# Given the wide dataframe with a lot of columns
# with different (important!) values
data = {f"col_{i:02d}": np.random.randint(0, 1000, 30000) for i in range(100)}
df = DataFrame(data).T
Reported by Pylint.
Line: 30
Column: 5
# Given the wide dataframe with a lot of columns
# with different (important!) values
data = {f"col_{i:02d}": np.random.randint(0, 1000, 30000) for i in range(100)}
df = DataFrame(data).T
result = df.duplicated()
# Then duplicates produce the bool Series as a result and don't fail during
# calculation. Actual values doesn't matter here, though usually it's all
# False in this case
Reported by Pylint.
Line: 36
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# Then duplicates produce the bool Series as a result and don't fail during
# calculation. Actual values doesn't matter here, though usually it's all
# False in this case
assert isinstance(result, Series)
assert result.dtype == np.bool_
@pytest.mark.parametrize(
"keep, expected",
Reported by Bandit.
Line: 37
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# calculation. Actual values doesn't matter here, though usually it's all
# False in this case
assert isinstance(result, Series)
assert result.dtype == np.bool_
@pytest.mark.parametrize(
"keep, expected",
[
Reported by Bandit.
Line: 46
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_keep(keep, expected):
df = DataFrame({"A": [0, 1, 1, 2, 0], "B": ["a", "b", "b", "c", "a"]})
result = df.duplicated(keep=keep)
Reported by Pylint.
Line: 49
Column: 5
],
)
def test_duplicated_keep(keep, expected):
df = DataFrame({"A": [0, 1, 1, 2, 0], "B": ["a", "b", "b", "c", "a"]})
result = df.duplicated(keep=keep)
tm.assert_series_equal(result, expected)
Reported by Pylint.