The following issues were found
pandas/tests/frame/methods/test_cov_corr.py
97 issues
Line: 4
Column: 1
import warnings
import numpy as np
import pytest
import pandas.util._test_decorators as td
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 202
Column: 24
ser = df["A"] # populate item_cache
if not using_array_manager:
assert len(df._mgr.blocks) == 2
_ = df.corr()
# Check that the corr didn't break link between ser and df
ser.values[0] = 99
Reported by Pylint.
Line: 1
Column: 1
import warnings
import numpy as np
import pytest
import pandas.util._test_decorators as td
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 17
Column: 1
import pandas._testing as tm
class TestDataFrameCov:
def test_cov(self, float_frame, float_string_frame):
# min_periods no NAs (corner case)
expected = float_frame.cov()
result = float_frame.cov(min_periods=len(float_frame))
Reported by Pylint.
Line: 18
Column: 5
class TestDataFrameCov:
def test_cov(self, float_frame, float_string_frame):
# min_periods no NAs (corner case)
expected = float_frame.cov()
result = float_frame.cov(min_periods=len(float_frame))
tm.assert_frame_equal(expected, result)
Reported by Pylint.
Line: 18
Column: 5
class TestDataFrameCov:
def test_cov(self, float_frame, float_string_frame):
# min_periods no NAs (corner case)
expected = float_frame.cov()
result = float_frame.cov(min_periods=len(float_frame))
tm.assert_frame_equal(expected, result)
Reported by Pylint.
Line: 26
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
tm.assert_frame_equal(expected, result)
result = float_frame.cov(min_periods=len(float_frame) + 1)
assert isna(result.values).all()
# with NAs
frame = float_frame.copy()
frame["A"][:5] = np.nan
frame["B"][5:10] = np.nan
Reported by Bandit.
Line: 49
Column: 9
tm.assert_frame_equal(result, expected)
# Single column frame
df = DataFrame(np.linspace(0.0, 1.0, 10))
result = df.cov()
expected = DataFrame(
np.cov(df.values.T).reshape((1, 1)), index=df.columns, columns=df.columns
)
tm.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 65
Column: 5
tm.assert_frame_equal(result, expected)
@pytest.mark.parametrize("test_ddof", [None, 0, 1, 2, 3])
def test_cov_ddof(self, test_ddof):
# GH#34611
np_array1 = np.random.rand(10)
np_array2 = np.random.rand(10)
df = DataFrame({0: np_array1, 1: np_array2})
result = df.cov(ddof=test_ddof)
Reported by Pylint.
Line: 65
Column: 5
tm.assert_frame_equal(result, expected)
@pytest.mark.parametrize("test_ddof", [None, 0, 1, 2, 3])
def test_cov_ddof(self, test_ddof):
# GH#34611
np_array1 = np.random.rand(10)
np_array2 = np.random.rand(10)
df = DataFrame({0: np_array1, 1: np_array2})
result = df.cov(ddof=test_ddof)
Reported by Pylint.
pandas/tests/indexes/datetimes/test_partial_slicing.py
97 issues
Line: 7
Column: 1
import operator
import numpy as np
import pytest
from pandas import (
DataFrame,
DatetimeIndex,
Index,
Reported by Pylint.
Line: 175
Column: 13
assert result == s.iloc[0]
with pytest.raises(KeyError, match=r"^'2004-12-31'$"):
s["2004-12-31"]
def test_partial_slice_daily(self):
rng = date_range(freq="H", start=datetime(2005, 1, 31), periods=500)
s = Series(np.arange(len(rng)), index=rng)
Reported by Pylint.
Line: 185
Column: 13
tm.assert_series_equal(result, s.iloc[:24])
with pytest.raises(KeyError, match=r"^'2004-12-31 00'$"):
s["2004-12-31 00"]
def test_partial_slice_hourly(self):
rng = date_range(freq="T", start=datetime(2005, 1, 1, 20, 0, 0), periods=500)
s = Series(np.arange(len(rng)), index=rng)
Reported by Pylint.
Line: 199
Column: 13
assert s["2005-1-1 20:00"] == s.iloc[0]
with pytest.raises(KeyError, match=r"^'2004-12-31 00:15'$"):
s["2004-12-31 00:15"]
def test_partial_slice_minutely(self):
rng = date_range(freq="S", start=datetime(2005, 1, 1, 23, 59, 0), periods=500)
s = Series(np.arange(len(rng)), index=rng)
Reported by Pylint.
Line: 213
Column: 13
assert s[Timestamp("2005-1-1 23:59:00")] == s.iloc[0]
with pytest.raises(KeyError, match=r"^'2004-12-31 00:00:00'$"):
s["2004-12-31 00:00:00"]
def test_partial_slice_second_precision(self):
rng = date_range(
start=datetime(2005, 1, 1, 0, 0, 59, microsecond=999990),
periods=20,
Reported by Pylint.
Line: 231
Column: 13
assert s[Timestamp("2005-1-1 00:00:59.999990")] == s.iloc[0]
with pytest.raises(KeyError, match="2005-1-1 00:00:00"):
s["2005-1-1 00:00:00"]
def test_partial_slicing_dataframe(self):
# GH14856
# Test various combinations of string slicing resolution vs.
# index resolution
Reported by Pylint.
Line: 270
Column: 21
assert result == expected
msg = fr"^'{ts_string}'$"
with pytest.raises(KeyError, match=msg):
df[ts_string]
# Timestamp with resolution less precise than index
for fmt in formats[:rnum]:
for element, theslice in [[0, slice(None, 1)], [1, slice(1, None)]]:
ts_string = index[element].strftime(fmt)
Reported by Pylint.
Line: 300
Column: 21
assert result == 2
msg = fr"^'{ts_string}'$"
with pytest.raises(KeyError, match=msg):
df[ts_string]
# Not compatible with existing key
# Should raise KeyError
for fmt, res in list(zip(formats, resolutions))[rnum + 1 :]:
ts = index[1] + Timedelta("1 " + res)
Reported by Pylint.
Line: 309
Column: 21
ts_string = ts.strftime(fmt)
msg = fr"^'{ts_string}'$"
with pytest.raises(KeyError, match=msg):
df["a"][ts_string]
with pytest.raises(KeyError, match=msg):
df[ts_string]
def test_partial_slicing_with_multiindex(self):
Reported by Pylint.
Line: 311
Column: 21
with pytest.raises(KeyError, match=msg):
df["a"][ts_string]
with pytest.raises(KeyError, match=msg):
df[ts_string]
def test_partial_slicing_with_multiindex(self):
# GH 4758
# partial string indexing with a multi-index buggy
Reported by Pylint.
pandas/tests/indexes/interval/test_indexing.py
97 issues
Line: 4
Column: 1
import re
import numpy as np
import pytest
from pandas.errors import InvalidIndexError
from pandas import (
NA,
Reported by Pylint.
Line: 350
Column: 3
tm.assert_numpy_array_equal(result_indexer, expected_indexer)
tm.assert_numpy_array_equal(result_missing, expected_missing)
# TODO we may also want to test get_indexer for the case when
# the intervals are duplicated, decreasing, non-monotonic, etc..
def test_get_indexer_non_monotonic(self):
# GH 16410
idx1 = IntervalIndex.from_tuples([(2, 3), (4, 5), (0, 1)])
Reported by Pylint.
Line: 370
Column: 20
index = IntervalIndex([np.nan, np.nan])
other = IntervalIndex([np.nan])
assert not index._index_as_unique
result = index.get_indexer_for(other)
expected = np.array([0, 1], dtype=np.intp)
tm.assert_numpy_array_equal(result, expected)
Reported by Pylint.
Line: 1
Column: 1
import re
import numpy as np
import pytest
from pandas.errors import InvalidIndexError
from pandas import (
NA,
Reported by Pylint.
Line: 21
Column: 1
import pandas._testing as tm
class TestGetLoc:
@pytest.mark.parametrize("side", ["right", "left", "both", "neither"])
def test_get_loc_interval(self, closed, side):
idx = IntervalIndex.from_tuples([(0, 1), (2, 3)], closed=closed)
Reported by Pylint.
Line: 23
Column: 5
class TestGetLoc:
@pytest.mark.parametrize("side", ["right", "left", "both", "neither"])
def test_get_loc_interval(self, closed, side):
idx = IntervalIndex.from_tuples([(0, 1), (2, 3)], closed=closed)
for bound in [[0, 1], [1, 2], [2, 3], [3, 4], [0, 2], [2.5, 3], [-1, 4]]:
# if get_loc is supplied an interval, it should only search
Reported by Pylint.
Line: 23
Column: 5
class TestGetLoc:
@pytest.mark.parametrize("side", ["right", "left", "both", "neither"])
def test_get_loc_interval(self, closed, side):
idx = IntervalIndex.from_tuples([(0, 1), (2, 3)], closed=closed)
for bound in [[0, 1], [1, 2], [2, 3], [3, 4], [0, 2], [2.5, 3], [-1, 4]]:
# if get_loc is supplied an interval, it should only search
Reported by Pylint.
Line: 33
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
msg = re.escape(f"Interval({bound[0]}, {bound[1]}, closed='{side}')")
if closed == side:
if bound == [0, 1]:
assert idx.get_loc(Interval(0, 1, closed=side)) == 0
elif bound == [2, 3]:
assert idx.get_loc(Interval(2, 3, closed=side)) == 1
else:
with pytest.raises(KeyError, match=msg):
idx.get_loc(Interval(*bound, closed=side))
Reported by Bandit.
Line: 35
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html
if bound == [0, 1]:
assert idx.get_loc(Interval(0, 1, closed=side)) == 0
elif bound == [2, 3]:
assert idx.get_loc(Interval(2, 3, closed=side)) == 1
else:
with pytest.raises(KeyError, match=msg):
idx.get_loc(Interval(*bound, closed=side))
else:
with pytest.raises(KeyError, match=msg):
Reported by Bandit.
Line: 44
Column: 5
idx.get_loc(Interval(*bound, closed=side))
@pytest.mark.parametrize("scalar", [-0.5, 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5])
def test_get_loc_scalar(self, closed, scalar):
# correct = {side: {query: answer}}.
# If query is not in the dict, that query should raise a KeyError
correct = {
"right": {0.5: 0, 1: 0, 2.5: 1, 3: 1},
Reported by Pylint.
pandas/tests/tseries/offsets/test_custom_business_day.py
97 issues
Line: 11
Column: 1
)
import numpy as np
import pytest
from pandas._libs.tslibs.offsets import (
ApplyTypeError,
BMonthEnd,
CDay,
Reported by Pylint.
Line: 13
Column: 1
import numpy as np
import pytest
from pandas._libs.tslibs.offsets import (
ApplyTypeError,
BMonthEnd,
CDay,
)
from pandas.compat import np_datetime64_compat
Reported by Pylint.
Line: 13
Column: 1
import numpy as np
import pytest
from pandas._libs.tslibs.offsets import (
ApplyTypeError,
BMonthEnd,
CDay,
)
from pandas.compat import np_datetime64_compat
Reported by Pylint.
Line: 39
Column: 28
class TestCustomBusinessDay(Base):
_offset = CDay
def setup_method(self, method):
self.d = datetime(2008, 1, 1)
self.nd = np_datetime64_compat("2008-01-01 00:00:00Z")
self.offset = CDay()
self.offset1 = self.offset
Reported by Pylint.
Line: 41
Column: 9
def setup_method(self, method):
self.d = datetime(2008, 1, 1)
self.nd = np_datetime64_compat("2008-01-01 00:00:00Z")
self.offset = CDay()
self.offset1 = self.offset
self.offset2 = CDay(2)
Reported by Pylint.
Line: 43
Column: 9
self.d = datetime(2008, 1, 1)
self.nd = np_datetime64_compat("2008-01-01 00:00:00Z")
self.offset = CDay()
self.offset1 = self.offset
self.offset2 = CDay(2)
def test_different_normalize_equals(self):
# GH#21404 changed __eq__ to return False when `normalize` does not match
Reported by Pylint.
Line: 44
Column: 9
self.nd = np_datetime64_compat("2008-01-01 00:00:00Z")
self.offset = CDay()
self.offset1 = self.offset
self.offset2 = CDay(2)
def test_different_normalize_equals(self):
# GH#21404 changed __eq__ to return False when `normalize` does not match
offset = self._offset()
Reported by Pylint.
Line: 45
Column: 9
self.offset = CDay()
self.offset1 = self.offset
self.offset2 = CDay(2)
def test_different_normalize_equals(self):
# GH#21404 changed __eq__ to return False when `normalize` does not match
offset = self._offset()
offset2 = self._offset(normalize=True)
Reported by Pylint.
Line: 32
Column: 1
)
from pandas.tests.tseries.offsets.test_offsets import _ApplyCases
from pandas.tseries import offsets as offsets
from pandas.tseries.holiday import USFederalHolidayCalendar
class TestCustomBusinessDay(Base):
_offset = CDay
Reported by Pylint.
Line: 36
Column: 1
from pandas.tseries.holiday import USFederalHolidayCalendar
class TestCustomBusinessDay(Base):
_offset = CDay
def setup_method(self, method):
self.d = datetime(2008, 1, 1)
self.nd = np_datetime64_compat("2008-01-01 00:00:00Z")
Reported by Pylint.
pandas/tests/tools/test_to_numeric.py
96 issues
Line: 5
Column: 1
import numpy as np
from numpy import iinfo
import pytest
from pandas.compat import is_platform_arm
import pandas as pd
from pandas import (
Reported by Pylint.
Line: 116
Column: 23
@pytest.mark.parametrize(
"errors,exp_data", [("ignore", [1, -3.14, "apple"]), ("coerce", [1, -3.14, np.nan])]
)
def test_ignore_error(errors, exp_data):
ser = Series([1, -3.14, "apple"])
result = to_numeric(ser, errors=errors)
expected = Series(exp_data)
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 133
Column: 24
("coerce", [1.0, 0.0, np.nan]),
],
)
def test_bool_handling(errors, exp):
ser = Series([True, False, "apple"])
if isinstance(exp, str):
with pytest.raises(ValueError, match=exp):
to_numeric(ser, errors=errors)
Reported by Pylint.
Line: 233
Column: 21
tm.assert_series_equal(result, expected)
def test_type_check(errors):
# see gh-11776
df = DataFrame({"a": [1, -3.14, 7], "b": ["4", "5", "6"]})
kwargs = {"errors": errors} if errors is not None else {}
with pytest.raises(TypeError, match="1-d array"):
to_numeric(df, **kwargs)
Reported by Pylint.
Line: 242
Column: 30
@pytest.mark.parametrize("val", [1, 1.1, 20001])
def test_scalar(val, signed, transform):
val = -val if signed else val
assert to_numeric(transform(val)) == float(val)
def test_really_large_scalar(large_val, signed, transform, errors):
Reported by Pylint.
Line: 242
Column: 22
@pytest.mark.parametrize("val", [1, 1.1, 20001])
def test_scalar(val, signed, transform):
val = -val if signed else val
assert to_numeric(transform(val)) == float(val)
def test_really_large_scalar(large_val, signed, transform, errors):
Reported by Pylint.
Line: 247
Column: 30
assert to_numeric(transform(val)) == float(val)
def test_really_large_scalar(large_val, signed, transform, errors):
# see gh-24910
kwargs = {"errors": errors} if errors is not None else {}
val = -large_val if signed else large_val
val = transform(val)
Reported by Pylint.
Line: 247
Column: 41
assert to_numeric(transform(val)) == float(val)
def test_really_large_scalar(large_val, signed, transform, errors):
# see gh-24910
kwargs = {"errors": errors} if errors is not None else {}
val = -large_val if signed else large_val
val = transform(val)
Reported by Pylint.
Line: 247
Column: 60
assert to_numeric(transform(val)) == float(val)
def test_really_large_scalar(large_val, signed, transform, errors):
# see gh-24910
kwargs = {"errors": errors} if errors is not None else {}
val = -large_val if signed else large_val
val = transform(val)
Reported by Pylint.
Line: 247
Column: 49
assert to_numeric(transform(val)) == float(val)
def test_really_large_scalar(large_val, signed, transform, errors):
# see gh-24910
kwargs = {"errors": errors} if errors is not None else {}
val = -large_val if signed else large_val
val = transform(val)
Reported by Pylint.
pandas/tests/arrays/categorical/test_api.py
96 issues
Line: 4
Column: 1
import re
import numpy as np
import pytest
from pandas import (
Categorical,
CategoricalIndex,
DataFrame,
Reported by Pylint.
Line: 267
Column: 37
# internals...
c = Categorical([1, 2, 3, 4, 1], categories=[1, 2, 3, 4], ordered=True)
tm.assert_numpy_array_equal(c._codes, np.array([0, 1, 2, 3, 0], dtype=np.int8))
tm.assert_index_equal(c.categories, Index([1, 2, 3, 4]))
exp = np.array([1, 2, 3, 4, 1], dtype=np.int64)
tm.assert_numpy_array_equal(np.asarray(c), exp)
Reported by Pylint.
Line: 277
Column: 37
c = c.set_categories([4, 3, 2, 1])
# positions are changed
tm.assert_numpy_array_equal(c._codes, np.array([3, 2, 1, 0, 3], dtype=np.int8))
# categories are now in new order
tm.assert_index_equal(c.categories, Index([4, 3, 2, 1]))
# output is the same
Reported by Pylint.
Line: 347
Column: 9
def test_set_categories_private(self):
cat = Categorical(["a", "b", "c"], categories=["a", "b", "c", "d"])
cat._set_categories(["a", "c", "d", "e"])
expected = Categorical(["a", "c", "d"], categories=list("acde"))
tm.assert_categorical_equal(cat, expected)
# fastpath
cat = Categorical(["a", "b", "c"], categories=["a", "b", "c", "d"])
Reported by Pylint.
Line: 353
Column: 9
# fastpath
cat = Categorical(["a", "b", "c"], categories=["a", "b", "c", "d"])
cat._set_categories(["a", "c", "d", "e"], fastpath=True)
expected = Categorical(["a", "c", "d"], categories=list("acde"))
tm.assert_categorical_equal(cat, expected)
def test_remove_categories(self):
cat = Categorical(["a", "b", "c", "a"], ordered=True)
Reported by Pylint.
Line: 494
Column: 21
def test_codes_setter_deprecated(self):
cat = Categorical([1, 2, 3, 1, 2, 3, 3, 2, 1, 1, 1])
new_codes = cat._codes + 1
with tm.assert_produces_warning(FutureWarning):
# GH#40606
cat._codes = new_codes
assert cat._codes is new_codes
Reported by Pylint.
Line: 497
Column: 13
new_codes = cat._codes + 1
with tm.assert_produces_warning(FutureWarning):
# GH#40606
cat._codes = new_codes
assert cat._codes is new_codes
class TestPrivateCategoricalAPI:
Reported by Pylint.
Line: 499
Column: 16
# GH#40606
cat._codes = new_codes
assert cat._codes is new_codes
class TestPrivateCategoricalAPI:
def test_codes_immutable(self):
Reported by Pylint.
Line: 525
Column: 9
c[4] = "a"
exp = np.array([0, 1, 2, 0, 0], dtype="int8")
tm.assert_numpy_array_equal(c.codes, exp)
c._codes[4] = 2
exp = np.array([0, 1, 2, 0, 2], dtype="int8")
tm.assert_numpy_array_equal(c.codes, exp)
@pytest.mark.parametrize(
"codes, old, new, expected",
Reported by Pylint.
Line: 1
Column: 1
import re
import numpy as np
import pytest
from pandas import (
Categorical,
CategoricalIndex,
DataFrame,
Reported by Pylint.
pandas/tests/test_multilevel.py
95 issues
Line: 2
Column: 1
import numpy as np
import pytest
import pandas as pd
from pandas import (
DataFrame,
MultiIndex,
Series,
)
Reported by Pylint.
Line: 211
Column: 13
level_name = frame.index.names[level]
if axis == 0:
frame = frame
else:
frame = frame.T
grouped = frame.groupby(level=level, axis=axis, sort=sort)
Reported by Pylint.
Line: 231
Column: 23
frame = frame.sort_index(level=level, axis=axis)
# for good measure, groupby detail
level_index = frame._get_axis(axis).levels[level].rename(level_name)
tm.assert_index_equal(leftside._get_axis(axis), level_index)
tm.assert_index_equal(rightside._get_axis(axis), level_index)
tm.assert_frame_equal(leftside, rightside)
Reported by Pylint.
Line: 233
Column: 31
# for good measure, groupby detail
level_index = frame._get_axis(axis).levels[level].rename(level_name)
tm.assert_index_equal(leftside._get_axis(axis), level_index)
tm.assert_index_equal(rightside._get_axis(axis), level_index)
tm.assert_frame_equal(leftside, rightside)
def test_std_var_pass_ddof(self):
Reported by Pylint.
Line: 234
Column: 31
level_index = frame._get_axis(axis).levels[level].rename(level_name)
tm.assert_index_equal(leftside._get_axis(axis), level_index)
tm.assert_index_equal(rightside._get_axis(axis), level_index)
tm.assert_frame_equal(leftside, rightside)
def test_std_var_pass_ddof(self):
index = MultiIndex.from_arrays(
Reported by Pylint.
Line: 246
Column: 51
for meth in ["var", "std"]:
ddof = 4
alt = lambda x: getattr(x, meth)(ddof=ddof)
with tm.assert_produces_warning(FutureWarning):
result = getattr(df[0], meth)(level=0, ddof=ddof)
expected = df[0].groupby(level=0).agg(alt)
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 246
Column: 40
for meth in ["var", "std"]:
ddof = 4
alt = lambda x: getattr(x, meth)(ddof=ddof)
with tm.assert_produces_warning(FutureWarning):
result = getattr(df[0], meth)(level=0, ddof=ddof)
expected = df[0].groupby(level=0).agg(alt)
tm.assert_series_equal(result, expected)
Reported by Pylint.
Line: 280
Column: 3
expected = ymd.groupby([k1, k2]).mean()
# TODO groupby with level_values drops names
tm.assert_frame_equal(result, expected, check_names=False)
assert result.index.names == ymd.index.names[:2]
result2 = ymd.groupby(level=ymd.index.names[:2]).mean()
tm.assert_frame_equal(result, result2)
Reported by Pylint.
Line: 296
Column: 14
)
df = DataFrame(np.random.randn(4, 4), index=index, columns=index)
df["Totals", ""] = df.sum(1)
df = df._consolidate()
def test_level_with_tuples(self):
index = MultiIndex(
levels=[[("foo", "bar", 0), ("foo", "baz", 0), ("foo", "qux", 0)], [0, 1]],
codes=[[0, 0, 1, 1, 2, 2], [0, 1, 0, 1, 0, 1]],
Reported by Pylint.
Line: 315
Column: 13
tm.assert_series_equal(result2, expected)
with pytest.raises(KeyError, match=r"^\(\('foo', 'bar', 0\), 2\)$"):
series[("foo", "bar", 0), 2]
result = frame.loc[("foo", "bar", 0)]
result2 = frame.xs(("foo", "bar", 0))
expected = frame[:2]
expected.index = expected.index.droplevel(0)
Reported by Pylint.
pandas/tests/io/formats/style/test_html.py
95 issues
Line: 16
Suggestion:
https://bandit.readthedocs.io/en/latest/plugins/b701_jinja2_autoescape_false.html
from pandas.io.formats.style import Styler
loader = jinja2.PackageLoader("pandas", "io/formats/templates")
env = jinja2.Environment(loader=loader, trim_blocks=True)
@pytest.fixture
def styler():
return Styler(DataFrame([[2.61], [2.69]], index=["a", "b"], columns=["A"]))
Reported by Bandit.
Line: 4
Column: 1
from textwrap import dedent
import numpy as np
import pytest
from pandas import (
DataFrame,
MultiIndex,
option_context,
Reported by Pylint.
Line: 49
Column: 25
assert "{% include html_table_tpl %}" in result
def test_exclude_styles(styler):
result = styler.to_html(exclude_styles=True, doctype_html=True)
expected = dedent(
"""\
<!DOCTYPE html>
<html>
Reported by Pylint.
Line: 84
Column: 25
assert result == expected
def test_w3_html_format(styler):
styler.set_uuid("").set_table_styles(
[{"selector": "th", "props": "att2:v2;"}]
).applymap(lambda x: "att1:v1;").set_table_attributes(
'class="my-cls1" style="attr3:v3;"'
).set_td_classes(
Reported by Pylint.
Line: 133
Column: 5
def test_colspan_w3():
# GH 36223
df = DataFrame(data=[[1, 2]], columns=[["l0", "l0"], ["l1a", "l1b"]])
styler = Styler(df, uuid="_", cell_ids=False)
assert '<th class="col_heading level0 col0" colspan="2">l0</th>' in styler.to_html()
def test_rowspan_w3():
# GH 38533
Reported by Pylint.
Line: 140
Column: 5
def test_rowspan_w3():
# GH 38533
df = DataFrame(data=[[1, 2]], index=[["l0", "l0"], ["l1a", "l1b"]])
styler = Styler(df, uuid="_", cell_ids=False)
assert '<th class="row_heading level0 row0" rowspan="2">l0</th>' in styler.to_html()
def test_styles(styler):
styler.set_uuid("abc")
Reported by Pylint.
Line: 144
Column: 17
assert '<th class="row_heading level0 row0" rowspan="2">l0</th>' in styler.to_html()
def test_styles(styler):
styler.set_uuid("abc")
styler.set_table_styles([{"selector": "td", "props": "color: red;"}])
result = styler.to_html(doctype_html=True)
expected = dedent(
"""\
Reported by Pylint.
Line: 186
Column: 18
assert result == expected
def test_doctype(styler):
result = styler.to_html(doctype_html=False)
assert "<html>" not in result
assert "<body>" not in result
assert "<!DOCTYPE html>" not in result
assert "<head>" not in result
Reported by Pylint.
Line: 194
Column: 33
assert "<head>" not in result
def test_block_names(tpl_style, tpl_table):
# catch accidental removal of a block
expected_style = {
"before_style",
"style",
"table_styles",
Reported by Pylint.
Line: 194
Column: 22
assert "<head>" not in result
def test_block_names(tpl_style, tpl_table):
# catch accidental removal of a block
expected_style = {
"before_style",
"style",
"table_styles",
Reported by Pylint.
pandas/tests/extension/base/reshaping.py
94 issues
Line: 4
Column: 1
import itertools
import numpy as np
import pytest
from pandas.core.dtypes.common import (
is_datetime64tz_dtype,
is_interval_dtype,
is_period_dtype,
Reported by Pylint.
Line: 36
Column: 20
dtype = result.dtype
assert dtype == data.dtype
if hasattr(result._mgr, "blocks"):
assert isinstance(result._mgr.blocks[0], ExtensionBlock)
assert isinstance(result._mgr.arrays[0], ExtensionArray)
@pytest.mark.parametrize("in_frame", [True, False])
def test_concat_all_na_block(self, data_missing, in_frame):
Reported by Pylint.
Line: 37
Column: 31
assert dtype == data.dtype
if hasattr(result._mgr, "blocks"):
assert isinstance(result._mgr.blocks[0], ExtensionBlock)
assert isinstance(result._mgr.arrays[0], ExtensionArray)
@pytest.mark.parametrize("in_frame", [True, False])
def test_concat_all_na_block(self, data_missing, in_frame):
valid_block = pd.Series(data_missing.take([1, 1]), index=[0, 1])
Reported by Pylint.
Line: 38
Column: 27
assert dtype == data.dtype
if hasattr(result._mgr, "blocks"):
assert isinstance(result._mgr.blocks[0], ExtensionBlock)
assert isinstance(result._mgr.arrays[0], ExtensionArray)
@pytest.mark.parametrize("in_frame", [True, False])
def test_concat_all_na_block(self, data_missing, in_frame):
valid_block = pd.Series(data_missing.take([1, 1]), index=[0, 1])
na_block = pd.Series(data_missing.take([0, 0]), index=[2, 3])
Reported by Pylint.
Line: 95
Column: 22
df2 = pd.DataFrame({"B": [1, 2, 3]}, index=[1, 2, 3])
expected = pd.DataFrame(
{
"A": data._from_sequence(list(data[:3]) + [na_value], dtype=data.dtype),
"B": [np.nan, 1, 2, 3],
}
)
result = pd.concat([df1, df2], axis=1)
Reported by Pylint.
Line: 111
Column: 22
df2 = pd.DataFrame({"B": data[3:7]})
expected = pd.DataFrame(
{
"A": data._from_sequence(list(data[:3]) + [na_value], dtype=data.dtype),
"B": data[3:7],
}
)
result = pd.concat([df1, df2], axis=1, copy=False)
self.assert_frame_equal(result, expected)
Reported by Pylint.
Line: 137
Column: 24
r1, r2 = pd.Series(a).align(pd.Series(b, index=[1, 2, 3]))
# Assumes that the ctor can take a list of scalars of the type
e1 = pd.Series(data._from_sequence(list(a) + [na_value], dtype=data.dtype))
e2 = pd.Series(data._from_sequence([na_value] + list(b), dtype=data.dtype))
self.assert_series_equal(r1, e1)
self.assert_series_equal(r2, e2)
def test_align_frame(self, data, na_value):
Reported by Pylint.
Line: 138
Column: 24
# Assumes that the ctor can take a list of scalars of the type
e1 = pd.Series(data._from_sequence(list(a) + [na_value], dtype=data.dtype))
e2 = pd.Series(data._from_sequence([na_value] + list(b), dtype=data.dtype))
self.assert_series_equal(r1, e1)
self.assert_series_equal(r2, e2)
def test_align_frame(self, data, na_value):
a = data[:3]
Reported by Pylint.
Line: 149
Column: 19
# Assumes that the ctor can take a list of scalars of the type
e1 = pd.DataFrame(
{"A": data._from_sequence(list(a) + [na_value], dtype=data.dtype)}
)
e2 = pd.DataFrame(
{"A": data._from_sequence([na_value] + list(b), dtype=data.dtype)}
)
self.assert_frame_equal(r1, e1)
Reported by Pylint.
Line: 152
Column: 19
{"A": data._from_sequence(list(a) + [na_value], dtype=data.dtype)}
)
e2 = pd.DataFrame(
{"A": data._from_sequence([na_value] + list(b), dtype=data.dtype)}
)
self.assert_frame_equal(r1, e1)
self.assert_frame_equal(r2, e2)
def test_align_series_frame(self, data, na_value):
Reported by Pylint.
pandas/core/arrays/categorical.py
94 issues
Line: 25
Column: 1
from pandas._config import get_option
from pandas._libs import (
NaT,
algos as libalgos,
hashtable as htable,
lib,
)
Reported by Pylint.
Line: 25
Column: 1
from pandas._config import get_option
from pandas._libs import (
NaT,
algos as libalgos,
hashtable as htable,
lib,
)
Reported by Pylint.
Line: 25
Column: 1
from pandas._config import get_option
from pandas._libs import (
NaT,
algos as libalgos,
hashtable as htable,
lib,
)
Reported by Pylint.
Line: 31
Column: 1
hashtable as htable,
lib,
)
from pandas._libs.arrays import NDArrayBacked
from pandas._libs.lib import no_default
from pandas._typing import (
ArrayLike,
Dtype,
NpDtype,
Reported by Pylint.
Line: 31
Column: 1
hashtable as htable,
lib,
)
from pandas._libs.arrays import NDArrayBacked
from pandas._libs.lib import no_default
from pandas._typing import (
ArrayLike,
Dtype,
NpDtype,
Reported by Pylint.
Line: 32
Column: 1
lib,
)
from pandas._libs.arrays import NDArrayBacked
from pandas._libs.lib import no_default
from pandas._typing import (
ArrayLike,
Dtype,
NpDtype,
Ordered,
Reported by Pylint.
Line: 32
Column: 1
lib,
)
from pandas._libs.arrays import NDArrayBacked
from pandas._libs.lib import no_default
from pandas._typing import (
ArrayLike,
Dtype,
NpDtype,
Ordered,
Reported by Pylint.
Line: 2049
Column: 50
codes = self.categories.get_indexer(value)
return codes.astype(self._ndarray.dtype, copy=False)
def _reverse_indexer(self) -> dict[Hashable, npt.NDArray[np.intp]]:
"""
Compute the inverse of a categorical, returning
a dict of categories -> indexers.
*This is an internal function*
Reported by Pylint.
Line: 145
Column: 20
# the same (maybe up to ordering, depending on ordered)
msg = "Categoricals can only be compared if 'categories' are the same."
if not self._categories_match_up_to_permutation(other):
raise TypeError(msg)
if not self.ordered and not self.categories.equals(other.categories):
# both unordered and different order
other_codes = recode_for_categories(
Reported by Pylint.
Line: 154
Column: 31
other.codes, other.categories, self.categories, copy=False
)
else:
other_codes = other._codes
ret = op(self._codes, other_codes)
mask = (self._codes == -1) | (other_codes == -1)
if mask.any():
ret[mask] = fill_value
Reported by Pylint.