Skip to content

Commit

Permalink
Update flake8 settings (#4038)
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Jul 17, 2022
1 parent 3c64b5c commit 396018b
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 45 deletions.
17 changes: 11 additions & 6 deletions py-polars/.flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
[flake8]
# just stop shouting as black decides line lengths.
max-line-length = 180
# E203, W503: due to black fmt
ignore = E203,W503
exclude = docs, venv, target

# Satisfy black: https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
# TODO: Handle long lines adequately
max-line-length = 160
extend-ignore = E203
per-file-ignores =
__init__.py:F401
tests/*.py: E101, W191
extend-exclude =
# Automatically generated test artifacts
venv/,
target/,
18 changes: 4 additions & 14 deletions py-polars/polars/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# flake8: noqa
import warnings

try:
from polars.polars import version
except ImportError as e: # pragma: no cover
except ImportError: # pragma: no cover

def version() -> str:
return ""
Expand All @@ -12,10 +11,7 @@ def version() -> str:
warnings.warn("polars binary missing!")

import polars.testing as testing
from polars.cfg import ( # flake8: noqa. We do not export in __all__
Config,
toggle_string_cache,
)
from polars.cfg import Config, toggle_string_cache # We do not export in __all__
from polars.convert import (
from_arrow,
from_dict,
Expand Down Expand Up @@ -61,10 +57,7 @@ def version() -> str:
ShapeError,
)
from polars.internals.expr import Expr
from polars.internals.frame import ( # flake8: noqa # TODO: remove need for wrap_df
DataFrame,
wrap_df,
)
from polars.internals.frame import DataFrame, wrap_df # TODO: remove need for wrap_df
from polars.internals.functions import concat, date_range, get_dummies
from polars.internals.io import read_ipc_schema, read_parquet_schema
from polars.internals.lazy_frame import LazyFrame
Expand Down Expand Up @@ -113,10 +106,7 @@ def version() -> str:
)
from polars.internals.lazy_functions import to_list as list
from polars.internals.lazy_functions import var
from polars.internals.series import ( # flake8: noqa # TODO: remove need for wrap_s
Series,
wrap_s,
)
from polars.internals.series import Series, wrap_s # TODO: remove need for wrap_s
from polars.internals.whenthen import when
from polars.io import (
read_avro,
Expand Down
7 changes: 6 additions & 1 deletion py-polars/polars/_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ def __exit__(


class HTMLFormatter:
def __init__(self, df: DataFrame, max_cols: int = 75, max_rows: int = 40): # type: ignore # noqa
def __init__(
self,
df: DataFrame, # type: ignore[name-defined] # noqa: F821
max_cols: int = 75,
max_rows: int = 40,
):
self.df = df
self.elements: list[str] = []
self.max_cols = max_cols
Expand Down
1 change: 0 additions & 1 deletion py-polars/polars/internals/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa
"""
The modules within `polars.internals` are interdependent. To prevent cyclical imports, they all import from each other
via this __init__ file using `import polars.internals as pli`. The imports below are being shared across this module.
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/internals/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ def write_json(

def to_pandas(
self, *args: Any, date_as_object: bool = False, **kwargs: Any
) -> pd.DataFrame: # noqa: F821
) -> pd.DataFrame:
"""
Cast to a pandas DataFrame.
This requires that pandas and pyarrow are installed.
Expand Down
2 changes: 0 additions & 2 deletions py-polars/tests/io/test_avro.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# flake8: noqa: W191,E101
from __future__ import annotations

import os
from typing import List

import pytest

Expand Down
1 change: 0 additions & 1 deletion py-polars/tests/io/test_csv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa: W191,E101
from __future__ import annotations

import gzip
Expand Down
2 changes: 0 additions & 2 deletions py-polars/tests/io/test_ipc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# flake8: noqa: W191,E101
from __future__ import annotations

import io
import os
from pathlib import Path
from typing import List

import pandas as pd
import pytest
Expand Down
3 changes: 0 additions & 3 deletions py-polars/tests/io/test_json.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# flake8: noqa: W191,E101
from __future__ import annotations

import io
import os

import pytest

import polars as pl


Expand Down
2 changes: 0 additions & 2 deletions py-polars/tests/io/test_lazy_csv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# flake8: noqa: W191,E101
from __future__ import annotations

import io
from os import path
from pathlib import Path

Expand Down
1 change: 0 additions & 1 deletion py-polars/tests/io/test_lazy_ipc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa: W191,E101
from __future__ import annotations

import polars as pl
Expand Down
1 change: 0 additions & 1 deletion py-polars/tests/io/test_lazy_parquet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa: W191,E101
from __future__ import annotations

from os import path
Expand Down
1 change: 0 additions & 1 deletion py-polars/tests/io/test_other.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa: W191,E101
from __future__ import annotations

import copy
Expand Down
2 changes: 0 additions & 2 deletions py-polars/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# flake8: noqa: W191,E101
from __future__ import annotations

import io
import os
from typing import List

import numpy as np
import pandas as pd
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_read_sql() -> None:
import tempfile

try:
import connectorx # noqa
import connectorx # noqa: F401

with tempfile.TemporaryDirectory() as tmpdir_name:
test_db = os.path.join(tmpdir_name, "test.db")
Expand Down
11 changes: 5 additions & 6 deletions py-polars/tests/test_df.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# flake8: noqa: W191,E101
from __future__ import annotations

import sys
import typing
from builtins import range
from datetime import date, datetime, timedelta
from io import BytesIO
from typing import Any, Iterator, Type
from typing import Any, Iterator
from unittest.mock import patch

import numpy as np
Expand All @@ -24,7 +23,7 @@


def test_version() -> None:
_version = pl.__version__
pl.__version__


def test_null_count() -> None:
Expand Down Expand Up @@ -1622,7 +1621,7 @@ def test_apply_dataframe_return() -> None:
assert out.frame_equal(expected, null_equal=True)


def test_groupby_cat_list() -> None: # noqa: W191,E101
def test_groupby_cat_list() -> None:
grouped = (
pl.DataFrame(
[
Expand Down Expand Up @@ -2152,9 +2151,9 @@ def test_join_suffixes() -> None:

for how in ["left", "inner", "outer", "cross"]:
# no need for an assert, we error if wrong
_df = df_a.join(df_b, on="A", suffix="_y", how=how)["B_y"]
df_a.join(df_b, on="A", suffix="_y", how=how)["B_y"]

_df = df_a.join_asof(df_b, on="A", suffix="_y")["B_y"]
df_a.join_asof(df_b, on="A", suffix="_y")["B_y"]


def test_preservation_of_subclasses() -> None:
Expand Down

0 comments on commit 396018b

Please sign in to comment.