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

Add ParetoNBDModel #177

Closed
wants to merge 2 commits into from
Closed
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
39 changes: 31 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,65 @@ on:
push:
branches: [main]

env:
OLDEST_PYMC_VERSION: "5.4.0"

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]

python-version: ["3.8", "3.11"]
oldest-pymc: [false, true]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install oldest version of PyMC
if: ${{ matrix.oldest-pymc }}
run: pip install pymc==${{ env.OLDEST_PYMC_VERSION }}
- name: Run lint
run: |
make init
make check_lint
run: make check_lint
- name: Check oldest version of PyMC
if: ${{ matrix.oldest-pymc }}
run: python -c "import pymc; assert pymc.__version__ == '${{ env.OLDEST_PYMC_VERSION }}'"

test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]

config: [ {python-version: "3.8", oldest-pymc: false}, {python-version: "3.11", oldest-pymc: true}]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.config.python-version }}
- name: Install oldest version of PyMC
if: ${{ matrix.config.oldest-pymc }}
run: pip install pymc==${{ env.OLDEST_PYMC_VERSION }}
- name: Run tests
run: |
pip install -e .[test]
pytest --cov-report=xml --no-cov-on-fail
- name: Check oldest version of PyMC
if: ${{ matrix.oldest-pymc }}
run: python -c "import pymc; assert pymc.__version__ == '${{ env.OLDEST_PYMC_VERSION }}'"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }} # use token for more robust uploads
name: ${{ matrix.python-version }}
fail_ci_if_error: false

all:
if: ${{ always() }}
runs-on: ubuntu-latest
name: All checks
needs: [ lint, test ]
steps:
- name: Confirm checks passed
if: ${{ (needs.lint.result != 'success' || needs.test.result != 'success') }}
run: exit 1
4 changes: 2 additions & 2 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ jobs:
path: dist
- uses: pypa/gh-action-pypi-publish@release/v1
with:
skip_existing: true
skip-existing: true
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
repository-url: https://test.pypi.org/legacy/
- uses: actions/setup-python@v4
with:
python-version: 3.8
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/rtd-link-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Read the Docs Pull Request Preview
on:
pull_request_target:
types:
- opened

permissions:
pull-requests: write

jobs:
documentation-links:
runs-on: ubuntu-latest
steps:
- uses: readthedocs/actions/preview@v1
with:
project-slug: "pymc-marketing"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,4 @@ dmypy.json
.vscode

# PyCharm .idea files
.idea/
.idea/
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ repos:
entry: isort --profile black
language: system
types: [python]
- id: mypy
name: mypy
entry: mypy
language: system
types: [python]
files: ^pymc_marketing/
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
Expand Down
172 changes: 172 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Guidelines for Contributing

PyMC-Marketing welcomes contributions from interested individuals or groups. These guidelines are provided to give potential contributors information to make their contribution compliant with the conventions of the PyMC-Marketing project, and maximize the probability of such contributions to be merged as quickly and efficiently as possible. Contributors need not be experts, but should be interested in the project, willing to learn, and share knowledge.

There are 4 main ways of contributing to the PyMC-Marketing project (in ascending order of difficulty or scope):

1. Submitting issues related to bugs or desired enhancements.
2. Contributing or improving the documentation (docs) or examples.
3. Fixing outstanding issues (bugs) with the existing codebase. They range from low-level software bugs to higher-level design problems.
4. Adding new or improved functionality to the existing codebase.

