Skip to content

48855 style fix pylint issues #49848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
2 changes: 2 additions & 0 deletions pandas/io/parsers/c_parser_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def __init__(self, src: ReadCsvBuffer[str], **kwds) -> None:
n
# error: Cannot determine type of 'names'
for i, n in enumerate(self.names) # type: ignore[has-type]
# pylint: disable=unsupported-membership-test
if (i in usecols or n in usecols)
]

Expand Down Expand Up @@ -322,6 +323,7 @@ def read(

def _filter_usecols(self, names: Sequence[Hashable]) -> Sequence[Hashable]:
# hackish
# pylint: disable=unsupported-membership-test
usecols = self._evaluate_usecols(self.usecols, names)
if usecols is not None and len(names) != len(usecols):
names = [
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/extension/list/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def test_to_csv(data):
# which was done in to_native_types
df = pd.DataFrame({"a": data})
res = df.to_csv()
assert str(data[0]) in res
assert str(data[0]) in str(res)
1 change: 1 addition & 0 deletions pandas/tests/indexes/multi/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ def test_where_array_like(self, listlike_box):

class TestContains:
def test_contains_top_level(self):
# pylint: disable=unsupported-membership-test
midx = MultiIndex.from_product([["A", "B"], [1, 2]])
assert "A" in midx
assert "A" not in midx._engine
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/io/formats/style/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ def test_format_escape_html(escape, exp):

s = Styler(df, uuid_len=0).format("&{0}&", escape=None)
expected = f'<td id="T__row0_col0" class="data row0 col0" >&{chars}&</td>'
assert expected in s.to_html()
assert expected in str(s.to_html())

# only the value should be escaped before passing to the formatter
s = Styler(df, uuid_len=0).format("&{0}&", escape=escape)
expected = f'<td id="T__row0_col0" class="data row0 col0" >&{exp}&</td>'
assert expected in s.to_html()
assert expected in str(s.to_html())

# also test format_index()
styler = Styler(DataFrame(columns=[chars]), uuid_len=0)
Expand All @@ -198,8 +198,8 @@ def test_format_escape_na_rep():
s = Styler(df, uuid_len=0).format("X&{0}>X", escape="html", na_rep="&")
ex = '<td id="T__row0_col0" class="data row0 col0" >X&&lt;&gt;&amp;&#34;>X</td>'
expected2 = '<td id="T__row0_col1" class="data row0 col1" >&</td>'
assert ex in s.to_html()
assert expected2 in s.to_html()
assert ex in str(s.to_html())
assert expected2 in str(s.to_html())

# also test for format_index()
df = DataFrame(columns=['<>&"', None])
Expand Down Expand Up @@ -429,7 +429,7 @@ def test_precision_zero(df):
def test_formatter_options_validator(formatter, exp):
df = DataFrame([[9]])
with option_context("styler.format.formatter", formatter):
assert f" {exp} " in df.style.to_latex()
assert f" {exp} " in str(df.style.to_latex())


def test_formatter_options_raises():
Expand Down
12 changes: 8 additions & 4 deletions pandas/tests/io/formats/style/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,18 @@ 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()
assert '<th class="col_heading level0 col0" colspan="2">l0</th>' in str(
styler.to_html()
)


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()
assert '<th class="row_heading level0 row0" rowspan="2">l0</th>' in str(
styler.to_html()
)


def test_styles(styler):
Expand Down Expand Up @@ -803,7 +807,7 @@ def test_rendered_links(type, text, exp, found):
styler = df.style.format_index(hyperlinks="html")

rendered = f'<a href="{found}" target="_blank">{found}</a>'
result = styler.to_html()
result = str(styler.to_html())
assert (rendered in result) is exp
assert (text in result) is not exp # test conversion done when expected and not

Expand All @@ -812,7 +816,7 @@ def test_multiple_rendered_links():
links = ("www.a.b", "http://a.c", "https://a.d", "ftp://a.e")
# pylint: disable-next=consider-using-f-string
df = DataFrame(["text {} {} text {} {}".format(*links)])
result = df.style.format(hyperlinks="html").to_html()
result = str(df.style.format(hyperlinks="html").to_html())
href = '<a href="{0}" target="_blank">{0}</a>'
for link in links:
assert href.format(link) in result
Expand Down
24 changes: 13 additions & 11 deletions pandas/tests/io/formats/style/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_render_empty_mi():
</thead>
"""
)
assert expected in df.style.to_html()
assert expected in str(df.style.to_html())


@pytest.mark.parametrize("comprehensive", [True, False])
Expand Down Expand Up @@ -505,7 +505,7 @@ def test_multiple_render(self, df):
s.to_html() # do 2 renders to ensure css styles not duplicated
assert (
'<style type="text/css">\n#T__row0_col0, #T__row1_col0 {\n'
" color: red;\n}\n</style>" in s.to_html()
" color: red;\n}\n</style>" in str(s.to_html())
)

def test_render_empty_dfs(self):
Expand Down Expand Up @@ -792,7 +792,7 @@ def test_init_with_na_rep(self):

def test_caption(self, df):
styler = Styler(df, caption="foo")
result = styler.to_html()
result = str(styler.to_html())
assert all(["caption" in result, "foo" in result])

styler = df.style
Expand All @@ -802,7 +802,7 @@ def test_caption(self, df):

def test_uuid(self, df):
styler = Styler(df, uuid="abc123")
result = styler.to_html()
result = str(styler.to_html())
assert "abc123" in result

styler = df.style
Expand All @@ -813,7 +813,7 @@ def test_uuid(self, df):
def test_unique_id(self):
# See https://github.com/pandas-dev/pandas/issues/16780
df = DataFrame({"a": [1, 3, 5, 6], "b": [2, 4, 12, 21]})
result = df.style.to_html(uuid="test")
result = str(df.style.to_html(uuid="test"))
assert "test" in result
ids = re.findall('id="(.*?)"', result)
assert np.unique(ids).size == len(ids)
Expand Down Expand Up @@ -880,7 +880,7 @@ def test_maybe_convert_css_to_tuples_err(self):
def test_table_attributes(self, df):
attributes = 'class="foo" data-bar'
styler = Styler(df, table_attributes=attributes)
result = styler.to_html()
result = str(styler.to_html())
assert 'class="foo" data-bar' in result

result = df.style.set_table_attributes(attributes).to_html()
Expand Down Expand Up @@ -1258,13 +1258,15 @@ def test_no_cell_ids(self):
def test_set_data_classes(self, classes):
# GH 36159
df = DataFrame(data=[[0, 1], [2, 3]], columns=["A", "B"], index=["a", "b"])
s = Styler(df, uuid_len=0, cell_ids=False).set_td_classes(classes).to_html()
s = str(
Styler(df, uuid_len=0, cell_ids=False).set_td_classes(classes).to_html()
)
assert '<td class="data row0 col0" >0</td>' in s
assert '<td class="data row0 col1 test-class" >1</td>' in s
assert '<td class="data row1 col0" >2</td>' in s
assert '<td class="data row1 col1" >3</td>' in s
# GH 39317
s = Styler(df, uuid_len=0, cell_ids=True).set_td_classes(classes).to_html()
s = str(Styler(df, uuid_len=0, cell_ids=True).set_td_classes(classes).to_html())
assert '<td id="T__row0_col0" class="data row0 col0" >0</td>' in s
assert '<td id="T__row0_col1" class="data row0 col1 test-class" >1</td>' in s
assert '<td id="T__row1_col0" class="data row1 col0" >2</td>' in s
Expand All @@ -1280,7 +1282,7 @@ def test_set_data_classes_reindex(self):
columns=[0, 2],
index=[0, 2],
)
s = Styler(df, uuid_len=0).set_td_classes(classes).to_html()
s = str(Styler(df, uuid_len=0).set_td_classes(classes).to_html())
assert '<td id="T__row0_col0" class="data row0 col0 mi" >0</td>' in s
assert '<td id="T__row0_col2" class="data row0 col2 ma" >2</td>' in s
assert '<td id="T__row1_col1" class="data row1 col1" >4</td>' in s
Expand All @@ -1303,11 +1305,11 @@ def test_column_and_row_styling(self):
df = DataFrame(data=[[0, 1], [1, 2]], columns=["A", "B"])
s = Styler(df, uuid_len=0)
s = s.set_table_styles({"A": [{"selector": "", "props": [("color", "blue")]}]})
assert "#T_ .col0 {\n color: blue;\n}" in s.to_html()
assert "#T_ .col0 {\n color: blue;\n}" in str(s.to_html())
s = s.set_table_styles(
{0: [{"selector": "", "props": [("color", "blue")]}]}, axis=1
)
assert "#T_ .row0 {\n color: blue;\n}" in s.to_html()
assert "#T_ .row0 {\n color: blue;\n}" in str(s.to_html())

@pytest.mark.parametrize("len_", [1, 5, 32, 33, 100])
def test_uuid_len(self, len_):
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/io/formats/style/test_to_latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,10 @@ def test_multiindex_columns_hidden():
df = DataFrame([[1, 2, 3, 4]])
df.columns = MultiIndex.from_tuples([("A", 1), ("A", 2), ("A", 3), ("B", 1)])
s = df.style
assert "{tabular}{lrrrr}" in s.to_latex()
assert "{tabular}{lrrrr}" in str(s.to_latex())
s.set_table_styles([]) # reset the position command
s.hide([("A", 2)], axis="columns")
assert "{tabular}{lrrr}" in s.to_latex()
assert "{tabular}{lrrr}" in str(s.to_latex())


@pytest.mark.parametrize(
Expand Down Expand Up @@ -851,7 +851,7 @@ def test_rendered_links():
# note the majority of testing is done in test_html.py: test_rendered_links
# these test only the alternative latex format is functional
df = DataFrame(["text www.domain.com text"])
result = df.style.format(hyperlinks="latex").to_latex()
result = str(df.style.format(hyperlinks="latex").to_latex())
assert r"text \href{www.domain.com}{www.domain.com} text" in result


Expand Down Expand Up @@ -898,7 +898,7 @@ def test_clines_validation(clines, styler):
@pytest.mark.parametrize("env", ["table", "longtable"])
def test_clines_index(clines, exp, env):
df = DataFrame([[1], [2], [3], [4]])
result = df.style.to_latex(clines=clines, environment=env)
result = str(df.style.to_latex(clines=clines, environment=env))
expected = f"""\
0 & 1 \\\\{exp}
1 & 2 \\\\{exp}
Expand Down Expand Up @@ -988,7 +988,7 @@ def test_clines_multiindex(clines, expected, env):
styler = df.style
styler.hide([("-", 0, "X"), ("-", 0, "Y")])
styler.hide(level=1)
result = styler.to_latex(clines=clines, environment=env)
result = str(styler.to_latex(clines=clines, environment=env))
assert expected in result


Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ def test_repr_float_format_in_object_col(self, float_format, expected):
def test_dict_entries(self):
df = DataFrame({"A": [{"a": 1, "b": 2}]})

val = df.to_string()
val = str(df.to_string())
assert "'a': 1" in val
assert "'b': 2" in val

Expand Down Expand Up @@ -2418,7 +2418,7 @@ def test_datetimeindex(self):

index = date_range("20130102", periods=6)
s = Series(1, index=index)
result = s.to_string()
result = str(s.to_string())
assert "2013-01-02" in result

# nat in index
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def test_to_html_truncation_index_false_max_cols(
@pytest.mark.parametrize("notebook", [True, False])
def test_to_html_notebook_has_style(notebook):
df = DataFrame({"A": [1, 2, 3]})
result = df.to_html(notebook=notebook)
result = str(df.to_html(notebook=notebook))

if notebook:
assert "tbody tr th:only-of-type" in result
Expand All @@ -725,14 +725,14 @@ def test_to_html_notebook_has_style(notebook):
def test_to_html_with_index_names_false():
# GH 16493
df = DataFrame({"A": [1, 2]}, index=Index(["a", "b"], name="myindexname"))
result = df.to_html(index_names=False)
result = str(df.to_html(index_names=False))
assert "myindexname" not in result


def test_to_html_with_id():
# GH 8496
df = DataFrame({"A": [1, 2]}, index=Index(["a", "b"], name="myindexname"))
result = df.to_html(index_names=False, table_id="TEST_ID")
result = str(df.to_html(index_names=False, table_id="TEST_ID"))
assert ' id="TEST_ID"' in result


Expand Down Expand Up @@ -799,8 +799,8 @@ def test_to_html_round_column_headers():
# GH 17280
df = DataFrame([1], columns=[0.55555])
with option_context("display.precision", 3):
html = df.to_html(notebook=False)
notebook = df.to_html(notebook=True)
html = str(df.to_html(notebook=False))
notebook = str(df.to_html(notebook=True))
assert "0.55555" in html
assert "0.556" in notebook

Expand Down
14 changes: 7 additions & 7 deletions pandas/tests/io/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,18 +1121,18 @@ def test_to_html_timestamp(self):
rng = date_range("2000-01-01", periods=10)
df = DataFrame(np.random.randn(10, 4), index=rng)

result = df.to_html()
result = str(df.to_html())
assert "2000-01-01" in result

def test_to_html_borderless(self):
df = DataFrame([{"A": 1, "B": 2}])
out_border_default = df.to_html()
out_border_true = df.to_html(border=True)
out_border_explicit_default = df.to_html(border=1)
out_border_nondefault = df.to_html(border=2)
out_border_zero = df.to_html(border=0)
out_border_default = str(df.to_html())
out_border_true = str(df.to_html(border=True))
out_border_explicit_default = str(df.to_html(border=1))
out_border_nondefault = str(df.to_html(border=2))
out_border_zero = str(df.to_html(border=0))

out_border_false = df.to_html(border=False)
out_border_false = str(df.to_html(border=False))

assert ' border="1"' in out_border_default
assert out_border_true == out_border_default
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ disable = [
"ungrouped-imports",
"unsubscriptable-object",
"unsupported-assignment-operation",
"unsupported-membership-test",
"unused-import",
"use-implicit-booleaness-not-comparison",
"use-implicit-booleaness-not-len",
Expand Down