Skip to content

Commit

Permalink
lint: Fix misc lint problems (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjchambers authored Aug 4, 2023
1 parent d6bf2b2 commit 3266ee4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
4 changes: 2 additions & 2 deletions sparrow-py/.flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
select = B,B9,C,D,DAR,E,F,N,RST,W
ignore = E203,E501,RST201,RST203,RST301,W503
select = B,B9,C,D,DAR,E,F,N,W
ignore = E203,E501,W503
max-line-length = 100
max-complexity = 10
docstring-convention = numpy
Expand Down
2 changes: 2 additions & 0 deletions sparrow-py/pysrc/sparrow_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ._session import init_session
from ._windows import SinceWindow
from ._windows import SlidingWindow
from ._windows import Window


def record(fields: Dict[str, Expr]) -> Expr:
Expand All @@ -23,6 +24,7 @@ def record(fields: Dict[str, Expr]) -> Expr:
"Expr",
"init_session",
"record",
"Window",
"SinceWindow",
"SlidingWindow",
"sources",
Expand Down
26 changes: 11 additions & 15 deletions sparrow-py/pysrc/sparrow_py/_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
import sparrow_py as kt
import sparrow_py._ffi as _ffi

from ._result import Result
from ._windows import SinceWindow
from ._windows import SlidingWindow
from ._windows import Window


#: The type of arguments to expressions.
Arg = Union["Expr", int, str, float, None]
Expand Down Expand Up @@ -289,19 +284,21 @@ def is_not_null(self) -> "Expr":
"""Return a boolean expression indicating if the expression is not null."""
return Expr.call("is_valid", self)

def collect(self, max: Optional[int], window: Optional[Window] = None) -> "Expr":
def collect(
self, max: Optional[int], window: Optional["kt.Window"] = None
) -> "Expr":
"""Return an expression collecting the last `max` values in the `window`."""
return _aggregation("collect", self, window, max)

def sum(self, window: Optional[Window] = None) -> "Expr":
def sum(self, window: Optional["kt.Window"] = None) -> "Expr":
"""Return the sum aggregation of the expression."""
return _aggregation("sum", self, window)

def first(self, window: Optional[Window] = None) -> "Expr":
def first(self, window: Optional["kt.Window"] = None) -> "Expr":
"""Return the first aggregation of the expression."""
return _aggregation("first", self, window)

def last(self, window: Optional[Window] = None) -> "Expr":
def last(self, window: Optional["kt.Window"] = None) -> "Expr":
"""Return the last aggregation of the expression."""
return _aggregation("last", self, window)

Expand Down Expand Up @@ -339,10 +336,10 @@ def run_to_csv_string(self) -> str:


def _aggregation(
op: str, input: Expr, window: Optional[Window], *args: Optional[Arg]
op: str, input: Expr, window: Optional["kt.Window"], *args: Optional[Arg]
) -> Expr:
"""
Creates an aggregation.
Create the aggregation `op` with the given `input`, `window` and `args`.
Parameters
----------
Expand All @@ -361,10 +358,9 @@ def _aggregation(
Raises
------
UnimplementedError
NotImplementedError
If the window is not a known type.
"""

# Note: things would be easier if we had a more normal order, which
# we could do as part of "aligning" Sparrow signatures to the new direction.
# However, `collect` currently has `collect(max, input, window)`, requiring
Expand All @@ -373,7 +369,7 @@ def _aggregation(
return Expr.call(op, *args, input, None, None)
elif isinstance(window, kt.SinceWindow):
return Expr.call(op, *args, input, window._predicate, None)
elif isinstance(window, SlidingWindow):
elif isinstance(window, kt.SlidingWindow):
return Expr.call(op, *args, input, window._predicate, window._duration)
else:
raise UnimplementedError(f"Unknown window type {window!r}")
raise NotImplementedError(f"Unknown window type {window!r}")
4 changes: 2 additions & 2 deletions sparrow-py/pysrc/sparrow_py/sources/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
from typing import Optional

import pyarrow as pa
import sparrow_py as kt
import sparrow_py._ffi as _ffi

from .._expr import Expr
from .._session import _get_session


_TABLE_NUM: int = 0


class Source(kt.Expr):
class Source(Expr):
"""A source expression."""

# TODO: Clean-up naming on the FFI side.
Expand Down
6 changes: 3 additions & 3 deletions sparrow-py/pytests/collect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def source() -> kt.sources.CsvSource:


def test_collect_basic(source, golden) -> None:
"""Test we can collect values to a list"""
"""Test we can collect values to a list."""
m = source["m"]
n = source["n"]
golden(
Expand All @@ -37,7 +37,7 @@ def test_collect_basic(source, golden) -> None:


def test_collect_with_max(source, golden) -> None:
"""Test we can collect values to a list with a max"""
"""Test we can collect values to a list with a max."""
m = source["m"]
n = source["n"]
golden(
Expand All @@ -53,6 +53,6 @@ def test_collect_with_max(source, golden) -> None:


def test_collect_since_window(source, golden) -> None:
"""Test we can collect values to a list in a since window"""
"""Test we can collect values to a list in a since window."""
m = source["m"]
golden(kt.record({"m": m, "since_m": m.sum(window=kt.SinceWindow(m > 10))}))
5 changes: 1 addition & 4 deletions sparrow-py/pytests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def pytest_addoption(parser: pytest.Parser):


@pytest.fixture
def golden(request: pytest.FixtureRequest, pytestconfig: pytest.Config):
def golden(request: pytest.FixtureRequest, pytestconfig: pytest.Config): # noqa: C901
"""Test fixture for checking results against a golden file."""
output = 0

Expand Down Expand Up @@ -96,9 +96,6 @@ def handler(
)
else:
raise ValueError(f"Unknown format {format}")
print(df.iloc[:, 0])
print(df.dtypes)
print(correct.iloc[:, 0])
pd.testing.assert_frame_equal(df, correct)

return handler

0 comments on commit 3266ee4

Please sign in to comment.