Skip to content
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

[flake8] Enable flake8-bugbear extension #4073

Merged
merged 2 commits into from
Jul 19, 2022
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
1 change: 1 addition & 0 deletions py-polars/build.requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ isort~=5.10.1
mypy==0.961
ghp-import==2.1.0
flake8==4.0.1
flake8-bugbear==22.7.1
sphinx==4.2.0
pydata-sphinx-theme==0.6.3
sphinx-panels==0.6.0
Expand Down
6 changes: 3 additions & 3 deletions py-polars/polars/internals/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4053,8 +4053,8 @@ def drop(self: DF, name: str | list[str]) -> DF:
if isinstance(name, list):
df = self.clone()

for name in name:
df._df.drop_in_place(name)
for n in name:
df._df.drop_in_place(n)
return df

return self._from_pydf(self._df.drop(name))
Expand Down Expand Up @@ -4192,7 +4192,7 @@ def clone(self: DF) -> DF:
def __copy__(self: DF) -> DF:
return self.clone()

def __deepcopy__(self: DF, memodict: dict = {}) -> DF:
def __deepcopy__(self: DF, memo: None = None) -> DF:
return self.clone()

def get_columns(self) -> list[pli.Series]:
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/lazy_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ def clone(self: LDF) -> LDF:
def __copy__(self: LDF) -> LDF:
return self.clone()

def __deepcopy__(self: LDF, memodict: dict = {}) -> LDF:
def __deepcopy__(self: LDF, memo: None = None) -> LDF:
return self.clone()

def filter(self: LDF, predicate: pli.Expr | str) -> LDF:
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2433,7 +2433,7 @@ def clone(self) -> "Series":
def __copy__(self) -> Series:
return self.clone()

def __deepcopy__(self, memodict: Any = {}) -> Series:
def __deepcopy__(self, memo: None = None) -> Series:
return self.clone()

def fill_nan(self, fill_value: str | int | float | bool | pli.Expr) -> Series:
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def between(draw: Callable, type_: type, min_: Any, max_: Any) -> Any:
"""
Draw a value in a given range from a type-inferred strategy.
"""
strategy_init = getattr(from_type(type_), "function")
strategy_init = from_type(type_).function # type: ignore[attr-defined]
return draw(strategy_init(min_, max_))

@dataclass
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/db-benchmark/various.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_windows_not_cached() -> None:
)
)
# this might fail if they are cached
for i in range(1000):
for _ in range(1000):
ldf.collect()


Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_init_only_columns() -> None:
assert df.shape == (0, 4)
assert df.frame_equal(truth, null_equal=True)
assert df.dtypes == [pl.Date, pl.UInt64, pl.Int8, pl.List]
assert getattr(df.schema["d"], "inner") == pl.UInt8
assert df.schema["d"].inner == pl.UInt8 # type: ignore[attr-defined]

dfe = df.cleared()
assert (df.schema == dfe.schema) and (dfe.shape == df.shape)
Expand Down
4 changes: 2 additions & 2 deletions py-polars/tests/test_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_dtype() -> None:
a = pl.Series("a", [[1, 2, 3], [2, 5], [6, 7, 8, 9]])
assert a.dtype == pl.List
assert a.inner_dtype == pl.Int64
assert getattr(a.dtype, "inner") == pl.Int64
assert a.dtype.inner == pl.Int64 # type: ignore[attr-defined]

# explicit
df = pl.DataFrame(
Expand All @@ -84,7 +84,7 @@ def test_dtype() -> None:
"dt": pl.List(pl.Date),
"dtm": pl.List(pl.Datetime),
}
assert getattr(df.schema["i"], "inner") == pl.Int8
assert df.schema["i"].inner == pl.Int8 # type: ignore[attr-defined]
assert df.rows() == [
(
[1, 2, 3],
Expand Down
4 changes: 2 additions & 2 deletions py-polars/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,11 +1054,11 @@ def test_comparisons_bool_series_to_int() -> None:
with pytest.raises(
TypeError, match=r"'<' not supported between instances of 'Series' and 'int'"
):
srs_bool < 2
srs_bool < 2 # noqa: B015
with pytest.raises(
TypeError, match=r"'>' not supported between instances of 'Series' and 'int'"
):
srs_bool > 2
srs_bool > 2 # noqa: B015


def test_trigonometry_functions() -> None:
Expand Down
13 changes: 5 additions & 8 deletions py-polars/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,11 @@ def test_no_panic_on_nan_3067() -> None:
}
)

df.select([pl.col("total").shift().over("group")])["total"].to_list() == [
None,
1.0,
2.0,
None,
4.0,
5.0,
]
expected = [None, 1.0, 2.0, None, 4.0, 5.0]
assert (
df.select([pl.col("total").shift().over("group")])["total"].to_list()
== expected
)


def test_quantile_as_window() -> None:
Expand Down