From ef18a92c0650a5fe064cae3d87b0513c0085f4a9 Mon Sep 17 00:00:00 2001 From: juanitorduz Date: Mon, 6 Nov 2023 13:28:19 +0100 Subject: [PATCH] add ruff linter and formater --- .pre-commit-config.yaml | 17 ++++------------- README.md | 1 - pymc_marketing/__init__.py | 2 ++ pymc_marketing/clv/distributions.py | 3 +++ pymc_marketing/mmm/__init__.py | 14 ++++++++++++++ pymc_marketing/mmm/budget_optimizer.py | 1 - pyproject.toml | 24 ++++++------------------ tests/clv/models/test_basic.py | 1 - tests/clv/models/test_pareto_nbd.py | 1 - tests/mmm/test_base.py | 2 -- 10 files changed, 29 insertions(+), 37 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 997dc9b5..a4b4cabc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,18 +1,9 @@ repos: - - repo: https://github.com/psf/black - rev: 22.12.0 + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: v0.1.4 hooks: - - id: black - - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 - hooks: - - id: flake8 - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - args: [--profile, black] - types: [python] + - id: ruff + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.2.0 hooks: diff --git a/README.md b/README.md index 55f4b48c..0d262093 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ ![Build](https://github.com/pymc-labs/pymc-marketing/workflows/ci/badge.svg) [![codecov](https://codecov.io/gh/pymc-labs/pymc-marketing/branch/main/graph/badge.svg?token=OBV3BS5TYE)](https://codecov.io/gh/pymc-labs/pymc-marketing) [![docs](https://readthedocs.org/projects/pymc-marketing/badge/?version=latest)](https://docs.readthedocs.io/en/latest/) -[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![PyPI Version](https://img.shields.io/pypi/v/pymc-marketing.svg)](https://pypi.python.org/pypi/pymc-marketing) [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) diff --git a/pymc_marketing/__init__.py b/pymc_marketing/__init__.py index b4f2675a..72df9f8e 100644 --- a/pymc_marketing/__init__.py +++ b/pymc_marketing/__init__.py @@ -1,2 +1,4 @@ from pymc_marketing import clv, mmm from pymc_marketing.version import __version__ + +__all__ = ["clv", "mmm", "__version__"] diff --git a/pymc_marketing/clv/distributions.py b/pymc_marketing/clv/distributions.py index 7da83599..7143d650 100644 --- a/pymc_marketing/clv/distributions.py +++ b/pymc_marketing/clv/distributions.py @@ -89,6 +89,7 @@ class ContNonContract(PositiveContinuous): the easy way: An alternative to the Pareto/NBD model." Marketing science 24.2 (2005): 275-284. """ + rv_op = continuous_non_contractual @classmethod @@ -210,6 +211,7 @@ class ContContract(PositiveContinuous): ======== =============================================== """ + rv_op = continuous_contractual @classmethod @@ -387,6 +389,7 @@ class ParetoNBD(PositiveContinuous): "A Note on Deriving the Pareto/NBD Model and Related Expressions." http://brucehardie.com/notes/009/pareto_nbd_derivations_2005-11-05.pdf """ + rv_op = pareto_nbd @classmethod diff --git a/pymc_marketing/mmm/__init__.py b/pymc_marketing/mmm/__init__.py index 662604e7..ee1a3947 100644 --- a/pymc_marketing/mmm/__init__.py +++ b/pymc_marketing/mmm/__init__.py @@ -6,3 +6,17 @@ preprocessing_method_y, ) from pymc_marketing.mmm.validating import validation_method_X, validation_method_y + +__all__ = [ + "base", + "delayed_saturated_mmm", + "preprocessing", + "validating", + "MMM", + "BaseMMM", + "DelayedSaturatedMMM", + "preprocessing_method_X", + "preprocessing_method_y", + "validation_method_X", + "validation_method_y", +] diff --git a/pymc_marketing/mmm/budget_optimizer.py b/pymc_marketing/mmm/budget_optimizer.py index a423d805..a6047b44 100644 --- a/pymc_marketing/mmm/budget_optimizer.py +++ b/pymc_marketing/mmm/budget_optimizer.py @@ -192,7 +192,6 @@ def budget_allocator( parameters: Dict[str, Tuple[float, float]], budget_ranges: Optional[Dict[str, Tuple[float, float]]], ) -> DataFrame: - optimal_budget = optimize_budget_distribution( method=method, total_budget=total_budget, diff --git a/pyproject.toml b/pyproject.toml index fce29b4e..84b64708 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "pymc-marketing" description = "Marketing Statistical Models in PyMC" requires-python = ">=3.9" readme = "README.md" -license = {file = "LICENSE"} +license = { file = "LICENSE" } dynamic = ["version"] maintainers = [{ name = "PyMC Labs", email = "info@pymc-labs.io" }] @@ -35,22 +35,15 @@ docs = [ "sphinx-autodoc-typehints", "sphinxext-opengraph", "sphinx-notfound-page", - "sphinx-design" + "sphinx-design", ] lint = [ - "black>=22.3.0", - "flake8>=4.0.1", - "isort>=5.10.1", "mypy", "pandas-stubs", "pre-commit>=2.19.0", - "pylint" -] -test = [ - "lifetimes==0.11.3", - "pytest==7.0.1", - "pytest-cov==3.0.0" + "ruff>=0.1.4", ] +test = ["lifetimes==0.11.3", "pytest==7.0.1", "pytest-cov==3.0.0"] [tool.setuptools] packages = [ @@ -61,7 +54,7 @@ packages = [ ] [tool.setuptools.dynamic] -version = {file = "pymc_marketing/version.txt"} +version = { file = "pymc_marketing/version.txt" } [project.urls] repository = "https://github.com/pymc-labs/pymc-marketing" @@ -70,9 +63,6 @@ repository = "https://github.com/pymc-labs/pymc-marketing" #documentation = "" #changelog = "" -[tool.isort] -profile = "black" - [tool.pytest.ini_options] addopts = [ "-v", @@ -82,7 +72,5 @@ addopts = [ "--cov-report=term-missing", "--color=yes", ] -filterwarnings = [ - "ignore::DeprecationWarning:bokeh.core.property.primitive:37" -] +filterwarnings = ["ignore::DeprecationWarning:bokeh.core.property.primitive:37"] testpaths = "tests" diff --git a/tests/clv/models/test_basic.py b/tests/clv/models/test_basic.py index 1fb901a9..d27e27b9 100644 --- a/tests/clv/models/test_basic.py +++ b/tests/clv/models/test_basic.py @@ -125,7 +125,6 @@ def test_wrong_fit_method(self): ValueError, match=r"Fit method options are \['mcmc', 'map'\], got: wrong_method", ): - model.fit(fit_method="wrong_method") def test_sample_wihtout_build(self): diff --git a/tests/clv/models/test_pareto_nbd.py b/tests/clv/models/test_pareto_nbd.py index aec9c2ed..5c7581b4 100644 --- a/tests/clv/models/test_pareto_nbd.py +++ b/tests/clv/models/test_pareto_nbd.py @@ -300,7 +300,6 @@ def test_expected_purchase_probability(self, test_n, test_t): ], ) def test_posterior_distributions(self, fake_fit, T) -> None: - rng = np.random.default_rng(42) rtol = 0.45 dim_T = 2357 if T is None else len(T) diff --git a/tests/mmm/test_base.py b/tests/mmm/test_base.py index 5381aeff..c96eda4a 100644 --- a/tests/mmm/test_base.py +++ b/tests/mmm/test_base.py @@ -131,7 +131,6 @@ def test_init( toy_X, toy_y, ) -> None: - validate_channel_columns.configure_mock(_tags={"validation_X": True}) validate_date_col.configure_mock(_tags={"validation_X": True}) validate_target.configure_mock(_tags={"validation_y": True}) @@ -208,7 +207,6 @@ def transform(self, X): def test_validate_and_preprocess(toy_X, toy_y, test_mmm): - test_mmm test_mmm.validate("X", toy_X)