Skip to content

Commit

Permalink
Merge pull request pymc-labs#404 from pymc-labs/pre-commit-ci-update-…
Browse files Browse the repository at this point in the history
…config

[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
drbenvincent authored and arthurmello committed Sep 10, 2024
2 parents 4b0fcef + c8904f3 commit b3c00e4
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
exclude: &exclude_pattern 'iv_weak_instruments.ipynb'
args: ["--maxkb=1500"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.2
rev: v0.6.3
hooks:
# Run the linter
- id: ruff
Expand Down
182 changes: 182 additions & 0 deletions causalpy/data/gt_social_media_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
date,twitter,linkedin,tiktok,instagram
2022-05-15,55,9,23,59
2022-05-16,54,18,20,59
2022-05-17,54,20,23,57
2022-05-18,54,20,21,55
2022-05-19,49,23,21,52
2022-05-20,46,18,22,56
2022-05-21,51,9,23,58
2022-05-22,47,9,27,59
2022-05-23,45,19,21,58
2022-05-24,49,21,23,53
2022-05-25,55,21,21,61
2022-05-26,53,19,22,68
2022-05-27,52,16,23,52
2022-05-28,46,8,24,59
2022-05-29,45,7,22,56
2022-05-30,45,9,24,61
2022-05-31,46,19,20,58
2022-06-01,51,21,22,56
2022-06-02,47,19,22,54
2022-06-03,46,17,21,56
2022-06-04,45,9,23,58
2022-06-05,47,9,23,60
2022-06-06,48,20,21,58
2022-06-07,46,23,21,57
2022-06-08,48,22,24,56
2022-06-09,48,20,23,55
2022-06-10,48,17,22,56
2022-06-11,47,9,25,54
2022-06-12,46,9,24,56
2022-06-13,46,20,22,54
2022-06-14,46,21,23,58
2022-06-15,47,21,23,58
2022-06-16,46,21,24,56
2022-06-17,51,17,23,57
2022-06-18,44,9,24,54
2022-06-19,43,8,26,59
2022-06-20,45,16,25,53
2022-06-21,53,23,24,56
2022-06-22,48,21,25,58
2022-06-23,48,22,26,55
2022-06-24,54,18,24,56
2022-06-25,54,9,25,57
2022-06-26,48,8,23,62
2022-06-27,51,19,24,58
2022-06-28,54,21,25,56
2022-06-29,49,20,25,61
2022-06-30,53,19,27,58
2022-07-01,56,17,26,55
2022-07-02,47,8,25,56
2022-07-03,49,8,28,58
2022-07-04,47,9,25,58
2022-07-05,52,20,22,61
2022-07-06,49,20,27,60
2022-07-07,49,21,26,56
2022-07-08,58,17,27,53
2022-07-09,61,10,30,55
2022-07-10,56,15,31,55
2022-07-11,59,27,27,55
2022-07-12,52,25,28,57
2022-07-13,54,25,26,55
2022-07-14,61,25,25,60
2022-07-15,51,22,25,58
2022-07-16,50,12,24,58
2022-07-17,53,13,28,57
2022-07-18,48,24,25,57
2022-07-19,50,26,25,57
2022-07-20,47,26,25,53
2022-07-21,49,24,26,55
2022-07-22,50,21,26,57
2022-07-23,47,9,26,55
2022-07-24,45,8,27,57
2022-07-25,47,19,26,59
2022-07-26,47,20,28,58
2022-07-27,47,20,27,56
2022-07-28,48,19,26,57
2022-07-29,47,18,27,58
2022-07-30,46,9,28,53
2022-07-31,48,9,27,58
2022-08-01,48,19,25,56
2022-08-02,51,21,25,56
2022-08-03,49,21,27,55
2022-08-04,47,20,24,54
2022-08-05,47,17,25,54
2022-08-06,47,10,26,57
2022-08-07,46,9,26,58
2022-08-08,46,19,24,59
2022-08-09,62,21,25,59
2022-08-10,52,20,25,56
2022-08-11,54,21,24,61
2022-08-12,60,18,24,59
2022-08-13,55,9,26,56
2022-08-14,52,9,25,55
2022-08-15,48,19,24,54
2022-08-16,49,21,27,55
2022-08-17,47,20,24,53
2022-08-18,45,19,24,53
2022-08-19,47,18,25,53
2022-08-20,47,9,25,54
2022-08-21,49,10,27,56
2022-08-22,44,20,23,55
2022-08-23,46,22,23,52
2022-08-24,49,22,23,52
2022-08-25,47,21,23,56
2022-08-26,56,17,23,54
2022-08-27,52,9,25,55
2022-08-28,51,9,26,57
2022-08-29,47,19,22,56
2022-08-30,47,21,22,52
2022-08-31,46,20,21,52
2022-09-01,47,18,22,55
2022-09-02,48,16,21,49
2022-09-03,50,8,24,52
2022-09-04,47,8,25,56
2022-09-05,48,10,27,56
2022-09-06,45,19,24,54
2022-09-07,49,20,21,54
2022-09-08,51,19,23,50
2022-09-09,49,16,21,52
2022-09-10,49,9,21,52
2022-09-11,52,9,22,55
2022-09-12,49,19,21,50
2022-09-13,54,21,20,52
2022-09-14,47,21,20,49
2022-09-15,45,20,30,51
2022-09-16,42,16,22,48
2022-09-17,47,9,23,52
2022-09-18,50,9,23,51
2022-09-19,48,20,21,48
2022-09-20,47,21,22,50
2022-09-21,47,22,23,51
2022-09-22,46,21,23,55
2022-09-23,46,18,21,49
2022-09-24,47,9,22,50
2022-09-25,48,9,23,53
2022-09-26,45,17,23,51
2022-09-27,46,20,23,47
2022-09-28,49,19,23,50
2022-09-29,45,18,30,56
2022-09-30,49,17,32,56
2022-10-01,47,9,36,64
2022-10-02,52,9,39,66
2022-10-03,53,19,31,60
2022-10-04,64,21,33,66
2022-10-05,58,20,34,68
2022-10-06,49,19,33,62
2022-10-07,51,17,22,49
2022-10-08,50,9,24,48
2022-10-09,52,9,22,52
2022-10-10,52,16,21,50
2022-10-11,51,20,22,50
2022-10-12,47,19,22,49
2022-10-13,46,20,23,48
2022-10-14,46,18,20,49
2022-10-15,49,9,22,48
2022-10-16,52,9,23,52
2022-10-17,47,19,22,52
2022-10-18,48,20,24,49
2022-10-19,46,19,24,50
2022-10-20,46,20,22,49
2022-10-21,49,18,22,47
2022-10-22,50,9,23,49
2022-10-23,58,8,22,53
2022-10-24,53,18,22,50
2022-10-25,53,21,22,50
2022-10-26,52,19,22,49
2022-10-27,56,19,28,49
2022-10-28,100,17,26,48
2022-10-29,75,8,25,49
2022-10-30,66,9,23,56
2022-10-31,69,17,21,83
2022-11-01,75,19,21,58
2022-11-02,64,21,23,51
2022-11-03,61,19,24,49
2022-11-04,76,17,28,52
2022-11-05,69,9,23,54
2022-11-06,62,8,25,51
2022-11-07,66,18,23,50
2022-11-08,60,18,24,47
2022-11-09,64,18,21,45
2022-11-10,61,19,22,49
2022-11-11,69,16,23,47
55 changes: 55 additions & 0 deletions causalpy/tests/test_api_stability.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2024 The PyMC Labs Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Tests API stability for specific external calls
"""

import matplotlib.pyplot as plt
import pandas as pd

import causalpy as cp
from causalpy.experiments.prepostfit import SyntheticControl
from causalpy.pymc_models import WeightedSumFitter


def test_causal_inference_and_discovery_with_python_example():
"""Test example used in Alexander Molak's book 'Causal Inference and Discovery in Python'
Chapter 11 (pages 304-307)
"""
data = pd.read_csv(r"./causalpy/data/gt_social_media_data.csv")
data.index = pd.to_datetime(data["date"])
data = data.drop("date", axis=1)
treatment_index = pd.to_datetime("2022-10-28")

# Build the model
model = cp.pymc_models.WeightedSumFitter()
assert isinstance(
model, WeightedSumFitter
), "model is not an instance of WeightedSumFitter"

formula = "twitter ~ 0 + tiktok + linkedin + instagram"

# Run the experiment and plot results
results = cp.pymc_experiments.SyntheticControl(
data,
treatment_index,
formula=formula,
model=model,
)
assert isinstance(
results, SyntheticControl
), "results is not an instance of SyntheticControl"

fig, ax = results.plot()
assert isinstance(fig, plt.Figure)
6 changes: 3 additions & 3 deletions docs/source/_static/interrogate_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b3c00e4

Please sign in to comment.