The following issues were found
pandas/core/arraylike.py
33 issues
Line: 13
Column: 1
import numpy as np
from pandas._libs import lib
from pandas.core.construction import extract_array
from pandas.core.ops import (
maybe_dispatch_ufunc_to_dunder_op,
roperator,
Reported by Pylint.
Line: 261
Column: 9
# error: "Type[ndarray]" has no attribute "__array_ufunc__"
no_defer = (
np.ndarray.__array_ufunc__, # type: ignore[attr-defined]
cls.__array_ufunc__,
)
for item in inputs:
higher_priority = (
Reported by Pylint.
Line: 27
Column: 34
# -------------------------------------------------------------
# Comparisons
def _cmp_method(self, other, op):
return NotImplemented
@unpack_zerodim_and_defer("__eq__")
def __eq__(self, other):
return self._cmp_method(other, operator.eq)
Reported by Pylint.
Line: 27
Column: 27
# -------------------------------------------------------------
# Comparisons
def _cmp_method(self, other, op):
return NotImplemented
@unpack_zerodim_and_defer("__eq__")
def __eq__(self, other):
return self._cmp_method(other, operator.eq)
Reported by Pylint.
Line: 57
Column: 31
# -------------------------------------------------------------
# Logical Methods
def _logical_method(self, other, op):
return NotImplemented
@unpack_zerodim_and_defer("__and__")
def __and__(self, other):
return self._logical_method(other, operator.and_)
Reported by Pylint.
Line: 57
Column: 38
# -------------------------------------------------------------
# Logical Methods
def _logical_method(self, other, op):
return NotImplemented
@unpack_zerodim_and_defer("__and__")
def __and__(self, other):
return self._logical_method(other, operator.and_)
Reported by Pylint.
Line: 87
Column: 29
# -------------------------------------------------------------
# Arithmetic Methods
def _arith_method(self, other, op):
return NotImplemented
@unpack_zerodim_and_defer("__add__")
def __add__(self, other):
return self._arith_method(other, operator.add)
Reported by Pylint.
Line: 87
Column: 36
# -------------------------------------------------------------
# Arithmetic Methods
def _arith_method(self, other, op):
return NotImplemented
@unpack_zerodim_and_defer("__add__")
def __add__(self, other):
return self._arith_method(other, operator.add)
Reported by Pylint.
Line: 166
Column: 16
from pandas import DataFrame
if isinstance(other, DataFrame):
return frame._indexed_same(other)
else:
# Series -> match index
return frame.columns.equals(other.index)
Reported by Pylint.
Line: 273
Column: 38
has_array_ufunc = (
hasattr(item, "__array_ufunc__")
and type(item).__array_ufunc__ not in no_defer
and not isinstance(item, self._HANDLED_TYPES)
)
if higher_priority or has_array_ufunc:
return NotImplemented
# align all the inputs.
Reported by Pylint.
pandas/util/version/__init__.py
33 issues
Line: 1
Column: 1
# Vendored from https://github.com/pypa/packaging/blob/main/packaging/_structures.py
# and https://github.com/pypa/packaging/blob/main/packaging/_structures.py
# changeset ae891fd74d6dd4c6063bb04f2faeadaac6fc6313
# 04/30/2021
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import annotations
Reported by Pylint.
Line: 26
Column: 1
__all__ = ["parse", "Version", "LegacyVersion", "InvalidVersion", "VERSION_PATTERN"]
class InfinityType:
def __repr__(self) -> str:
return "Infinity"
def __hash__(self) -> int:
return hash(repr(self))
Reported by Pylint.
Line: 58
Column: 1
Infinity = InfinityType()
class NegativeInfinityType:
def __repr__(self) -> str:
return "-Infinity"
def __hash__(self) -> int:
return hash(repr(self))
Reported by Pylint.
Line: 181
Column: 1
return self._key != other._key
class LegacyVersion(_BaseVersion):
def __init__(self, version: str) -> None:
self._version = str(version)
self._key = _legacy_cmpkey(self._version)
warnings.warn(
Reported by Pylint.
Line: 199
Column: 5
return f"<LegacyVersion('{self}')>"
@property
def public(self) -> str:
return self._version
@property
def base_version(self) -> str:
return self._version
Reported by Pylint.
Line: 203
Column: 5
return self._version
@property
def base_version(self) -> str:
return self._version
@property
def epoch(self) -> int:
return -1
Reported by Pylint.
Line: 207
Column: 5
return self._version
@property
def epoch(self) -> int:
return -1
@property
def release(self) -> None:
return None
Reported by Pylint.
Line: 211
Column: 5
return -1
@property
def release(self) -> None:
return None
@property
def pre(self) -> None:
return None
Reported by Pylint.
Line: 215
Column: 5
return None
@property
def pre(self) -> None:
return None
@property
def post(self) -> None:
return None
Reported by Pylint.
Line: 219
Column: 5
return None
@property
def post(self) -> None:
return None
@property
def dev(self) -> None:
return None
Reported by Pylint.
pandas/tests/indexes/datetimelike_/test_nat.py
33 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import (
DatetimeIndex,
NaT,
PeriodIndex,
TimedeltaIndex,
)
Reported by Pylint.
Line: 18
Column: 9
empty_index = index_without_na[:0]
index_with_na = index_without_na.copy(deep=True)
index_with_na._data[1] = NaT
assert type(index_without_na)._na_value is NaT
assert empty_index._na_value is NaT
assert index_with_na._na_value is NaT
assert index_without_na._na_value is NaT
Reported by Pylint.
Line: 20
Column: 16
index_with_na = index_without_na.copy(deep=True)
index_with_na._data[1] = NaT
assert type(index_without_na)._na_value is NaT
assert empty_index._na_value is NaT
assert index_with_na._na_value is NaT
assert index_without_na._na_value is NaT
idx = index_without_na
Reported by Pylint.
Line: 21
Column: 16
index_with_na._data[1] = NaT
assert type(index_without_na)._na_value is NaT
assert empty_index._na_value is NaT
assert index_with_na._na_value is NaT
assert index_without_na._na_value is NaT
idx = index_without_na
assert idx._can_hold_na
Reported by Pylint.
Line: 22
Column: 16
assert type(index_without_na)._na_value is NaT
assert empty_index._na_value is NaT
assert index_with_na._na_value is NaT
assert index_without_na._na_value is NaT
idx = index_without_na
assert idx._can_hold_na
Reported by Pylint.
Line: 23
Column: 16
assert type(index_without_na)._na_value is NaT
assert empty_index._na_value is NaT
assert index_with_na._na_value is NaT
assert index_without_na._na_value is NaT
idx = index_without_na
assert idx._can_hold_na
tm.assert_numpy_array_equal(idx._isnan, np.array([False, False]))
Reported by Pylint.
Line: 26
Column: 16
assert index_without_na._na_value is NaT
idx = index_without_na
assert idx._can_hold_na
tm.assert_numpy_array_equal(idx._isnan, np.array([False, False]))
assert idx.hasnans is False
idx = index_with_na
Reported by Pylint.
Line: 28
Column: 37
idx = index_without_na
assert idx._can_hold_na
tm.assert_numpy_array_equal(idx._isnan, np.array([False, False]))
assert idx.hasnans is False
idx = index_with_na
assert idx._can_hold_na
Reported by Pylint.
Line: 32
Column: 16
assert idx.hasnans is False
idx = index_with_na
assert idx._can_hold_na
tm.assert_numpy_array_equal(idx._isnan, np.array([False, True]))
assert idx.hasnans is True
Reported by Pylint.
Line: 34
Column: 37
idx = index_with_na
assert idx._can_hold_na
tm.assert_numpy_array_equal(idx._isnan, np.array([False, True]))
assert idx.hasnans is True
class TestDatetimeIndexNA(NATests):
@pytest.fixture
Reported by Pylint.
pandas/tests/indexing/multiindex/test_iloc.py
33 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import (
DataFrame,
MultiIndex,
Series,
)
import pandas._testing as tm
Reported by Pylint.
Line: 43
Column: 49
),
],
)
def test_iloc_returns_series(indexer, expected, simple_multiindex_dataframe):
df = simple_multiindex_dataframe
arr = df.values
result = indexer(df)
expected = expected(arr)
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 51
Column: 33
tm.assert_series_equal(result, expected)
def test_iloc_returns_dataframe(simple_multiindex_dataframe):
df = simple_multiindex_dataframe
result = df.iloc[[0, 1]]
expected = df.xs(4, drop_level=False)
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 58
Column: 30
tm.assert_frame_equal(result, expected)
def test_iloc_returns_scalar(simple_multiindex_dataframe):
df = simple_multiindex_dataframe
arr = df.values
result = df.iloc[2, 2]
expected = arr[2, 2]
assert result == expected
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import (
DataFrame,
MultiIndex,
Series,
)
import pandas._testing as tm
Reported by Pylint.
Line: 40
Column: 1
(
lambda df: df.iloc[:, 2],
lambda arr: Series(arr[:, 2], index=[[4, 4, 8], [8, 10, 12]], name=(4, 10)),
),
],
)
def test_iloc_returns_series(indexer, expected, simple_multiindex_dataframe):
df = simple_multiindex_dataframe
arr = df.values
Reported by Pylint.
Line: 44
Column: 5
],
)
def test_iloc_returns_series(indexer, expected, simple_multiindex_dataframe):
df = simple_multiindex_dataframe
arr = df.values
result = indexer(df)
expected = expected(arr)
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 51
Column: 1
tm.assert_series_equal(result, expected)
def test_iloc_returns_dataframe(simple_multiindex_dataframe):
df = simple_multiindex_dataframe
result = df.iloc[[0, 1]]
expected = df.xs(4, drop_level=False)
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 52
Column: 5
def test_iloc_returns_dataframe(simple_multiindex_dataframe):
df = simple_multiindex_dataframe
result = df.iloc[[0, 1]]
expected = df.xs(4, drop_level=False)
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 58
Column: 1
tm.assert_frame_equal(result, expected)
def test_iloc_returns_scalar(simple_multiindex_dataframe):
df = simple_multiindex_dataframe
arr = df.values
result = df.iloc[2, 2]
expected = arr[2, 2]
assert result == expected
Reported by Pylint.
pandas/tests/indexes/numeric/test_setops.py
33 issues
Line: 7
Column: 1
)
import numpy as np
import pytest
from pandas import (
Float64Index,
Index,
Int64Index,
Reported by Pylint.
Line: 31
Column: 16
def test_union_non_numeric(self, dtype):
# corner case, non-numeric
index = Index(np.arange(5, dtype=dtype), dtype=dtype)
assert index.dtype == dtype
other = Index([datetime.now() + timedelta(i) for i in range(4)], dtype=object)
result = index.union(other)
expected = Index(np.concatenate((index, other)))
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 91
Column: 60
result = string_index.difference(float_index)
tm.assert_index_equal(result, string_index)
def test_intersection_uint64_outside_int64_range(self, index_large):
other = Index([2 ** 63, 2 ** 63 + 5, 2 ** 63 + 10, 2 ** 63 + 15, 2 ** 63 + 20])
result = index_large.intersection(other)
expected = Index(np.sort(np.intersect1d(index_large.values, other.values)))
tm.assert_index_equal(result, expected)
Reported by Pylint.
Line: 158
Column: 3
@pytest.mark.xfail(reason="Not implemented")
@pytest.mark.parametrize("slice_", [slice(None), slice(0)])
def test_union_sort_special_true(self, slice_):
# TODO: decide on True behaviour
# sort=True
idx = Index([1, 0, 2])
# default, sort=None
other = idx[slice_]
Reported by Pylint.
Line: 1
Column: 1
from datetime import (
datetime,
timedelta,
)
import numpy as np
import pytest
from pandas import (
Reported by Pylint.
Line: 20
Column: 1
@pytest.fixture
def index_large():
# large values used in TestUInt64Index where no compat needed with Int64/Float64
large = [2 ** 63, 2 ** 63 + 10, 2 ** 63 + 15, 2 ** 63 + 20, 2 ** 63 + 25]
return UInt64Index(large)
Reported by Pylint.
Line: 26
Column: 1
return UInt64Index(large)
class TestSetOps:
@pytest.mark.parametrize("dtype", ["f8", "u8", "i8"])
def test_union_non_numeric(self, dtype):
# corner case, non-numeric
index = Index(np.arange(5, dtype=dtype), dtype=dtype)
assert index.dtype == dtype
Reported by Pylint.
Line: 28
Column: 5
class TestSetOps:
@pytest.mark.parametrize("dtype", ["f8", "u8", "i8"])
def test_union_non_numeric(self, dtype):
# corner case, non-numeric
index = Index(np.arange(5, dtype=dtype), dtype=dtype)
assert index.dtype == dtype
other = Index([datetime.now() + timedelta(i) for i in range(4)], dtype=object)
Reported by Pylint.
Line: 28
Column: 5
class TestSetOps:
@pytest.mark.parametrize("dtype", ["f8", "u8", "i8"])
def test_union_non_numeric(self, dtype):
# corner case, non-numeric
index = Index(np.arange(5, dtype=dtype), dtype=dtype)
assert index.dtype == dtype
other = Index([datetime.now() + timedelta(i) for i in range(4)], dtype=object)
Reported by Pylint.
Line: 31
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_union_non_numeric(self, dtype):
# corner case, non-numeric
index = Index(np.arange(5, dtype=dtype), dtype=dtype)
assert index.dtype == dtype
other = Index([datetime.now() + timedelta(i) for i in range(4)], dtype=object)
result = index.union(other)
expected = Index(np.concatenate((index, other)))
tm.assert_index_equal(result, expected)
Reported by Bandit.
pandas/tests/apply/test_frame_transform.py
33 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import (
DataFrame,
MultiIndex,
Series,
)
import pandas._testing as tm
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import (
DataFrame,
MultiIndex,
Series,
)
import pandas._testing as tm
Reported by Pylint.
Line: 26
Column: 1
return obj
def test_transform_ufunc(axis, float_frame, frame_or_series):
# GH 35964
obj = unpack_obj(float_frame, frame_or_series, axis)
with np.errstate(all="ignore"):
f_sqrt = np.sqrt(obj)
Reported by Pylint.
Line: 46
Column: 1
([np.abs, np.sqrt], ["absolute", "sqrt"]),
(np.array([np.sqrt]), ["sqrt"]),
(np.array([np.abs, np.sqrt]), ["absolute", "sqrt"]),
],
)
def test_transform_listlike(axis, float_frame, ops, names):
# GH 35964
other_axis = 1 if axis in {0, "index"} else 0
with np.errstate(all="ignore"):
Reported by Pylint.
Line: 62
Column: 1
@pytest.mark.parametrize("ops", [[], np.array([])])
def test_transform_empty_listlike(float_frame, ops, frame_or_series):
obj = unpack_obj(float_frame, frame_or_series, 0)
with pytest.raises(ValueError, match="No transform functions were provided"):
obj.transform(ops)
Reported by Pylint.
Line: 70
Column: 1
@pytest.mark.parametrize("box", [dict, Series])
def test_transform_dictlike(axis, float_frame, box):
# GH 35964
if axis == 0 or axis == "index":
e = float_frame.columns[0]
expected = float_frame[[e]].transform(np.abs)
else:
Reported by Pylint.
Line: 72
Column: 8
@pytest.mark.parametrize("box", [dict, Series])
def test_transform_dictlike(axis, float_frame, box):
# GH 35964
if axis == 0 or axis == "index":
e = float_frame.columns[0]
expected = float_frame[[e]].transform(np.abs)
else:
e = float_frame.index[0]
expected = float_frame.iloc[[0]].transform(np.abs)
Reported by Pylint.
Line: 73
Column: 9
def test_transform_dictlike(axis, float_frame, box):
# GH 35964
if axis == 0 or axis == "index":
e = float_frame.columns[0]
expected = float_frame[[e]].transform(np.abs)
else:
e = float_frame.index[0]
expected = float_frame.iloc[[0]].transform(np.abs)
result = float_frame.transform(box({e: np.abs}), axis=axis)
Reported by Pylint.
Line: 76
Column: 9
e = float_frame.columns[0]
expected = float_frame[[e]].transform(np.abs)
else:
e = float_frame.index[0]
expected = float_frame.iloc[[0]].transform(np.abs)
result = float_frame.transform(box({e: np.abs}), axis=axis)
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 82
Column: 1
tm.assert_frame_equal(result, expected)
def test_transform_dictlike_mixed():
# GH 40018 - mix of lists and non-lists in values of a dictionary
df = DataFrame({"a": [1, 2], "b": [1, 4], "c": [1, 4]})
result = df.transform({"b": ["sqrt", "abs"], "c": "sqrt"})
expected = DataFrame(
[[1.0, 1, 1.0], [2.0, 4, 2.0]],
Reported by Pylint.
pandas/tests/frame/test_ufunc.py
33 issues
Line: 4
Column: 1
from functools import partial
import numpy as np
import pytest
import pandas.util._test_decorators as td
import pandas as pd
import pandas._testing as tm
Reported by Pylint.
Line: 259
Column: 5
# https://github.com/pandas-dev/pandas/issues/39184
# test that the deprecation also works with > 2 inputs -> using a numba
# written ufunc for this because numpy itself doesn't have such ufuncs
from numba import (
float64,
vectorize,
)
@vectorize([float64(float64, float64, float64)])
Reported by Pylint.
Line: 83
Column: 49
),
],
)
def test_ufunc_passes_args(func, arg, expected, request):
# GH#40662
arr = np.array([[1, 2], [3, 4]])
df = pd.DataFrame(arr)
result_inplace = np.zeros_like(arr)
# 1-argument ufunc
Reported by Pylint.
Line: 155
Column: 5
# np.array([[1, 3], [3, 4], [np.nan, np.nan]]),
# np.array([[1, 3], [np.nan, np.nan], [3, 4]]),
# )
# # TODO(FloatArray): this will be Float64Dtype.
# expected = pd.DataFrame(expected, index=["a", "b", "c"], columns=["A", "B"])
expected = pd.DataFrame(
[[1.0, 1.0], [1.0, 1.0]], columns=["A", "B"], index=["a", "b"]
)
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 1
Column: 1
from functools import partial
import numpy as np
import pytest
import pandas.util._test_decorators as td
import pandas as pd
import pandas._testing as tm
Reported by Pylint.
Line: 20
Column: 1
@pytest.mark.parametrize("dtype", dtypes)
def test_unary_unary(dtype):
# unary input, unary output
values = np.array([[-1, -1], [1, 1]], dtype="int64")
df = pd.DataFrame(values, columns=["A", "B"], index=["a", "b"]).astype(dtype=dtype)
result = np.positive(df)
expected = pd.DataFrame(
Reported by Pylint.
Line: 23
Column: 5
def test_unary_unary(dtype):
# unary input, unary output
values = np.array([[-1, -1], [1, 1]], dtype="int64")
df = pd.DataFrame(values, columns=["A", "B"], index=["a", "b"]).astype(dtype=dtype)
result = np.positive(df)
expected = pd.DataFrame(
np.positive(values), index=df.index, columns=df.columns
).astype(dtype)
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 32
Column: 1
@pytest.mark.parametrize("dtype", dtypes)
def test_unary_binary(request, dtype):
# unary input, binary output
if is_extension_array_dtype(dtype) or isinstance(dtype, dict):
request.node.add_marker(
pytest.mark.xfail(
reason="Extension / mixed with multiple outputs not implemented."
Reported by Pylint.
Line: 42
Column: 5
)
values = np.array([[-1, -1], [1, 1]], dtype="int64")
df = pd.DataFrame(values, columns=["A", "B"], index=["a", "b"]).astype(dtype=dtype)
result_pandas = np.modf(df)
assert isinstance(result_pandas, tuple)
assert len(result_pandas) == 2
expected_numpy = np.modf(values)
Reported by Pylint.
Line: 44
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
values = np.array([[-1, -1], [1, 1]], dtype="int64")
df = pd.DataFrame(values, columns=["A", "B"], index=["a", "b"]).astype(dtype=dtype)
result_pandas = np.modf(df)
assert isinstance(result_pandas, tuple)
assert len(result_pandas) == 2
expected_numpy = np.modf(values)
for result, b in zip(result_pandas, expected_numpy):
expected = pd.DataFrame(b, index=df.index, columns=df.columns)
Reported by Bandit.
pandas/tests/frame/methods/test_filter.py
33 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import DataFrame
import pandas._testing as tm
class TestDataFrameFilter:
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import DataFrame
import pandas._testing as tm
class TestDataFrameFilter:
Reported by Pylint.
Line: 9
Column: 1
import pandas._testing as tm
class TestDataFrameFilter:
def test_filter(self, float_frame, float_string_frame):
# Items
filtered = float_frame.filter(["A", "B", "E"])
assert len(filtered.columns) == 2
assert "E" not in filtered
Reported by Pylint.
Line: 10
Column: 5
class TestDataFrameFilter:
def test_filter(self, float_frame, float_string_frame):
# Items
filtered = float_frame.filter(["A", "B", "E"])
assert len(filtered.columns) == 2
assert "E" not in filtered
Reported by Pylint.
Line: 10
Column: 5
class TestDataFrameFilter:
def test_filter(self, float_frame, float_string_frame):
# Items
filtered = float_frame.filter(["A", "B", "E"])
assert len(filtered.columns) == 2
assert "E" not in filtered
Reported by Pylint.
Line: 13
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
def test_filter(self, float_frame, float_string_frame):
# Items
filtered = float_frame.filter(["A", "B", "E"])
assert len(filtered.columns) == 2
assert "E" not in filtered
filtered = float_frame.filter(["A", "B", "E"], axis="columns")
assert len(filtered.columns) == 2
assert "E" not in filtered
Reported by Bandit.
Line: 14
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
# Items
filtered = float_frame.filter(["A", "B", "E"])
assert len(filtered.columns) == 2
assert "E" not in filtered
filtered = float_frame.filter(["A", "B", "E"], axis="columns")
assert len(filtered.columns) == 2
assert "E" not in filtered
Reported by Bandit.
Line: 17
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
assert "E" not in filtered
filtered = float_frame.filter(["A", "B", "E"], axis="columns")
assert len(filtered.columns) == 2
assert "E" not in filtered
# Other axis
idx = float_frame.index[0:4]
filtered = float_frame.filter(idx, axis="index")
Reported by Bandit.
Line: 18
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
filtered = float_frame.filter(["A", "B", "E"], axis="columns")
assert len(filtered.columns) == 2
assert "E" not in filtered
# Other axis
idx = float_frame.index[0:4]
filtered = float_frame.filter(idx, axis="index")
expected = float_frame.reindex(index=idx)
Reported by Bandit.
Line: 31
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
fcopy["AA"] = 1
filtered = fcopy.filter(like="A")
assert len(filtered.columns) == 2
assert "AA" in filtered
# like with ints in column names
df = DataFrame(0.0, index=[0, 1, 2], columns=[0, 1, "_A", "_B"])
filtered = df.filter(like="_")
Reported by Bandit.
pandas/io/excel/_odfreader.py
32 issues
Line: 39
Column: 9
@property
def _workbook_class(self):
from odf.opendocument import OpenDocument
return OpenDocument
def load_workbook(self, filepath_or_buffer: FilePathOrBuffer):
from odf.opendocument import load
Reported by Pylint.
Line: 44
Column: 9
return OpenDocument
def load_workbook(self, filepath_or_buffer: FilePathOrBuffer):
from odf.opendocument import load
return load(filepath_or_buffer)
@property
def empty_value(self) -> str:
Reported by Pylint.
Line: 56
Column: 9
@property
def sheet_names(self) -> list[str]:
"""Return a list of sheet names present in the document"""
from odf.table import Table
tables = self.book.getElementsByType(Table)
return [t.getAttribute("name") for t in tables]
def get_sheet_by_index(self, index: int):
Reported by Pylint.
Line: 62
Column: 9
return [t.getAttribute("name") for t in tables]
def get_sheet_by_index(self, index: int):
from odf.table import Table
self.raise_if_bad_sheet_by_index(index)
tables = self.book.getElementsByType(Table)
return tables[index]
Reported by Pylint.
Line: 69
Column: 9
return tables[index]
def get_sheet_by_name(self, name: str):
from odf.table import Table
self.raise_if_bad_sheet_by_name(name)
tables = self.book.getElementsByType(Table)
for table in tables:
Reported by Pylint.
Line: 85
Column: 9
"""
Parse an ODF Table into a list of lists
"""
from odf.table import (
CoveredTableCell,
TableCell,
TableRow,
)
Reported by Pylint.
Line: 148
Column: 9
Repeating an empty row appeared to be a common way
of representing sparse rows in the table.
"""
from odf.namespaces import TABLENS
return int(row.attributes.get((TABLENS, "number-rows-repeated"), 1))
def _get_column_repeat(self, cell) -> int:
from odf.namespaces import TABLENS
Reported by Pylint.
Line: 153
Column: 9
return int(row.attributes.get((TABLENS, "number-rows-repeated"), 1))
def _get_column_repeat(self, cell) -> int:
from odf.namespaces import TABLENS
return int(cell.attributes.get((TABLENS, "number-columns-repeated"), 1))
def _is_empty_row(self, row) -> bool:
"""
Reported by Pylint.
Line: 168
Column: 9
return True
def _get_cell_value(self, cell, convert_float: bool) -> Scalar:
from odf.namespaces import OFFICENS
if str(cell) == "#N/A":
return np.nan
cell_type = cell.attributes.get((OFFICENS, "value-type"))
Reported by Pylint.
Line: 212
Column: 9
Find and decode OpenDocument text:s tags that represent
a run length encoded sequence of space characters.
"""
from odf.element import Element
from odf.namespaces import TEXTNS
from odf.text import S
text_s = S().qname
Reported by Pylint.
pandas/io/common.py
32 issues
Line: 212
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b310-urllib-urlopen
"""
import urllib.request
return urllib.request.urlopen(*args, **kwargs)
def is_fsspec_url(url: FilePathOrBuffer) -> bool:
"""
Returns true if the given URL looks like
Reported by Bandit.
Line: 301
Column: 3
fsspec_mode += "b"
if isinstance(filepath_or_buffer, str) and is_url(filepath_or_buffer):
# TODO: fsspec can also handle HTTP via requests, but leaving this
# unchanged. using fsspec appears to break the ability to infer if the
# server responded with gzipped data
storage_options = storage_options or {}
# waiting until now for importing to match intended lazy logic of
Reported by Pylint.
Line: 798
Column: 5
# _PathLike[str]], IO[bytes]]"
super().__init__(file, mode, **kwargs_zip) # type: ignore[arg-type]
def write(self, data):
# buffer multiple write calls, write on flush
if self.multiple_write_buffer is None:
self.multiple_write_buffer = (
BytesIO() if isinstance(data, bytes) else StringIO()
)
Reported by Pylint.
Line: 896
Column: 5
class BytesIOWrapper(io.BytesIO):
buffer: StringIO | TextIOBase | None
def __init__(self, buffer: StringIO | TextIOBase, encoding: str = "utf-8"):
self.buffer = buffer
self.encoding = encoding
# Because a character can be represented by more than 1 byte,
# it is possible that reading will produce more bytes than n
# We store the extra bytes in this overflow variable, and append the
Reported by Pylint.
Line: 966
Column: 12
handles.remove(handle)
handles.append(wrapped)
handle = wrapped
except Exception:
# we catch any errors that may have occurred
# because that is consistent with the lower-level
# functionality of the C engine (pd.read_csv), so
# leave the file handler as is then
memory_map = False
Reported by Pylint.
Line: 1
Column: 1
"""Common IO api utilities"""
from __future__ import annotations
import bz2
import codecs
from collections import abc
import dataclasses
import gzip
import io
Reported by Pylint.
Line: 106
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
avoid closing the potentially user-created buffer.
"""
if self.is_wrapped:
assert isinstance(self.handle, (TextIOWrapper, BytesIOWrapper))
self.handle.flush()
self.handle.detach()
self.created_handles.remove(self.handle)
try:
for handle in self.created_handles:
Reported by Bandit.
Line: 162
Column: 1
return filepath_or_buffer
def validate_header_arg(header) -> None:
if isinstance(header, bool):
raise TypeError(
"Passing a bool to header is invalid. Use header=None for no header or "
"header=int or list-like of ints to specify "
"the row(s) making up the column names"
Reported by Pylint.
Line: 210
Column: 5
Lazy-import wrapper for stdlib urlopen, as that imports a big chunk of
the stdlib.
"""
import urllib.request
return urllib.request.urlopen(*args, **kwargs)
def is_fsspec_url(url: FilePathOrBuffer) -> bool:
Reported by Pylint.
Line: 227
Column: 1
)
def _get_filepath_or_buffer(
filepath_or_buffer: FilePathOrBuffer,
encoding: str = "utf-8",
compression: CompressionOptions = None,
mode: str = "r",
storage_options: StorageOptions = None,
Reported by Pylint.