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

Reformat the repository with Black #27

Merged
merged 1 commit into from
Jan 24, 2025
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
43 changes: 13 additions & 30 deletions benchmarks/california_housing.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,11 @@ def __init__(self, regressors: List[RegressorMixin]) -> None:
self._regressors = regressors

def predict(self, X):
return np.mean([
regressor.predict(X)
for regressor in self._regressors
])
return np.mean([regressor.predict(X) for regressor in self._regressors])


@parfun(
split=per_argument(dataframe=df_by_row),
combine_with=lambda regressors: MeanRegressor(list(regressors)),
)
def train_regressor(
dataframe: pd.DataFrame, feature_names: List[str], target_name: str
) -> RegressorMixin:
@parfun(split=per_argument(dataframe=df_by_row), combine_with=lambda regressors: MeanRegressor(list(regressors)))
def train_regressor(dataframe: pd.DataFrame, feature_names: List[str], target_name: str) -> RegressorMixin:

regressor = DecisionTreeRegressor()
regressor.fit(dataframe[feature_names], dataframe[[target_name]])
Expand All @@ -52,17 +44,8 @@ def train_regressor(
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("n_workers", action="store", type=int)
parser.add_argument(
"--backend",
type=str,
choices=BACKEND_REGISTRY.keys(),
default="local_multiprocessing",
)
parser.add_argument(
"--backend_args",
type=str,
default="{}",
)
parser.add_argument("--backend", type=str, choices=BACKEND_REGISTRY.keys(), default="local_multiprocessing")
parser.add_argument("--backend_args", type=str, default="{}")

args = parser.parse_args()

Expand All @@ -79,10 +62,10 @@ def train_regressor(
with set_parallel_backend_context("local_single_process"):
regressor = train_regressor(dataframe, feature_names, target_name)

duration = timeit.timeit(
lambda: train_regressor(dataframe, feature_names, target_name),
number=N_MEASURES
) / N_MEASURES
duration = (
timeit.timeit(lambda: train_regressor(dataframe, feature_names, target_name), number=N_MEASURES)
/ N_MEASURES
)

print("Duration sequential:", duration)

Expand All @@ -91,9 +74,9 @@ def train_regressor(
with set_parallel_backend_context(args.backend, **backend_args):
regressor = train_regressor(dataframe, feature_names, target_name)

duration = timeit.timeit(
lambda: train_regressor(dataframe, feature_names, target_name),
number=N_MEASURES
) / N_MEASURES
duration = (
timeit.timeit(lambda: train_regressor(dataframe, feature_names, target_name), number=N_MEASURES)
/ N_MEASURES
)

print("Duration parallel:", duration)
7 changes: 1 addition & 6 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.doctest",
"sphinx_substitution_extensions",
"sphinx.ext.napoleon",
]
extensions = ["sphinx.ext.autodoc", "sphinx.ext.doctest", "sphinx_substitution_extensions", "sphinx.ext.napoleon"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
2 changes: 1 addition & 1 deletion parfun/about.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "7.0.7"
__version__ = "7.0.8"
3 changes: 1 addition & 2 deletions parfun/backend/scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ def __setstate__(self, state: dict) -> None:
self._client_kwargs = state["client_kwargs"]

self._client_pool = ScalerClientPool(
scheduler_address=self._scheduler_address,
client_kwargs=self._client_kwargs,
scheduler_address=self._scheduler_address, client_kwargs=self._client_kwargs
)

def session(self) -> ScalerSession:
Expand Down
8 changes: 4 additions & 4 deletions tests/backend/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def test_task_duration(self):
futures: Deque[ProfiledFuture] = deque()
total_task_duration = 0

with profile() as process_time, \
profile(time.perf_counter_ns) as eslaped_time, \
self.backend().session() as session:
with profile() as process_time, profile(
time.perf_counter_ns
) as eslaped_time, self.backend().session() as session:
i = 0
current_concurrency = 0
while i < ITERATIONS:
Expand All @@ -142,7 +142,7 @@ def test_task_duration(self):
delta = measured_duration * TOLERANCE

if abs(measured_duration - total_task_duration) < delta:
warnings.warn(f"Excpected execution duration of {total_task_duration} ns, measured {measured_duration} ns.")
warnings.warn(f"Expected execution duration of {total_task_duration} ns, measured {measured_duration} ns.")

def test_supports_nested_tasks(self):
"""Validates that the backend supports nested tasks if it reports it."""
Expand Down
1 change: 1 addition & 0 deletions tests/backend/test_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

try:
from parfun.backend.dask import DaskLocalClusterBackend, DaskRemoteClusterBackend

dask_available = True
except ImportError:
dask_available = False
Expand Down
2 changes: 2 additions & 0 deletions tests/backend/test_scaler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import unittest

from parfun.backend.mixins import BackendEngine

try:
from parfun.backend.scaler import ScalerLocalBackend, ScalerRemoteBackend

scaler_installed = True
except ImportError:
scaler_installed = False
Expand Down
5 changes: 4 additions & 1 deletion tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
from parfun.combine.dataframe import df_concat
from parfun.decorators import parfun
from parfun.entry_point import (
BACKEND_REGISTRY, get_parallel_backend, set_parallel_backend, set_parallel_backend_context
BACKEND_REGISTRY,
get_parallel_backend,
set_parallel_backend,
set_parallel_backend_context,
)
from parfun.partition.api import multiple_arguments, per_argument
from parfun.partition.collection import list_by_chunk
Expand Down
Loading