Skip to content

Commit c1b191e

Browse files
author
MarcoGorelli
committed
fixup b005 errors
1 parent c96cd9b commit c1b191e

File tree

6 files changed

+69
-5
lines changed

6 files changed

+69
-5
lines changed

doc/source/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,9 @@ class AccessorCallableDocumenter(AccessorLevelDocumenter, MethodDocumenter):
583583
priority = 0.5
584584

585585
def format_name(self):
586-
return MethodDocumenter.format_name(self).rstrip(".__call__")
586+
return pandas.util._str_methods.removesuffix(
587+
MethodDocumenter.format_name(self), ".__call__"
588+
)
587589

588590

589591
class PandasAutosummary(Autosummary):

pandas/core/ops/common.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
from pandas._libs.lib import item_from_zerodim
1010
from pandas._libs.missing import is_matching_na
1111
from pandas._typing import F
12+
from pandas.util._str_methods import (
13+
removeprefix,
14+
removesuffix,
15+
)
1216

1317
from pandas.core.dtypes.generic import (
1418
ABCDataFrame,
@@ -52,7 +56,8 @@ def _unpack_zerodim_and_defer(method, name: str):
5256
-------
5357
method
5458
"""
55-
is_cmp = name.strip("__") in {"eq", "ne", "lt", "le", "gt", "ge"}
59+
stripped_name = removesuffix(removeprefix(name, "__"), "__")
60+
is_cmp = stripped_name in {"eq", "ne", "lt", "le", "gt", "ge"}
5661

5762
@wraps(method)
5863
def new_method(self, other):

pandas/tests/io/test_sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ def test_get_schema2(self, test_frame1):
15871587
def _get_sqlite_column_type(self, schema, column):
15881588

15891589
for col in schema.split("\n"):
1590-
if col.split()[0].strip('""') == column:
1590+
if col.split()[0].strip('"') == column:
15911591
return col.split()[1]
15921592
raise ValueError(f"Column {column} not found")
15931593

pandas/tests/util/test_str_methods.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import pytest
2+
3+
from pandas.util._str_methods import (
4+
removeprefix,
5+
removesuffix,
6+
)
7+
8+
9+
@pytest.mark.parametrize(
10+
"string, prefix, expected",
11+
(
12+
("wildcat", "wild", "cat"),
13+
("blackbird", "black", "bird"),
14+
("housefly", "house", "fly"),
15+
("ladybug", "lady", "bug"),
16+
("rattlesnake", "rattle", "snake"),
17+
("baboon", "badger", "baboon"),
18+
("quetzal", "elk", "quetzal"),
19+
),
20+
)
21+
def test_remove_prefix(string, prefix, expected):
22+
result = removeprefix(string, prefix)
23+
assert result == expected
24+
25+
26+
@pytest.mark.parametrize(
27+
"string, suffix, expected",
28+
(
29+
("wildcat", "cat", "wild"),
30+
("blackbird", "bird", "black"),
31+
("housefly", "fly", "house"),
32+
("ladybug", "bug", "lady"),
33+
("rattlesnake", "snake", "rattle"),
34+
("seahorse", "horse", "sea"),
35+
("baboon", "badger", "baboon"),
36+
("quetzal", "elk", "quetzal"),
37+
),
38+
)
39+
def test_remove_suffix(string, suffix, expected):
40+
result = removesuffix(string, suffix)
41+
assert result == expected

pandas/util/_str_methods.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""
2+
Python3.9 introduces removesuffix and remove prefix.
3+
4+
They're reimplemented here for use in Python3.8.
5+
"""
6+
from __future__ import annotations
7+
8+
9+
def removesuffix(string: str, suffix: str) -> str:
10+
if string.endswith(suffix):
11+
return string[: -len(suffix)]
12+
return string
13+
14+
15+
def removeprefix(string: str, prefix: str) -> str:
16+
if string.startswith(prefix):
17+
return string[len(prefix) :]
18+
return string

setup.cfg

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,6 @@ ignore =
192192
# found modulo formatter (incorrect picks up mod operations)
193193
S001,
194194
# controversial
195-
B005,
196-
# controversial
197195
B006,
198196
# controversial
199197
B007,

0 commit comments

Comments
 (0)