Items 2-4 require setting up a local development environment, see [Local development steps](#Contributing-code-via-pull-requests) for more information.

## Opening issues
We appreciate being notified of problems with the existing PyMC-Marketing code. We prefer that issues be filed the on [Github Issue Tracker](https://github.com/pymc-labs/pymc-marketing/issues), rather than on social media or by direct email to the developers.

Please verify that your issue is not being currently addressed by other issues or pull requests by using the GitHub search tool to look for key words in the project issue tracker.

## Contributing code via pull requests

While issue reporting is valuable, we strongly encourage users who are inclined to do so to submit patches for new or existing issues via pull requests. This is particularly the case for simple fixes, such as typos or tweaks to documentation, which do not require a heavy investment of time and attention.

Contributors are also encouraged to contribute new code to enhance PyMC-Marketing's functionality, via pull requests.

The preferred workflow for contributing to PyMC-Marketing is to fork the GitHub repository, clone it to your local machine, and develop on a feature branch.

For more instructions see the [Pull request checklist](#pull-request-checklist)

## Local development steps

1. If you have not already done so, fork the [project repository](https://github.com/pymc-labs/pymc-marketing) by clicking on the 'Fork' button near the top right of the main repository page. This creates a copy of the code under your GitHub user account.

1. Clone your fork of the `pymc-marketing` repo from your GitHub account to your local disk, and add the base repository as a remote:

```bash
git clone [email protected]:<your GitHub handle>/pymc-marketing.git
cd pymc-marketing
git remote add upstream [email protected]:pymc-labs/pymc-marketing.git
```

1. Create a feature branch (e.g. `my-feature`) to hold your development changes:

```bash
git checkout -b my-feature
```

Always use a feature branch. It's good practice to never routinely work on the `main` branch of any repository.

1. Create an environment. For example:

```bash
conda create -n pymc_marketing_env
```

Activate the environment.

```bash
conda activate pymc_marketing_env
```

Install the package (in editable mode) and its development dependencies:

```bash
make init
```

Set [pre-commit hooks](https://pre-commit.com/). First install pre-commit package (either `pip install pre-commit`, see the package's installation instructions). Alternatively you can run `make check_lint` which will install the `pre-commit` package. Then run this to set up the git hook scripts:

```bash
pre-commit install
```

1. You can then work on your changes locally, in your feature branch. Add changed files using `git add` and then `git commit` files:

```bash
git add modified_files
git commit -m "Message summarizing commit changes"
```

to record your changes locally.
After committing, it is a good idea to sync with the base repository in case there have been any changes:

```bash
git fetch upstream
git rebase upstream/main
```

Then push the changes to your GitHub account with:

```bash
git push -u origin my-feature
```

1. [Optionally] Build the docs locally. If you have changed any of the documentation, you can build it locally to check that it looks as expected.

```bash
make html
```

To delete all intermediate files and cached content and build the docs from scratch, run `make cleandocs` before `make html`

1. Before you submit a Pull request, follow the [Pull request checklist](#pull-request-checklist).

1. Finally, to submit a pull request, go to the GitHub web page of your fork of the PyMC-Marketing repo. Click the 'Pull request' button to send your changes to the project's maintainers for review. This will send an email to the committers.

## Pull request checklist

We recommend that your contribution complies with the following guidelines before you submit a pull request:

- If your pull request addresses an issue, please use the pull request title to describe the issue and mention the issue number in the pull request description. This will make sure a link back to the original issue is created.

- All public methods must have informative docstrings with sample usage when appropriate.

- To indicate a work in progress please mark the PR as `draft`. Drafts may be useful to (1) indicate you are working on something to avoid duplicated work, (2) request broad review of functionality or API, or (3) seek collaborators.

- All other tests pass when everything is rebuilt from scratch.

- When adding additional functionality, either edit an existing example, or create a new example (typically in the form of a Jupyter Notebook) in the `pymc-marketing/docs/source/mmm` or `pymc-marketing/docs/source/clv` folders. Have a look at other examples for reference. Examples should demonstrate why the new functionality is useful in practice.

- Documentation and high-coverage tests are necessary for enhancements to be accepted.

- Documentation follows [NumPy style guide](https://numpydoc.readthedocs.io/en/latest/format.html)

- Run any of the pre-existing examples in `pymc-marketing/docs/source/*` that contain analyses that would be affected by your changes to ensure that nothing breaks. This is a useful opportunity to not only check your work for bugs that might not be revealed by unit test, but also to show how your contribution improves PyMC-Marketing for end users.

- Your code passes linting tests. Run the line below to check linting errors:

```bash
make check_lint
```
If you want to fix linting errors automatically, run

```bash
make lint
```

1. To run tests:

```bash
make test
```

6. To check code style:

```bash
make check_lint
```


## Overview of the MMM codebase

Packages

![](docs/source/uml/packages_mmm.png)

Classes

![](docs/source/uml/classes_mmm.png)

## Overview of the CLV codebase

Packages

![](docs/source/uml/packages_clv.png)

Classes

![](docs/source/uml/classes_clv.png)

---

This guide takes some inspiration from the [Bambi guide to contributing](https://github.com/bambinos/bambi/blob/main/docs/CONTRIBUTING.md)
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: init lint check_lint test
.PHONY: init lint check_lint test html cleandocs

init:
python -m pip install -e .
python3 -m pip install -e .

lint:
pip install .[lint]
Expand All @@ -13,12 +13,14 @@ check_lint:
flake8 .
isort --check-only .
black --diff --check --fast .
mypy .

test:
pip install .[test]
pytest

html:
pip install .[docs]
sphinx-build docs/source docs/build -b html

cleandocs:
Expand Down
Loading