The following issues were found
asv_bench/benchmarks/tslibs/tslib.py
9 issues
Line: 28
Column: 1
tzlocal,
)
import numpy as np
import pytz
try:
from pandas._libs.tslibs import ints_to_pydatetime
except ImportError:
from pandas._libs.tslib import ints_to_pydatetime
Reported by Pylint.
Line: 54
Column: 3
_tzs,
)
param_names = ["box", "size", "tz"]
# TODO: fold? freq?
def setup(self, box, size, tz):
if box == "date" and tz is not None:
# tz is ignored, so avoid running redundant benchmarks
raise NotImplementedError # skip benchmark
Reported by Pylint.
Line: 65
Column: 9
raise NotImplementedError # skip benchmark
arr = np.random.randint(0, 10, size=size, dtype="i8")
self.i8data = arr
def time_ints_to_pydatetime(self, box, size, tz):
ints_to_pydatetime(self.i8data, tz, box=box)
Reported by Pylint.
Line: 67
Column: 44
arr = np.random.randint(0, 10, size=size, dtype="i8")
self.i8data = arr
def time_ints_to_pydatetime(self, box, size, tz):
ints_to_pydatetime(self.i8data, tz, box=box)
Reported by Pylint.
Line: 47
Column: 1
_sizes = [0, 1, 100, 10 ** 4, 10 ** 6]
class TimeIntsToPydatetime:
params = (
["time", "date", "datetime", "timestamp"],
_sizes,
_tzs,
)
Reported by Pylint.
Line: 56
Column: 5
param_names = ["box", "size", "tz"]
# TODO: fold? freq?
def setup(self, box, size, tz):
if box == "date" and tz is not None:
# tz is ignored, so avoid running redundant benchmarks
raise NotImplementedError # skip benchmark
if size == 10 ** 6 and tz is _tzs[-1]:
# This is cumbersomely-slow, so skip to trim runtime
Reported by Pylint.
Line: 56
Column: 5
param_names = ["box", "size", "tz"]
# TODO: fold? freq?
def setup(self, box, size, tz):
if box == "date" and tz is not None:
# tz is ignored, so avoid running redundant benchmarks
raise NotImplementedError # skip benchmark
if size == 10 ** 6 and tz is _tzs[-1]:
# This is cumbersomely-slow, so skip to trim runtime
Reported by Pylint.
Line: 67
Column: 5
arr = np.random.randint(0, 10, size=size, dtype="i8")
self.i8data = arr
def time_ints_to_pydatetime(self, box, size, tz):
ints_to_pydatetime(self.i8data, tz, box=box)
Reported by Pylint.
Line: 67
Column: 5
arr = np.random.randint(0, 10, size=size, dtype="i8")
self.i8data = arr
def time_ints_to_pydatetime(self, box, size, tz):
ints_to_pydatetime(self.i8data, tz, box=box)
Reported by Pylint.
asv_bench/benchmarks/tslibs/resolution.py
9 issues
Line: 27
Column: 1
except ImportError:
from pandas._libs.tslibs.resolution import get_resolution
from .tslib import (
_sizes,
_tzs,
tzlocal_obj,
)
Reported by Pylint.
Line: 49
Column: 9
arr = np.random.randint(0, 10, size=size, dtype="i8")
arr = arr.view(f"M8[{unit}]").astype("M8[ns]").view("i8")
self.i8data = arr
def time_get_resolution(self, unit, size, tz):
get_resolution(self.i8data, tz)
Reported by Pylint.
Line: 51
Column: 35
arr = arr.view(f"M8[{unit}]").astype("M8[ns]").view("i8")
self.i8data = arr
def time_get_resolution(self, unit, size, tz):
get_resolution(self.i8data, tz)
Reported by Pylint.
Line: 51
Column: 41
arr = arr.view(f"M8[{unit}]").astype("M8[ns]").view("i8")
self.i8data = arr
def time_get_resolution(self, unit, size, tz):
get_resolution(self.i8data, tz)
Reported by Pylint.
Line: 34
Column: 1
)
class TimeResolution:
params = (
["D", "h", "m", "s", "us", "ns"],
_sizes,
_tzs,
)
Reported by Pylint.
Line: 42
Column: 5
)
param_names = ["unit", "size", "tz"]
def setup(self, unit, size, tz):
if size == 10 ** 6 and tz is tzlocal_obj:
# tzlocal is cumbersomely slow, so skip to keep runtime in check
raise NotImplementedError
arr = np.random.randint(0, 10, size=size, dtype="i8")
Reported by Pylint.
Line: 42
Column: 5
)
param_names = ["unit", "size", "tz"]
def setup(self, unit, size, tz):
if size == 10 ** 6 and tz is tzlocal_obj:
# tzlocal is cumbersomely slow, so skip to keep runtime in check
raise NotImplementedError
arr = np.random.randint(0, 10, size=size, dtype="i8")
Reported by Pylint.
Line: 51
Column: 5
arr = arr.view(f"M8[{unit}]").astype("M8[ns]").view("i8")
self.i8data = arr
def time_get_resolution(self, unit, size, tz):
get_resolution(self.i8data, tz)
Reported by Pylint.
Line: 51
Column: 5
arr = arr.view(f"M8[{unit}]").astype("M8[ns]").view("i8")
self.i8data = arr
def time_get_resolution(self, unit, size, tz):
get_resolution(self.i8data, tz)
Reported by Pylint.
asv_bench/benchmarks/io/sas.py
9 issues
Line: 3
Column: 1
import os
from pandas import read_sas
class SAS:
params = ["sas7bdat", "xport"]
param_names = ["format"]
Reported by Pylint.
Line: 11
Column: 21
params = ["sas7bdat", "xport"]
param_names = ["format"]
def setup(self, format):
# Read files that are located in 'pandas/tests/io/sas/data'
files = {"sas7bdat": "test1.sas7bdat", "xport": "paxraw_d_short.xpt"}
file = files[format]
paths = [
os.path.dirname(__file__),
Reported by Pylint.
Line: 27
Column: 9
"data",
file,
]
self.f = os.path.join(*paths)
def time_read_sas(self, format):
read_sas(self.f, format=format)
Reported by Pylint.
Line: 29
Column: 29
]
self.f = os.path.join(*paths)
def time_read_sas(self, format):
read_sas(self.f, format=format)
Reported by Pylint.
Line: 1
Column: 1
import os
from pandas import read_sas
class SAS:
params = ["sas7bdat", "xport"]
param_names = ["format"]
Reported by Pylint.
Line: 6
Column: 1
from pandas import read_sas
class SAS:
params = ["sas7bdat", "xport"]
param_names = ["format"]
def setup(self, format):
Reported by Pylint.
Line: 11
Column: 5
params = ["sas7bdat", "xport"]
param_names = ["format"]
def setup(self, format):
# Read files that are located in 'pandas/tests/io/sas/data'
files = {"sas7bdat": "test1.sas7bdat", "xport": "paxraw_d_short.xpt"}
file = files[format]
paths = [
os.path.dirname(__file__),
Reported by Pylint.
Line: 27
Column: 9
"data",
file,
]
self.f = os.path.join(*paths)
def time_read_sas(self, format):
read_sas(self.f, format=format)
Reported by Pylint.
Line: 29
Column: 5
]
self.f = os.path.join(*paths)
def time_read_sas(self, format):
read_sas(self.f, format=format)
Reported by Pylint.
pandas/tests/io/pytables/common.py
9 issues
Line: 5
Column: 1
import os
import tempfile
import pytest
from pandas.io.pytables import HDFStore
tables = pytest.importorskip("tables")
# set these parameters so we don't have file sharing
Reported by Pylint.
Line: 39
Column: 70
# contextmanager to ensure the file cleanup
@contextmanager
def ensure_clean_store(path, mode="a", complevel=None, complib=None, fletcher32=False):
try:
# put in the temporary path if we don't have one already
if not len(os.path.dirname(path)):
Reported by Pylint.
Line: 1
Column: 1
from contextlib import contextmanager
import os
import tempfile
import pytest
from pandas.io.pytables import HDFStore
tables = pytest.importorskip("tables")
Reported by Pylint.
Line: 16
Column: 1
tables.parameters.MAX_THREADS = 1
def safe_remove(path):
if path is not None:
try:
os.remove(path) # noqa: PDF008
except OSError:
pass
Reported by Pylint.
Line: 24
Column: 1
pass
def safe_close(store):
try:
if store is not None:
store.close()
except OSError:
pass
Reported by Pylint.
Line: 39
Column: 1
# contextmanager to ensure the file cleanup
@contextmanager
def ensure_clean_store(path, mode="a", complevel=None, complib=None, fletcher32=False):
try:
# put in the temporary path if we don't have one already
if not len(os.path.dirname(path)):
Reported by Pylint.
Line: 44
Column: 12
try:
# put in the temporary path if we don't have one already
if not len(os.path.dirname(path)):
path = create_tempfile(path)
store = HDFStore(
path, mode=mode, complevel=complevel, complib=complib, fletcher32=False
)
Reported by Pylint.
Line: 53
Column: 12
yield store
finally:
safe_close(store)
if mode == "w" or mode == "a":
safe_remove(path)
@contextmanager
def ensure_clean_path(path):
Reported by Pylint.
Line: 72
Column: 13
filenames = [create_tempfile(path)]
yield filenames[0]
finally:
for f in filenames:
safe_remove(f)
def _maybe_remove(store, key):
"""
Reported by Pylint.
pandas/tests/io/parser/test_comment.py
9 issues
Line: 8
Column: 1
from io import StringIO
import numpy as np
import pytest
from pandas import DataFrame
import pandas._testing as tm
Reported by Pylint.
Line: 15
Column: 1
@pytest.mark.parametrize("na_values", [None, ["NaN"]])
def test_comment(all_parsers, na_values):
parser = all_parsers
data = """A,B,C
1,2.,4.#hello world
5.,NaN,10.0
"""
Reported by Pylint.
Line: 30
Column: 1
@pytest.mark.parametrize(
"read_kwargs", [{}, {"lineterminator": "*"}, {"delim_whitespace": True}]
)
def test_line_comment(all_parsers, read_kwargs):
parser = all_parsers
data = """# empty
A,B,C
1,2.,4.#hello world
Reported by Pylint.
Line: 56
Column: 1
tm.assert_frame_equal(result, expected)
def test_comment_skiprows(all_parsers):
parser = all_parsers
data = """# empty
random line
# second empty line
1,2,3
Reported by Pylint.
Line: 74
Column: 1
tm.assert_frame_equal(result, expected)
def test_comment_header(all_parsers):
parser = all_parsers
data = """# empty
# second empty line
1,2,3
A,B,C
Reported by Pylint.
Line: 91
Column: 1
tm.assert_frame_equal(result, expected)
def test_comment_skiprows_header(all_parsers):
parser = all_parsers
data = """# empty
# second empty line
# third empty line
X,Y,Z
Reported by Pylint.
Line: 113
Column: 1
@pytest.mark.parametrize("comment_char", ["#", "~", "&", "^", "*", "@"])
def test_custom_comment_char(all_parsers, comment_char):
parser = all_parsers
data = "a,b,c\n1,2,3#ignore this!\n4,5,6#ignorethistoo"
result = parser.read_csv(
StringIO(data.replace("#", comment_char)), comment=comment_char
)
Reported by Pylint.
Line: 125
Column: 1
@pytest.mark.parametrize("header", ["infer", None])
def test_comment_first_line(all_parsers, header):
# see gh-4623
parser = all_parsers
data = "# notes\na,b,c\n# more notes\n1,2,3"
if header is None:
Reported by Pylint.
Line: 139
Column: 1
tm.assert_frame_equal(result, expected)
def test_comment_char_in_default_value(all_parsers, request):
# GH#34002
if all_parsers.engine == "c":
reason = "see gh-34002: works on the python engine but not the c engine"
# NA value containing comment char is interpreted as comment
request.node.add_marker(pytest.mark.xfail(reason=reason, raises=AssertionError))
Reported by Pylint.
pandas/tests/util/test_validate_kwargs.py
9 issues
Line: 1
Column: 1
import pytest
from pandas.util._validators import (
validate_bool_kwarg,
validate_kwargs,
)
_fname = "func"
Reported by Pylint.
Line: 1
Column: 1
import pytest
from pandas.util._validators import (
validate_bool_kwarg,
validate_kwargs,
)
_fname = "func"
Reported by Pylint.
Line: 8
Column: 1
validate_kwargs,
)
_fname = "func"
def test_bad_kwarg():
good_arg = "f"
bad_arg = good_arg + "o"
Reported by Pylint.
Line: 11
Column: 1
_fname = "func"
def test_bad_kwarg():
good_arg = "f"
bad_arg = good_arg + "o"
compat_args = {good_arg: "foo", bad_arg + "o": "bar"}
kwargs = {good_arg: "foo", bad_arg: "bar"}
Reported by Pylint.
Line: 25
Column: 1
@pytest.mark.parametrize("i", range(1, 3))
def test_not_all_none(i):
bad_arg = "foo"
msg = (
fr"the '{bad_arg}' parameter is not supported "
fr"in the pandas implementation of {_fname}\(\)"
)
Reported by Pylint.
Line: 43
Column: 1
validate_kwargs(_fname, kwargs, compat_args)
def test_validation():
# No exceptions should be raised.
compat_args = {"f": None, "b": 1, "ba": "s"}
kwargs = {"f": None, "b": 1}
validate_kwargs(_fname, kwargs, compat_args)
Reported by Pylint.
Line: 53
Column: 1
@pytest.mark.parametrize("name", ["inplace", "copy"])
@pytest.mark.parametrize("value", [1, "True", [1, 2, 3], 5.0])
def test_validate_bool_kwarg_fail(name, value):
msg = (
f'For argument "{name}" expected type bool, '
f"received type {type(value).__name__}"
)
Reported by Pylint.
Line: 65
Column: 1
@pytest.mark.parametrize("name", ["inplace", "copy"])
@pytest.mark.parametrize("value", [True, False, None])
def test_validate_bool_kwarg(name, value):
assert validate_bool_kwarg(value, name) == value
Reported by Pylint.
Line: 66
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
@pytest.mark.parametrize("name", ["inplace", "copy"])
@pytest.mark.parametrize("value", [True, False, None])
def test_validate_bool_kwarg(name, value):
assert validate_bool_kwarg(value, name) == value
Reported by Bandit.
pandas/tseries/offsets.py
9 issues
Line: 1
Column: 1
from pandas._libs.tslibs.offsets import ( # noqa:F401
FY5253,
BaseOffset,
BDay,
BMonthBegin,
BMonthEnd,
BQuarterBegin,
BQuarterEnd,
BusinessDay,
Reported by Pylint.
Line: 1
Column: 1
from pandas._libs.tslibs.offsets import ( # noqa:F401
FY5253,
BaseOffset,
BDay,
BMonthBegin,
BMonthEnd,
BQuarterBegin,
BQuarterEnd,
BusinessDay,
Reported by Pylint.
Line: 1
Column: 1
from pandas._libs.tslibs.offsets import ( # noqa:F401
FY5253,
BaseOffset,
BDay,
BMonthBegin,
BMonthEnd,
BQuarterBegin,
BQuarterEnd,
BusinessDay,
Reported by Pylint.
Line: 1
Column: 1
from pandas._libs.tslibs.offsets import ( # noqa:F401
FY5253,
BaseOffset,
BDay,
BMonthBegin,
BMonthEnd,
BQuarterBegin,
BQuarterEnd,
BusinessDay,
Reported by Pylint.
Line: 1
Column: 1
from pandas._libs.tslibs.offsets import ( # noqa:F401
FY5253,
BaseOffset,
BDay,
BMonthBegin,
BMonthEnd,
BQuarterBegin,
BQuarterEnd,
BusinessDay,
Reported by Pylint.
Line: 1
Column: 1
from pandas._libs.tslibs.offsets import ( # noqa:F401
FY5253,
BaseOffset,
BDay,
BMonthBegin,
BMonthEnd,
BQuarterBegin,
BQuarterEnd,
BusinessDay,
Reported by Pylint.
Line: 1
Column: 1
from pandas._libs.tslibs.offsets import ( # noqa:F401
FY5253,
BaseOffset,
BDay,
BMonthBegin,
BMonthEnd,
BQuarterBegin,
BQuarterEnd,
BusinessDay,
Reported by Pylint.
Line: 1
Column: 1
from pandas._libs.tslibs.offsets import ( # noqa:F401
FY5253,
BaseOffset,
BDay,
BMonthBegin,
BMonthEnd,
BQuarterBegin,
BQuarterEnd,
BusinessDay,
Reported by Pylint.
Line: 1
Column: 1
from pandas._libs.tslibs.offsets import ( # noqa:F401
FY5253,
BaseOffset,
BDay,
BMonthBegin,
BMonthEnd,
BQuarterBegin,
BQuarterEnd,
BusinessDay,
Reported by Pylint.
pandas/tests/series/methods/test_matmul.py
9 issues
Line: 4
Column: 1
import operator
import numpy as np
import pytest
from pandas import (
DataFrame,
Series,
)
Reported by Pylint.
Line: 1
Column: 1
import operator
import numpy as np
import pytest
from pandas import (
DataFrame,
Series,
)
Reported by Pylint.
Line: 13
Column: 1
import pandas._testing as tm
class TestMatmul:
def test_matmul(self):
# matmul test is for GH#10259
a = Series(np.random.randn(4), index=["p", "q", "r", "s"])
b = DataFrame(
np.random.randn(3, 4), index=["1", "2", "3"], columns=["p", "q", "r", "s"]
Reported by Pylint.
Line: 13
Column: 1
import pandas._testing as tm
class TestMatmul:
def test_matmul(self):
# matmul test is for GH#10259
a = Series(np.random.randn(4), index=["p", "q", "r", "s"])
b = DataFrame(
np.random.randn(3, 4), index=["1", "2", "3"], columns=["p", "q", "r", "s"]
Reported by Pylint.
Line: 14
Column: 5
class TestMatmul:
def test_matmul(self):
# matmul test is for GH#10259
a = Series(np.random.randn(4), index=["p", "q", "r", "s"])
b = DataFrame(
np.random.randn(3, 4), index=["1", "2", "3"], columns=["p", "q", "r", "s"]
).T
Reported by Pylint.
Line: 14
Column: 5
class TestMatmul:
def test_matmul(self):
# matmul test is for GH#10259
a = Series(np.random.randn(4), index=["p", "q", "r", "s"])
b = DataFrame(
np.random.randn(3, 4), index=["1", "2", "3"], columns=["p", "q", "r", "s"]
).T
Reported by Pylint.
Line: 16
Column: 9
class TestMatmul:
def test_matmul(self):
# matmul test is for GH#10259
a = Series(np.random.randn(4), index=["p", "q", "r", "s"])
b = DataFrame(
np.random.randn(3, 4), index=["1", "2", "3"], columns=["p", "q", "r", "s"]
).T
# Series @ DataFrame -> Series
Reported by Pylint.
Line: 17
Column: 9
def test_matmul(self):
# matmul test is for GH#10259
a = Series(np.random.randn(4), index=["p", "q", "r", "s"])
b = DataFrame(
np.random.randn(3, 4), index=["1", "2", "3"], columns=["p", "q", "r", "s"]
).T
# Series @ DataFrame -> Series
result = operator.matmul(a, b)
Reported by Pylint.
Line: 67
Column: 9
tm.assert_series_equal(result, expected)
# different dtypes DataFrame @ Series
a = a.astype(int)
result = operator.matmul(b.T, a)
expected = Series(np.dot(b.T.values, a.T.values), index=["1", "2", "3"])
tm.assert_series_equal(result, expected)
msg = r"Dot product shape mismatch, \(4,\) vs \(3,\)"
Reported by Pylint.
pandas/tests/series/methods/test_view.py
9 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas import (
Index,
Series,
array,
date_range,
)
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas import (
Index,
Series,
array,
date_range,
)
Reported by Pylint.
Line: 13
Column: 1
import pandas._testing as tm
class TestView:
def test_view_tz(self):
# GH#24024
ser = Series(date_range("2000", periods=4, tz="US/Central"))
result = ser.view("i8")
expected = Series(
Reported by Pylint.
Line: 14
Column: 5
class TestView:
def test_view_tz(self):
# GH#24024
ser = Series(date_range("2000", periods=4, tz="US/Central"))
result = ser.view("i8")
expected = Series(
[
Reported by Pylint.
Line: 14
Column: 5
class TestView:
def test_view_tz(self):
# GH#24024
ser = Series(date_range("2000", periods=4, tz="US/Central"))
result = ser.view("i8")
expected = Series(
[
Reported by Pylint.
Line: 33
Column: 5
)
@pytest.mark.parametrize(
"second", ["m8[ns]", "M8[ns]", "M8[ns, US/Central]", "period[D]"]
)
@pytest.mark.parametrize("box", [Series, Index, array])
def test_view_between_datetimelike(self, first, second, box):
dti = date_range("2016-01-01", periods=3)
Reported by Pylint.
Line: 33
Column: 5
)
@pytest.mark.parametrize(
"second", ["m8[ns]", "M8[ns]", "M8[ns, US/Central]", "period[D]"]
)
@pytest.mark.parametrize("box", [Series, Index, array])
def test_view_between_datetimelike(self, first, second, box):
dti = date_range("2016-01-01", periods=3)
Reported by Pylint.
Line: 41
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
orig = box(dti)
obj = orig.view(first)
assert obj.dtype == first
tm.assert_numpy_array_equal(np.asarray(obj.view("i8")), dti.asi8)
res = obj.view(second)
assert res.dtype == second
tm.assert_numpy_array_equal(np.asarray(obj.view("i8")), dti.asi8)
Reported by Bandit.
Line: 45
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
tm.assert_numpy_array_equal(np.asarray(obj.view("i8")), dti.asi8)
res = obj.view(second)
assert res.dtype == second
tm.assert_numpy_array_equal(np.asarray(obj.view("i8")), dti.asi8)
Reported by Bandit.
pandas/tests/series/methods/test_get_numeric_data.py
9 issues
Line: 14
Column: 18
# get the numeric data
obj = Series([1, 2, 3])
result = obj._get_numeric_data()
tm.assert_series_equal(result, obj)
obj = Series([1, "2", 3.0])
result = obj._get_numeric_data()
expected = Series([], dtype=object, index=Index([], dtype=object))
Reported by Pylint.
Line: 18
Column: 18
tm.assert_series_equal(result, obj)
obj = Series([1, "2", 3.0])
result = obj._get_numeric_data()
expected = Series([], dtype=object, index=Index([], dtype=object))
tm.assert_series_equal(result, expected)
obj = Series([True, False, True])
result = obj._get_numeric_data()
Reported by Pylint.
Line: 23
Column: 18
tm.assert_series_equal(result, expected)
obj = Series([True, False, True])
result = obj._get_numeric_data()
tm.assert_series_equal(result, obj)
obj = Series(date_range("20130101", periods=3))
result = obj._get_numeric_data()
expected = Series([], dtype="M8[ns]", index=Index([], dtype=object))
Reported by Pylint.
Line: 27
Column: 18
tm.assert_series_equal(result, obj)
obj = Series(date_range("20130101", periods=3))
result = obj._get_numeric_data()
expected = Series([], dtype="M8[ns]", index=Index([], dtype=object))
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 1
Column: 1
from pandas import (
Index,
Series,
date_range,
)
import pandas._testing as tm
class TestGetNumericData:
Reported by Pylint.
Line: 9
Column: 1
import pandas._testing as tm
class TestGetNumericData:
def test_get_numeric_data_preserve_dtype(self):
# get the numeric data
obj = Series([1, 2, 3])
result = obj._get_numeric_data()
Reported by Pylint.
Line: 9
Column: 1
import pandas._testing as tm
class TestGetNumericData:
def test_get_numeric_data_preserve_dtype(self):
# get the numeric data
obj = Series([1, 2, 3])
result = obj._get_numeric_data()
Reported by Pylint.
Line: 10
Column: 5
class TestGetNumericData:
def test_get_numeric_data_preserve_dtype(self):
# get the numeric data
obj = Series([1, 2, 3])
result = obj._get_numeric_data()
tm.assert_series_equal(result, obj)
Reported by Pylint.
Line: 10
Column: 5
class TestGetNumericData:
def test_get_numeric_data_preserve_dtype(self):
# get the numeric data
obj = Series([1, 2, 3])
result = obj._get_numeric_data()
tm.assert_series_equal(result, obj)
Reported by Pylint.