Skip to content

STY: enable subset of flake8-bugbear #40743

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

Merged
merged 1 commit into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ repos:
rev: 3.9.0
hooks:
- id: flake8
additional_dependencies: [flake8-comprehensions>=3.1.0]
additional_dependencies: [flake8-comprehensions>=3.1.0, flake8-bugbear>=21.3.2]
- id: flake8
name: flake8 (cython)
types: [cython]
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies:
- black=20.8b1
- cpplint
- flake8
- flake8-bugbear>=21.3.2 # used by flake8, find likely bugs
- flake8-comprehensions>=3.1.0 # used by flake8, linting of unnecessary comprehensions
- isort>=5.2.1 # check that imports are in the right order
- mypy=0.812
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def get_callable_name(obj):
if isinstance(obj, partial):
return get_callable_name(obj.func)
# fall back to class name
if hasattr(obj, "__call__"):
if callable(obj):
return type(obj).__name__
# everything failed (probably because the argument
# wasn't actually callable); we return None
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ def _is_dtype(arr_or_dtype, condition) -> bool:
return False
try:
dtype = get_dtype(arr_or_dtype)
except (TypeError, ValueError, UnicodeEncodeError):
except (TypeError, ValueError):
return False
return condition(dtype)

Expand Down Expand Up @@ -1651,7 +1651,7 @@ def _is_dtype_type(arr_or_dtype, condition) -> bool:

try:
tipo = pandas_dtype(arr_or_dtype).type
except (TypeError, ValueError, UnicodeEncodeError):
except (TypeError, ValueError):
if is_scalar(arr_or_dtype):
return condition(type(None))

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/reshape/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def _convert_by(by):
elif (
is_scalar(by)
or isinstance(by, (np.ndarray, Index, ABCSeries, Grouper))
or hasattr(by, "__call__")
or callable(by)
):
by = [by]
else:
Expand Down
5 changes: 1 addition & 4 deletions pandas/tests/frame/methods/test_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,7 @@ def test_to_csv_dups_cols(self):
[df_float, df_int, df_bool, df_object, df_dt], axis=1, ignore_index=True
)

cols = []
for i in range(5):
cols.extend([0, 1, 2])
df.columns = cols
df.columns = [0, 1, 2] * 5

with tm.ensure_clean() as filename:
df.to_csv(filename)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/categorical/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ def test_get_indexer_non_unique(self):
for indexer in [idx2, list("abf"), Index(list("abf"))]:
msg = "Reindexing only valid with uniquely valued Index objects"
with pytest.raises(InvalidIndexError, match=msg):
idx1.get_indexer(idx2)
idx1.get_indexer(indexer)

r1, _ = idx1.get_indexer_non_unique(idx2)
r1, _ = idx1.get_indexer_non_unique(indexer)
expected = np.array([0, 1, 2, -1], dtype=np.intp)
tm.assert_almost_equal(r1, expected)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/datetimes/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_where_other(self):
i = date_range("20130101", periods=3, tz="US/Eastern")

for arr in [np.nan, pd.NaT]:
result = i.where(notna(i), other=np.nan)
result = i.where(notna(i), other=arr)
expected = i
tm.assert_index_equal(result, expected)

Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/io/sas/test_sas7bdat.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ def test_iterator_loop(self):
# github #13654
for j in 0, 1:
for k in self.test_ix[j]:
for chunksize in 3, 5, 10, 11:
for chunksize in (3, 5, 10, 11):
fname = os.path.join(self.dirpath, f"test{k}.sas7bdat")
with pd.read_sas(fname, chunksize=10, encoding="utf-8") as rdr:
with pd.read_sas(
fname, chunksize=chunksize, encoding="utf-8"
) as rdr:
y = 0
for x in rdr:
y += x.shape[0]
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/resample/test_datetime_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ def test_resample_nunique():
assert expected.name == "ID"

for t in [r, g]:
result = r.ID.nunique()
result = t.ID.nunique()
tm.assert_series_equal(result, expected)

result = df.ID.resample("D").nunique()
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cython>=0.29.21
black==20.8b1
cpplint
flake8
flake8-bugbear>=21.3.2
flake8-comprehensions>=3.1.0
isort>=5.2.1
mypy==0.812
Expand Down
11 changes: 10 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ ignore =
W504, # line break after binary operator
E402, # module level import not at top of file
E731, # do not assign a lambda expression, use a def
S001 # found modulo formatter (incorrect picks up mod operations)
S001, # found modulo formatter (incorrect picks up mod operations)
B005, # controversial
B006, # controversial
B007, # controversial
B008, # controversial
B009, # setattr is used to side-step mypy
B010, # getattr is used to side-step mypy
B011, # tests use assert False
B015, # tests use comparisons but not their returned value
B301 # false positives
exclude =
doc/sphinxext/*.py,
doc/build/*.py,
Expand Down