The following issues were found
asv_bench/benchmarks/finalize.py
8 issues
Line: 1
Column: 1
import pandas as pd
class Finalize:
param_names = ["series", "frame"]
params = [pd.Series, pd.DataFrame]
def setup(self, param):
N = 1000
Reported by Pylint.
Line: 13
Column: 9
obj = param(dtype=float)
for i in range(N):
obj.attrs[i] = i
self.obj = obj
def time_finalize_micro(self, param):
self.obj.__finalize__(self.obj, method="__finalize__")
Reported by Pylint.
Line: 15
Column: 35
obj.attrs[i] = i
self.obj = obj
def time_finalize_micro(self, param):
self.obj.__finalize__(self.obj, method="__finalize__")
Reported by Pylint.
Line: 1
Column: 1
import pandas as pd
class Finalize:
param_names = ["series", "frame"]
params = [pd.Series, pd.DataFrame]
def setup(self, param):
N = 1000
Reported by Pylint.
Line: 4
Column: 1
import pandas as pd
class Finalize:
param_names = ["series", "frame"]
params = [pd.Series, pd.DataFrame]
def setup(self, param):
N = 1000
Reported by Pylint.
Line: 8
Column: 5
param_names = ["series", "frame"]
params = [pd.Series, pd.DataFrame]
def setup(self, param):
N = 1000
obj = param(dtype=float)
for i in range(N):
obj.attrs[i] = i
self.obj = obj
Reported by Pylint.
Line: 9
Column: 9
params = [pd.Series, pd.DataFrame]
def setup(self, param):
N = 1000
obj = param(dtype=float)
for i in range(N):
obj.attrs[i] = i
self.obj = obj
Reported by Pylint.
Line: 15
Column: 5
obj.attrs[i] = i
self.obj = obj
def time_finalize_micro(self, param):
self.obj.__finalize__(self.obj, method="__finalize__")
Reported by Pylint.
pandas/tests/arrays/interval/test_astype.py
8 issues
Line: 1
Column: 1
import pytest
from pandas import (
Categorical,
CategoricalDtype,
Index,
IntervalIndex,
)
import pandas._testing as tm
Reported by Pylint.
Line: 16
Column: 15
@pytest.mark.parametrize("ordered", [True, False])
def test_astype_categorical_retains_ordered(self, ordered):
index = IntervalIndex.from_breaks(range(5))
arr = index._data
dtype = CategoricalDtype(None, ordered=ordered)
expected = Categorical(list(arr), ordered=ordered)
result = arr.astype(dtype)
Reported by Pylint.
Line: 1
Column: 1
import pytest
from pandas import (
Categorical,
CategoricalDtype,
Index,
IntervalIndex,
)
import pandas._testing as tm
Reported by Pylint.
Line: 12
Column: 1
import pandas._testing as tm
class TestAstype:
@pytest.mark.parametrize("ordered", [True, False])
def test_astype_categorical_retains_ordered(self, ordered):
index = IntervalIndex.from_breaks(range(5))
arr = index._data
Reported by Pylint.
Line: 12
Column: 1
import pandas._testing as tm
class TestAstype:
@pytest.mark.parametrize("ordered", [True, False])
def test_astype_categorical_retains_ordered(self, ordered):
index = IntervalIndex.from_breaks(range(5))
arr = index._data
Reported by Pylint.
Line: 14
Column: 5
class TestAstype:
@pytest.mark.parametrize("ordered", [True, False])
def test_astype_categorical_retains_ordered(self, ordered):
index = IntervalIndex.from_breaks(range(5))
arr = index._data
dtype = CategoricalDtype(None, ordered=ordered)
Reported by Pylint.
Line: 14
Column: 5
class TestAstype:
@pytest.mark.parametrize("ordered", [True, False])
def test_astype_categorical_retains_ordered(self, ordered):
index = IntervalIndex.from_breaks(range(5))
arr = index._data
dtype = CategoricalDtype(None, ordered=ordered)
Reported by Pylint.
Line: 22
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
expected = Categorical(list(arr), ordered=ordered)
result = arr.astype(dtype)
assert result.ordered is ordered
tm.assert_categorical_equal(result, expected)
# test IntervalIndex.astype while we're at it.
result = index.astype(dtype)
expected = Index(expected)
Reported by Bandit.
pandas/core/sample.py
8 issues
Line: 8
Column: 1
import numpy as np
from pandas._libs import lib
from pandas._typing import FrameOrSeries
from pandas.core.dtypes.generic import (
ABCDataFrame,
ABCSeries,
Reported by Pylint.
Line: 116
Column: 19
size: int,
replace: bool,
weights: np.ndarray | None,
random_state: np.random.RandomState | np.random.Generator,
) -> np.ndarray:
"""
Randomly sample `size` indices in `np.arange(obj_len)`
Parameters
Reported by Pylint.
Line: 51
Column: 16
)
if isinstance(obj, ABCSeries):
func = obj._constructor
else:
func = obj._constructor_sliced
weights = func(weights, dtype="float64")._values
Reported by Pylint.
Line: 53
Column: 16
if isinstance(obj, ABCSeries):
func = obj._constructor
else:
func = obj._constructor_sliced
weights = func(weights, dtype="float64")._values
if len(weights) != obj.shape[axis]:
raise ValueError("Weights and axis to be sampled must be of same length")
Reported by Pylint.
Line: 55
Column: 15
else:
func = obj._constructor_sliced
weights = func(weights, dtype="float64")._values
if len(weights) != obj.shape[axis]:
raise ValueError("Weights and axis to be sampled must be of same length")
if lib.has_infs(weights):
Reported by Pylint.
Line: 17
Column: 1
)
def preprocess_weights(obj: FrameOrSeries, weights, axis: int) -> np.ndarray:
"""
Process and validate the `weights` argument to `NDFrame.sample` and
`.GroupBy.sample`.
Returns `weights` as an ndarray[np.float64], validated except for normalizing
Reported by Pylint.
Line: 74
Column: 1
return weights
def process_sampling_size(
n: int | None, frac: float | None, replace: bool
) -> int | None:
"""
Process and validate the `n` and `frac` arguments to `NDFrame.sample` and
`.GroupBy.sample`.
Reported by Pylint.
Line: 97
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
if n % 1 != 0:
raise ValueError("Only integers accepted as `n` values")
else:
assert frac is not None # for mypy
if frac > 1 and not replace:
raise ValueError(
"Replace has to be set to `True` when "
"upsampling the population `frac` > 1."
)
Reported by Bandit.
pandas/tests/arrays/categorical/test_warnings.py
8 issues
Line: 1
Column: 1
import pytest
from pandas.util._test_decorators import async_mark
import pandas._testing as tm
class TestCategoricalWarnings:
@async_mark()
Reported by Pylint.
Line: 13
Column: 9
async def test_tab_complete_warning(self, ip):
# https://github.com/pandas-dev/pandas/issues/16409
pytest.importorskip("IPython", minversion="6.0.0")
from IPython.core.completer import provisionalcompleter
code = "import pandas as pd; c = Categorical([])"
await ip.run_code(code)
# GH 31324 newer jedi version raises Deprecation warning;
Reported by Pylint.
Line: 1
Column: 1
import pytest
from pandas.util._test_decorators import async_mark
import pandas._testing as tm
class TestCategoricalWarnings:
@async_mark()
Reported by Pylint.
Line: 8
Column: 1
import pandas._testing as tm
class TestCategoricalWarnings:
@async_mark()
async def test_tab_complete_warning(self, ip):
# https://github.com/pandas-dev/pandas/issues/16409
pytest.importorskip("IPython", minversion="6.0.0")
from IPython.core.completer import provisionalcompleter
Reported by Pylint.
Line: 8
Column: 1
import pandas._testing as tm
class TestCategoricalWarnings:
@async_mark()
async def test_tab_complete_warning(self, ip):
# https://github.com/pandas-dev/pandas/issues/16409
pytest.importorskip("IPython", minversion="6.0.0")
from IPython.core.completer import provisionalcompleter
Reported by Pylint.
Line: 10
Column: 5
class TestCategoricalWarnings:
@async_mark()
async def test_tab_complete_warning(self, ip):
# https://github.com/pandas-dev/pandas/issues/16409
pytest.importorskip("IPython", minversion="6.0.0")
from IPython.core.completer import provisionalcompleter
code = "import pandas as pd; c = Categorical([])"
Reported by Pylint.
Line: 10
Column: 5
class TestCategoricalWarnings:
@async_mark()
async def test_tab_complete_warning(self, ip):
# https://github.com/pandas-dev/pandas/issues/16409
pytest.importorskip("IPython", minversion="6.0.0")
from IPython.core.completer import provisionalcompleter
code = "import pandas as pd; c = Categorical([])"
Reported by Pylint.
Line: 13
Column: 9
async def test_tab_complete_warning(self, ip):
# https://github.com/pandas-dev/pandas/issues/16409
pytest.importorskip("IPython", minversion="6.0.0")
from IPython.core.completer import provisionalcompleter
code = "import pandas as pd; c = Categorical([])"
await ip.run_code(code)
# GH 31324 newer jedi version raises Deprecation warning;
Reported by Pylint.
pandas/core/reshape/util.py
8 issues
Line: 1
Column: 1
import numpy as np
from pandas.core.dtypes.common import is_list_like
def cartesian_product(X):
"""
Numpy version of itertools.product.
Sometimes faster (for large inputs)...
Reported by Pylint.
Line: 6
Column: 1
from pandas.core.dtypes.common import is_list_like
def cartesian_product(X):
"""
Numpy version of itertools.product.
Sometimes faster (for large inputs)...
Parameters
Reported by Pylint.
Line: 32
Column: 9
msg = "Input must be a list-like of list-likes"
if not is_list_like(X):
raise TypeError(msg)
for x in X:
if not is_list_like(x):
raise TypeError(msg)
if len(X) == 0:
return []
Reported by Pylint.
Line: 39
Column: 5
if len(X) == 0:
return []
lenX = np.fromiter((len(x) for x in X), dtype=np.intp)
cumprodX = np.cumproduct(lenX)
if np.any(cumprodX < 0):
raise ValueError("Product space too large to allocate arrays!")
Reported by Pylint.
Line: 40
Column: 5
return []
lenX = np.fromiter((len(x) for x in X), dtype=np.intp)
cumprodX = np.cumproduct(lenX)
if np.any(cumprodX < 0):
raise ValueError("Product space too large to allocate arrays!")
a = np.roll(cumprodX, 1)
Reported by Pylint.
Line: 45
Column: 5
if np.any(cumprodX < 0):
raise ValueError("Product space too large to allocate arrays!")
a = np.roll(cumprodX, 1)
a[0] = 1
if cumprodX[-1] != 0:
b = cumprodX[-1] / cumprodX
else:
Reported by Pylint.
Line: 49
Column: 9
a[0] = 1
if cumprodX[-1] != 0:
b = cumprodX[-1] / cumprodX
else:
# if any factor is empty, the cartesian product is empty
b = np.zeros_like(cumprodX)
return [tile_compat(np.repeat(x, b[i]), np.product(a[i])) for i, x in enumerate(X)]
Reported by Pylint.
Line: 52
Column: 9
b = cumprodX[-1] / cumprodX
else:
# if any factor is empty, the cartesian product is empty
b = np.zeros_like(cumprodX)
return [tile_compat(np.repeat(x, b[i]), np.product(a[i])) for i, x in enumerate(X)]
def tile_compat(arr, num: int):
Reported by Pylint.
pandas/tests/extension/list/test_list.py
8 issues
Line: 1
Column: 1
import pytest
import pandas as pd
from pandas.tests.extension.list.array import (
ListArray,
ListDtype,
make_data,
)
Reported by Pylint.
Line: 19
Column: 5
@pytest.fixture
def data():
"""Length-100 ListArray for semantics test."""
data = make_data()
while len(data[0]) == len(data[1]):
data = make_data()
return ListArray(data)
Reported by Pylint.
Line: 27
Column: 17
return ListArray(data)
def test_to_csv(data):
# https://github.com/pandas-dev/pandas/issues/28840
# array with list-likes fail when doing astype(str) on the numpy array
# which was done in to_native_types
df = pd.DataFrame({"a": data})
res = df.to_csv()
Reported by Pylint.
Line: 1
Column: 1
import pytest
import pandas as pd
from pandas.tests.extension.list.array import (
ListArray,
ListDtype,
make_data,
)
Reported by Pylint.
Line: 12
Column: 1
@pytest.fixture
def dtype():
return ListDtype()
@pytest.fixture
def data():
Reported by Pylint.
Line: 27
Column: 1
return ListArray(data)
def test_to_csv(data):
# https://github.com/pandas-dev/pandas/issues/28840
# array with list-likes fail when doing astype(str) on the numpy array
# which was done in to_native_types
df = pd.DataFrame({"a": data})
res = df.to_csv()
Reported by Pylint.
Line: 31
Column: 5
# https://github.com/pandas-dev/pandas/issues/28840
# array with list-likes fail when doing astype(str) on the numpy array
# which was done in to_native_types
df = pd.DataFrame({"a": data})
res = df.to_csv()
assert str(data[0]) in res
Reported by Pylint.
Line: 33
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# which was done in to_native_types
df = pd.DataFrame({"a": data})
res = df.to_csv()
assert str(data[0]) in res
Reported by Bandit.
pandas/tests/indexes/datetimes/test_npfuncs.py
8 issues
Line: 12
Column: 20
# GH#14042
indices = date_range("2016-01-01 00:00:00+0200", freq="S", periods=10)
result = np.split(indices, indices_or_sections=[])[0]
expected = indices._with_freq(None)
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 12
Column: 20
# GH#14042
indices = date_range("2016-01-01 00:00:00+0200", freq="S", periods=10)
result = np.split(indices, indices_or_sections=[])[0]
expected = indices._with_freq(None)
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 12
Column: 20
# GH#14042
indices = date_range("2016-01-01 00:00:00+0200", freq="S", periods=10)
result = np.split(indices, indices_or_sections=[])[0]
expected = indices._with_freq(None)
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
from pandas import date_range
import pandas._testing as tm
class TestSplit:
def test_split_non_utc(self):
# GH#14042
Reported by Pylint.
Line: 7
Column: 1
import pandas._testing as tm
class TestSplit:
def test_split_non_utc(self):
# GH#14042
indices = date_range("2016-01-01 00:00:00+0200", freq="S", periods=10)
result = np.split(indices, indices_or_sections=[])[0]
expected = indices._with_freq(None)
Reported by Pylint.
Line: 7
Column: 1
import pandas._testing as tm
class TestSplit:
def test_split_non_utc(self):
# GH#14042
indices = date_range("2016-01-01 00:00:00+0200", freq="S", periods=10)
result = np.split(indices, indices_or_sections=[])[0]
expected = indices._with_freq(None)
Reported by Pylint.
Line: 8
Column: 5
class TestSplit:
def test_split_non_utc(self):
# GH#14042
indices = date_range("2016-01-01 00:00:00+0200", freq="S", periods=10)
result = np.split(indices, indices_or_sections=[])[0]
expected = indices._with_freq(None)
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 8
Column: 5
class TestSplit:
def test_split_non_utc(self):
# GH#14042
indices = date_range("2016-01-01 00:00:00+0200", freq="S", periods=10)
result = np.split(indices, indices_or_sections=[])[0]
expected = indices._with_freq(None)
tm.assert_index_equal(result, expected)
Reported by Pylint.
pandas/core/ops/missing.py
8 issues
Line: 37
Column: 24
from pandas.core.ops import roperator
def fill_zeros(result, x, y):
"""
If this is a reversed op, then flip x,y
If we have an integer value (or array in y)
and we have 0's, fill them with np.nan,
Reported by Pylint.
Line: 106
Column: 3
array([ inf, nan, -inf])
"""
if not isinstance(result, np.ndarray):
# FIXME: SparseArray would raise TypeError with np.putmask
return result
if is_scalar(y):
y = np.array(y)
Reported by Pylint.
Line: 115
Column: 3
zmask = y == 0
if isinstance(zmask, bool):
# FIXME: numpy did not evaluate pointwise, seen in docs build
return result
if zmask.any():
# Flip sign if necessary for -0.0
Reported by Pylint.
Line: 37
Column: 1
from pandas.core.ops import roperator
def fill_zeros(result, x, y):
"""
If this is a reversed op, then flip x,y
If we have an integer value (or array in y)
and we have 0's, fill them with np.nan,
Reported by Pylint.
Line: 37
Column: 1
from pandas.core.ops import roperator
def fill_zeros(result, x, y):
"""
If this is a reversed op, then flip x,y
If we have an integer value (or array in y)
and we have 0's, fill them with np.nan,
Reported by Pylint.
Line: 77
Column: 1
return result
def mask_zero_div_zero(x, y, result):
"""
Set results of 0 // 0 to np.nan, regardless of the dtypes
of the numerator or the denominator.
Parameters
Reported by Pylint.
Line: 77
Column: 1
return result
def mask_zero_div_zero(x, y, result):
"""
Set results of 0 // 0 to np.nan, regardless of the dtypes
of the numerator or the denominator.
Parameters
Reported by Pylint.
Line: 140
Column: 1
return result
def dispatch_fill_zeros(op, left, right, result):
"""
Call fill_zeros with the appropriate fill value depending on the operation,
with special logic for divmod and rdivmod.
Parameters
Reported by Pylint.
pandas/tests/frame/methods/test_convert_dtypes.py
8 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
import pandas._testing as tm
class TestConvertDtypes:
@pytest.mark.parametrize(
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
import pandas._testing as tm
class TestConvertDtypes:
@pytest.mark.parametrize(
Reported by Pylint.
Line: 8
Column: 1
import pandas._testing as tm
class TestConvertDtypes:
@pytest.mark.parametrize(
"convert_integer, expected", [(False, np.dtype("int32")), (True, "Int32")]
)
def test_convert_dtypes(self, convert_integer, expected, string_storage):
# Specific types are tested in tests/series/test_dtypes.py
Reported by Pylint.
Line: 11
Column: 5
class TestConvertDtypes:
@pytest.mark.parametrize(
"convert_integer, expected", [(False, np.dtype("int32")), (True, "Int32")]
)
def test_convert_dtypes(self, convert_integer, expected, string_storage):
# Specific types are tested in tests/series/test_dtypes.py
# Just check that it works for DataFrame here
df = pd.DataFrame(
{
Reported by Pylint.
Line: 11
Column: 5
class TestConvertDtypes:
@pytest.mark.parametrize(
"convert_integer, expected", [(False, np.dtype("int32")), (True, "Int32")]
)
def test_convert_dtypes(self, convert_integer, expected, string_storage):
# Specific types are tested in tests/series/test_dtypes.py
# Just check that it works for DataFrame here
df = pd.DataFrame(
{
Reported by Pylint.
Line: 15
Column: 9
def test_convert_dtypes(self, convert_integer, expected, string_storage):
# Specific types are tested in tests/series/test_dtypes.py
# Just check that it works for DataFrame here
df = pd.DataFrame(
{
"a": pd.Series([1, 2, 3], dtype=np.dtype("int32")),
"b": pd.Series(["x", "y", "z"], dtype=np.dtype("O")),
}
)
Reported by Pylint.
Line: 31
Column: 5
)
tm.assert_frame_equal(result, expected)
def test_convert_empty(self):
# Empty DataFrame can pass convert_dtypes, see GH#40393
empty_df = pd.DataFrame()
tm.assert_frame_equal(empty_df, empty_df.convert_dtypes())
Reported by Pylint.
Line: 31
Column: 5
)
tm.assert_frame_equal(result, expected)
def test_convert_empty(self):
# Empty DataFrame can pass convert_dtypes, see GH#40393
empty_df = pd.DataFrame()
tm.assert_frame_equal(empty_df, empty_df.convert_dtypes())
Reported by Pylint.
pandas/tests/dtypes/test_concat.py
8 issues
Line: 1
Column: 1
import pytest
import pandas.core.dtypes.concat as _concat
import pandas as pd
from pandas import Series
import pandas._testing as tm
Reported by Pylint.
Line: 15
Column: 51
ser1 = Series(["a", "b", "c"], dtype="category")
ser2 = Series([], dtype="category")
result = _concat.concat_compat([ser1._values, ser2._values])
expected = pd.concat([ser1, ser2])._values
tm.assert_categorical_equal(result, expected)
@pytest.mark.parametrize("copy", [True, False])
Reported by Pylint.
Line: 15
Column: 37
ser1 = Series(["a", "b", "c"], dtype="category")
ser2 = Series([], dtype="category")
result = _concat.concat_compat([ser1._values, ser2._values])
expected = pd.concat([ser1, ser2])._values
tm.assert_categorical_equal(result, expected)
@pytest.mark.parametrize("copy", [True, False])
Reported by Pylint.
Line: 16
Column: 16
ser2 = Series([], dtype="category")
result = _concat.concat_compat([ser1._values, ser2._values])
expected = pd.concat([ser1, ser2])._values
tm.assert_categorical_equal(result, expected)
@pytest.mark.parametrize("copy", [True, False])
def test_concat_single_dataframe_tz_aware(copy):
Reported by Pylint.
Line: 1
Column: 1
import pytest
import pandas.core.dtypes.concat as _concat
import pandas as pd
from pandas import Series
import pandas._testing as tm
Reported by Pylint.
Line: 10
Column: 1
import pandas._testing as tm
def test_concat_mismatched_categoricals_with_empty():
# concat_compat behavior on series._values should match pd.concat on series
ser1 = Series(["a", "b", "c"], dtype="category")
ser2 = Series([], dtype="category")
result = _concat.concat_compat([ser1._values, ser2._values])
Reported by Pylint.
Line: 21
Column: 1
@pytest.mark.parametrize("copy", [True, False])
def test_concat_single_dataframe_tz_aware(copy):
# https://github.com/pandas-dev/pandas/issues/25257
df = pd.DataFrame(
{"timestamp": [pd.Timestamp("2020-04-08 09:00:00.709949+0000", tz="UTC")]}
)
expected = df.copy()
Reported by Pylint.
Line: 23
Column: 5
@pytest.mark.parametrize("copy", [True, False])
def test_concat_single_dataframe_tz_aware(copy):
# https://github.com/pandas-dev/pandas/issues/25257
df = pd.DataFrame(
{"timestamp": [pd.Timestamp("2020-04-08 09:00:00.709949+0000", tz="UTC")]}
)
expected = df.copy()
result = pd.concat([df], copy=copy)
tm.assert_frame_equal(result, expected)
Reported by Pylint.