Skip to content

Commit

Permalink
chore: formatting and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBernstorff committed Oct 26, 2023
1 parent 2d6591a commit 437ccf9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ _build/
.vscode/

# MacOS
.DS_Store
.DS_Store
FunctionalPython.egg-info
2 changes: 0 additions & 2 deletions FunctionalPython/benchmark/query_1/input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,3 @@

if __name__ == "__main__":
data = Q1_DATA

pass
30 changes: 1 addition & 29 deletions FunctionalPython/benchmark/query_1/iterators_q1.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def parse_input_data(input_data: Sequence[Mapping[str, Any]]) -> Sequence[Item]:
tax=row["tax"],
returned=row["returned"],
line_status=LineStatus[row["line_status"].upper()],
cancelled=row["cancelled"],
),
)
.to_list()
Expand All @@ -90,35 +91,6 @@ def parse_input_data(input_data: Sequence[Mapping[str, Any]]) -> Sequence[Item]:
return parsed_data


def main_native(data: Sequence[Item]) -> Sequence[CategorySummary]:
filtered = filter(lambda x: x.ship_date <= dt.datetime(2000, 1, 1), data)
grouped = (
Group(group_id=key, group_contents=value)
for key, value in itertools.groupby(
filtered,
key=lambda row: f"status_{row.cancelled}_returned_{row.returned}",
)
)
summarised = map(summarise_category, grouped)

return list(summarised)


def main_inlined(data: Sequence[Item]) -> Sequence[CategorySummary]:
return list(
map(
summarise_category,
(
Group(group_id=key, group_contents=value)
for key, value in itertools.groupby(
filter(lambda x: x.ship_date <= dt.datetime(2000, 1, 1), data),
key=lambda row: f"status_{row.cancelled}_returned_{row.returned}",
)
),
)
)


def main_iterator(data: Sequence[Item]) -> Sequence[CategorySummary]:
sequence = (
Seq(data)
Expand Down
3 changes: 1 addition & 2 deletions FunctionalPython/benchmark/query_1/polars_q1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime as dt

import polars as pl

from FunctionalPython.benchmark.query_1.input_data import Q1_DATA
from FunctionalPython.benchmark.utils import benchmark_method

Expand Down Expand Up @@ -43,5 +44,3 @@ def main(data: pl.LazyFrame) -> pl.DataFrame:
query=main,
method_title="polars_q1",
)

pass
3 changes: 2 additions & 1 deletion FunctionalPython/benchmark/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import timeit
from collections.abc import Callable
from dataclasses import dataclass
from typing import Callable, Generic, TypeVar
from typing import Generic, TypeVar

from linetimer import CodeTimer

Expand Down
6 changes: 3 additions & 3 deletions FunctionalPython/sequence.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import itertools
from collections.abc import Iterable, Iterator, Sequence
from collections.abc import Callable, Iterable, Iterator, Sequence
from dataclasses import dataclass
from functools import reduce
from typing import Callable, Generic, TypeVar
from typing import Generic, TypeVar

_T0 = TypeVar("_T0")
_T1 = TypeVar("_T1")
Expand All @@ -11,7 +11,7 @@
@dataclass(frozen=True)
class Group(Generic[_T0]):
group_id: str
group_contents: "Seq[_T0]" | Iterable[_T0]
group_contents: "Seq[_T0]"


class Seq(Generic[_T0]):
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
linetimer
polars

0 comments on commit 437ccf9

Please sign in to comment.