The following issues were found
pandas/tests/indexes/base_class/test_where.py
5 issues
Line: 1
Column: 1
import numpy as np
from pandas import Index
import pandas._testing as tm
class TestWhere:
def test_where_intlike_str_doesnt_cast_ints(self):
idx = Index(range(3))
Reported by Pylint.
Line: 7
Column: 1
import pandas._testing as tm
class TestWhere:
def test_where_intlike_str_doesnt_cast_ints(self):
idx = Index(range(3))
mask = np.array([True, False, True])
res = idx.where(mask, "2")
expected = Index([0, "2", 2])
Reported by Pylint.
Line: 7
Column: 1
import pandas._testing as tm
class TestWhere:
def test_where_intlike_str_doesnt_cast_ints(self):
idx = Index(range(3))
mask = np.array([True, False, True])
res = idx.where(mask, "2")
expected = Index([0, "2", 2])
Reported by Pylint.
Line: 8
Column: 5
class TestWhere:
def test_where_intlike_str_doesnt_cast_ints(self):
idx = Index(range(3))
mask = np.array([True, False, True])
res = idx.where(mask, "2")
expected = Index([0, "2", 2])
tm.assert_index_equal(res, expected)
Reported by Pylint.
Line: 8
Column: 5
class TestWhere:
def test_where_intlike_str_doesnt_cast_ints(self):
idx = Index(range(3))
mask = np.array([True, False, True])
res = idx.where(mask, "2")
expected = Index([0, "2", 2])
tm.assert_index_equal(res, expected)
Reported by Pylint.
pandas/tests/apply/test_series_apply_relabeling.py
5 issues
Line: 1
Column: 1
import pandas as pd
import pandas._testing as tm
def test_relabel_no_duplicated_method():
# this is to test there is no duplicated method used in agg
df = pd.DataFrame({"A": [1, 2, 1, 2], "B": [1, 2, 3, 4]})
result = df["A"].agg(foo="sum")
Reported by Pylint.
Line: 5
Column: 1
import pandas._testing as tm
def test_relabel_no_duplicated_method():
# this is to test there is no duplicated method used in agg
df = pd.DataFrame({"A": [1, 2, 1, 2], "B": [1, 2, 3, 4]})
result = df["A"].agg(foo="sum")
expected = df["A"].agg({"foo": "sum"})
Reported by Pylint.
Line: 7
Column: 5
def test_relabel_no_duplicated_method():
# this is to test there is no duplicated method used in agg
df = pd.DataFrame({"A": [1, 2, 1, 2], "B": [1, 2, 3, 4]})
result = df["A"].agg(foo="sum")
expected = df["A"].agg({"foo": "sum"})
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 22
Column: 1
tm.assert_series_equal(result, expected)
def test_relabel_duplicated_method():
# this is to test with nested renaming, duplicated method can be used
# if they are assigned with different new names
df = pd.DataFrame({"A": [1, 2, 1, 2], "B": [1, 2, 3, 4]})
result = df["A"].agg(foo="sum", bar="sum")
Reported by Pylint.
Line: 25
Column: 5
def test_relabel_duplicated_method():
# this is to test with nested renaming, duplicated method can be used
# if they are assigned with different new names
df = pd.DataFrame({"A": [1, 2, 1, 2], "B": [1, 2, 3, 4]})
result = df["A"].agg(foo="sum", bar="sum")
expected = pd.Series([6, 6], index=["foo", "bar"], name="A")
tm.assert_series_equal(result, expected)
Reported by Pylint.
pandas/_config/localization.py
5 issues
Line: 102
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b602_subprocess_popen_with_shell_equals_true.html
def _default_locale_getter():
return subprocess.check_output(["locale -a"], shell=True)
def get_locales(prefix=None, normalize=True, locale_getter=_default_locale_getter):
"""
Get all the locales that are available on the system.
Reported by Bandit.
Line: 9
Suggestion:
https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess
from contextlib import contextmanager
import locale
import re
import subprocess
from pandas._config.config import options
@contextmanager
Reported by Bandit.
Line: 47
Column: 1
locale.setlocale(lc_var, current_locale)
def can_set_locale(lc: str, lc_var: int = locale.LC_ALL) -> bool:
"""
Check to see if we can set a locale, and subsequently get the locale,
without raising an Exception.
Parameters
Reported by Pylint.
Line: 102
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b607_start_process_with_partial_path.html
def _default_locale_getter():
return subprocess.check_output(["locale -a"], shell=True)
def get_locales(prefix=None, normalize=True, locale_getter=_default_locale_getter):
"""
Get all the locales that are available on the system.
Reported by Bandit.
Line: 147
Column: 13
# extract what we can and then rejoin.
raw_locales = raw_locales.split(b"\n")
out_locales = []
for x in raw_locales:
try:
out_locales.append(str(x, encoding=options.display.encoding))
except UnicodeError:
# 'locale -a' is used to populated 'raw_locales' and on
# Redhat 7 Linux (and maybe others) prints locale names
Reported by Pylint.
pandas/io/formats/console.py
5 issues
Line: 14
Column: 5
Returns (None,None) in non-interactive session.
"""
from pandas import get_option
display_width = get_option("display.width")
display_height = get_option("display.max_rows")
# Consider
Reported by Pylint.
Line: 33
Column: 13
if in_ipython_frontend():
# sane defaults for interactive non-shell terminal
# match default for width,height in config_init
from pandas._config.config import get_default_val
terminal_width = get_default_val("display.width")
terminal_height = get_default_val("display.max_rows")
else:
# pure terminal
Reported by Pylint.
Line: 62
Column: 5
bool
True if running under python/ipython interactive shell.
"""
from pandas import get_option
def check_main():
try:
import __main__ as main
except ModuleNotFoundError:
Reported by Pylint.
Line: 66
Column: 13
def check_main():
try:
import __main__ as main
except ModuleNotFoundError:
return get_option("mode.sim_interactive")
return not hasattr(main, "__file__") or get_option("mode.sim_interactive")
try:
Reported by Pylint.
Line: 88
Column: 9
"""
try:
# error: Name 'get_ipython' is not defined
ip = get_ipython() # type: ignore[name-defined]
return "zmq" in str(type(ip)).lower()
except NameError:
pass
return False
Reported by Pylint.
pandas/tests/indexes/timedeltas/methods/test_fillna.py
5 issues
Line: 1
Column: 1
from pandas import (
Index,
NaT,
Timedelta,
TimedeltaIndex,
)
import pandas._testing as tm
Reported by Pylint.
Line: 10
Column: 1
import pandas._testing as tm
class TestFillNA:
def test_fillna_timedelta(self):
# GH#11343
idx = TimedeltaIndex(["1 day", NaT, "3 day"])
exp = TimedeltaIndex(["1 day", "2 day", "3 day"])
Reported by Pylint.
Line: 10
Column: 1
import pandas._testing as tm
class TestFillNA:
def test_fillna_timedelta(self):
# GH#11343
idx = TimedeltaIndex(["1 day", NaT, "3 day"])
exp = TimedeltaIndex(["1 day", "2 day", "3 day"])
Reported by Pylint.
Line: 11
Column: 5
class TestFillNA:
def test_fillna_timedelta(self):
# GH#11343
idx = TimedeltaIndex(["1 day", NaT, "3 day"])
exp = TimedeltaIndex(["1 day", "2 day", "3 day"])
tm.assert_index_equal(idx.fillna(Timedelta("2 day")), exp)
Reported by Pylint.
Line: 11
Column: 5
class TestFillNA:
def test_fillna_timedelta(self):
# GH#11343
idx = TimedeltaIndex(["1 day", NaT, "3 day"])
exp = TimedeltaIndex(["1 day", "2 day", "3 day"])
tm.assert_index_equal(idx.fillna(Timedelta("2 day")), exp)
Reported by Pylint.
pandas/tests/series/methods/test_isna.py
5 issues
Line: 13
Column: 1
import pandas._testing as tm
class TestIsna:
def test_isna_period_dtype(self):
# GH#13737
ser = Series([Period("2011-01", freq="M"), Period("NaT", freq="M")])
expected = Series([False, True])
Reported by Pylint.
Line: 14
Column: 5
class TestIsna:
def test_isna_period_dtype(self):
# GH#13737
ser = Series([Period("2011-01", freq="M"), Period("NaT", freq="M")])
expected = Series([False, True])
Reported by Pylint.
Line: 14
Column: 5
class TestIsna:
def test_isna_period_dtype(self):
# GH#13737
ser = Series([Period("2011-01", freq="M"), Period("NaT", freq="M")])
expected = Series([False, True])
Reported by Pylint.
Line: 26
Column: 5
result = ser.notna()
tm.assert_series_equal(result, ~expected)
def test_isna(self):
ser = Series([0, 5.4, 3, np.nan, -0.001])
expected = Series([False, False, False, True, False])
tm.assert_series_equal(ser.isna(), expected)
tm.assert_series_equal(ser.notna(), ~expected)
Reported by Pylint.
Line: 26
Column: 5
result = ser.notna()
tm.assert_series_equal(result, ~expected)
def test_isna(self):
ser = Series([0, 5.4, 3, np.nan, -0.001])
expected = Series([False, False, False, True, False])
tm.assert_series_equal(ser.isna(), expected)
tm.assert_series_equal(ser.notna(), ~expected)
Reported by Pylint.
pandas/tests/indexes/multi/test_astype.py
5 issues
Line: 2
Column: 1
import numpy as np
import pytest
from pandas.core.dtypes.dtypes import CategoricalDtype
import pandas._testing as tm
def test_astype(idx):
Reported by Pylint.
Line: 1
Column: 1
import numpy as np
import pytest
from pandas.core.dtypes.dtypes import CategoricalDtype
import pandas._testing as tm
def test_astype(idx):
Reported by Pylint.
Line: 9
Column: 1
import pandas._testing as tm
def test_astype(idx):
expected = idx.copy()
actual = idx.astype("O")
tm.assert_copy(actual.levels, expected.levels)
tm.assert_copy(actual.codes, expected.codes)
assert actual.names == list(expected.names)
Reported by Pylint.
Line: 14
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
actual = idx.astype("O")
tm.assert_copy(actual.levels, expected.levels)
tm.assert_copy(actual.codes, expected.codes)
assert actual.names == list(expected.names)
with pytest.raises(TypeError, match="^Setting.*dtype.*object"):
idx.astype(np.dtype(int))
Reported by Bandit.
Line: 21
Column: 1
@pytest.mark.parametrize("ordered", [True, False])
def test_astype_category(idx, ordered):
# GH 18630
msg = "> 1 ndim Categorical are not supported at this time"
with pytest.raises(NotImplementedError, match=msg):
idx.astype(CategoricalDtype(ordered=ordered))
Reported by Pylint.
pandas/util/_exceptions.py
5 issues
Line: 1
Column: 1
from __future__ import annotations
import contextlib
import inspect
import os
@contextlib.contextmanager
def rewrite_exception(old_name: str, new_name: str):
Reported by Pylint.
Line: 34
Column: 5
"""
stack = inspect.stack()
import pandas as pd
pkg_dir = os.path.dirname(pd.__file__)
test_dir = os.path.join(pkg_dir, "tests")
for n in range(len(stack)):
Reported by Pylint.
Line: 39
Column: 9
pkg_dir = os.path.dirname(pd.__file__)
test_dir = os.path.join(pkg_dir, "tests")
for n in range(len(stack)):
fname = stack[n].filename
if fname.startswith(pkg_dir) and not fname.startswith(test_dir):
continue
else:
break
Reported by Pylint.
Line: 39
Column: 5
pkg_dir = os.path.dirname(pd.__file__)
test_dir = os.path.join(pkg_dir, "tests")
for n in range(len(stack)):
fname = stack[n].filename
if fname.startswith(pkg_dir) and not fname.startswith(test_dir):
continue
else:
break
Reported by Pylint.
Line: 41
Column: 9
for n in range(len(stack)):
fname = stack[n].filename
if fname.startswith(pkg_dir) and not fname.startswith(test_dir):
continue
else:
break
return n
Reported by Pylint.
pandas/tests/io/excel/test_odf.py
5 issues
Line: 4
Column: 1
import functools
import numpy as np
import pytest
import pandas as pd
import pandas._testing as tm
pytest.importorskip("odf")
Reported by Pylint.
Line: 1
Column: 1
import functools
import numpy as np
import pytest
import pandas as pd
import pandas._testing as tm
pytest.importorskip("odf")
Reported by Pylint.
Line: 13
Column: 1
@pytest.fixture(autouse=True)
def cd_and_set_engine(monkeypatch, datapath):
func = functools.partial(pd.read_excel, engine="odf")
monkeypatch.setattr(pd, "read_excel", func)
monkeypatch.chdir(datapath("io", "data", "excel"))
Reported by Pylint.
Line: 19
Column: 1
monkeypatch.chdir(datapath("io", "data", "excel"))
def test_read_invalid_types_raises():
# the invalid_value_type.ods required manually editing
# of the included content.xml file
with pytest.raises(ValueError, match="Unrecognized type awesome_new_type"):
pd.read_excel("invalid_value_type.ods")
Reported by Pylint.
Line: 26
Column: 1
pd.read_excel("invalid_value_type.ods")
def test_read_writer_table():
# Also test reading tables from an text OpenDocument file
# (.odt)
index = pd.Index(["Row 1", "Row 2", "Row 3"], name="Header")
expected = pd.DataFrame(
[[1, np.nan, 7], [2, np.nan, 8], [3, np.nan, 9]],
Reported by Pylint.
pandas/tests/series/methods/test_tz_convert.py
5 issues
Line: 1
Column: 1
import numpy as np
from pandas import (
DatetimeIndex,
Series,
)
import pandas._testing as tm
Reported by Pylint.
Line: 10
Column: 1
import pandas._testing as tm
class TestTZConvert:
def test_series_tz_convert_to_utc(self):
base = DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03"], tz="UTC")
idx1 = base.tz_convert("Asia/Tokyo")[:2]
idx2 = base.tz_convert("US/Eastern")[1:]
Reported by Pylint.
Line: 10
Column: 1
import pandas._testing as tm
class TestTZConvert:
def test_series_tz_convert_to_utc(self):
base = DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03"], tz="UTC")
idx1 = base.tz_convert("Asia/Tokyo")[:2]
idx2 = base.tz_convert("US/Eastern")[1:]
Reported by Pylint.
Line: 11
Column: 5
class TestTZConvert:
def test_series_tz_convert_to_utc(self):
base = DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03"], tz="UTC")
idx1 = base.tz_convert("Asia/Tokyo")[:2]
idx2 = base.tz_convert("US/Eastern")[1:]
res = Series([1, 2], index=idx1) + Series([1, 1], index=idx2)
Reported by Pylint.
Line: 11
Column: 5
class TestTZConvert:
def test_series_tz_convert_to_utc(self):
base = DatetimeIndex(["2011-01-01", "2011-01-02", "2011-01-03"], tz="UTC")
idx1 = base.tz_convert("Asia/Tokyo")[:2]
idx2 = base.tz_convert("US/Eastern")[1:]
res = Series([1, 2], index=idx1) + Series([1, 1], index=idx2)
Reported by Pylint.