Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] authored Aug 26, 2024
1 parent b66f517 commit a6ca571
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 149 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ readme.ipynb
#docs/site_libs
#site_libs
tests/.coverage

8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ repos:
- id: check-added-large-files

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.3
rev: 0.29.2
hooks:
- id: check-github-workflows
args: ["--verbose"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
rev: v0.6.2
hooks:
- id: ruff
args: ["--fix", "--output-format=full"]
- id: ruff-format

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.8.5
rev: 1.8.7
hooks:
- id: nbqa-ruff
args: ["--fix", "--output-format=full"]
files: ^docs/.*\.ipynb$

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.11.2
hooks:
- id: mypy
args: [--ignore-missing-imports]
Expand Down
9 changes: 4 additions & 5 deletions benchmarks/run_benchmarks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
"%autoreload 2\n",
"\n",
"import time\n",
"\n",
"import pandas as pd\n",
"import numpy as np\n",
"from pyfixest.estimation import feols, fepois\n",
"from tqdm import tqdm # note: tqdm is not a dependency of pyfixest\n",
"\n",
"from pyfixest.estimation import feols, fepois\n",
"\n",
"\n",
"def run_standard_benchmark(model, fixed_effect):\n",
" \"\"\"\n",
Expand All @@ -41,7 +42,6 @@
" Returns:\n",
" A pd.DataFrame with the results.\n",
" \"\"\"\n",
"\n",
" assert model in [\"feols\", \"fepois\"]\n",
" assert fixed_effect in [\"dum_1\", \"dum_1+dum_2\", \"dum_1+dum_2+dum_3\"]\n",
"\n",
Expand All @@ -58,7 +58,7 @@
" fml = f\"{fml_base} | {fixed_effect}\"\n",
"\n",
" # warmup\n",
" df = pd.read_stata(f\"./data/_STATA/base_s2_r1.dta\")\n",
" df = pd.read_stata(\"./data/_STATA/base_s2_r1.dta\")\n",
" feols(fml, data=df)\n",
"\n",
" for size in tqdm(range(1, 6)):\n",
Expand Down Expand Up @@ -98,7 +98,6 @@
" \"\"\"\n",
" Run all the benchmarks.\n",
" \"\"\"\n",
"\n",
" res = pd.DataFrame()\n",
" for model in [\"feols\", \"fepois\"]:\n",
" for fixef in [\"dum_1\", \"dum_1+dum_2\", \"dum_1+dum_2+dum_3\"]:\n",
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/visualise_benchmarks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import pandas as pd\n",
"from lets_plot import *\n",
"\n",
"LetsPlot.setup_html(no_js=True)"
Expand Down
72 changes: 21 additions & 51 deletions docs/compare-fixest-pyfixest.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"%autoreload 2\n",
"\n",
"# Get data using pyfixest\n",
"data = pf.get_data(model=\"Feols\", N=10_000, seed = 99292)"
"data = pf.get_data(model=\"Feols\", N=10_000, seed=99292)"
]
},
{
Expand Down Expand Up @@ -78,11 +78,7 @@
"metadata": {},
"outputs": [],
"source": [
"fit = pf.feols(\n",
" fml = \"Y ~ X1 + X2 | f1 + f2\",\n",
" data = data,\n",
" vcov = \"iid\"\n",
")"
"fit = pf.feols(fml=\"Y ~ X1 + X2 | f1 + f2\", data=data, vcov=\"iid\")"
]
},
{
Expand All @@ -99,10 +95,7 @@
"outputs": [],
"source": [
"fit_weights = pf.feols(\n",
" fml = \"Y ~ X1 + X2 | f1 + f2\",\n",
" data = data,\n",
" weights = \"weights\",\n",
" vcov = \"iid\"\n",
" fml=\"Y ~ X1 + X2 | f1 + f2\", data=data, weights=\"weights\", vcov=\"iid\"\n",
")"
]
},
Expand Down Expand Up @@ -311,7 +304,7 @@
}
],
"source": [
"pf.etable([fit, fit_weights], digits = 6)"
"pf.etable([fit, fit_weights], digits=6)"
]
},
{
Expand Down Expand Up @@ -444,7 +437,7 @@
}
],
"source": [
"pd.DataFrame(fixest.etable(r_fit, r_fit_weights, digits = 6)).T"
"pd.DataFrame(fixest.etable(r_fit, r_fit_weights, digits=6)).T"
]
},
{
Expand All @@ -467,15 +460,9 @@
"metadata": {},
"outputs": [],
"source": [
"fit = pf.feols(\n",
" fml = \"Y ~ X1 + X2 | f1 + f2\", data = data,\n",
" vcov = \"hetero\"\n",
")\n",
"fit = pf.feols(fml=\"Y ~ X1 + X2 | f1 + f2\", data=data, vcov=\"hetero\")\n",
"fit_weights = pf.feols(\n",
" fml = \"Y ~ X1 + X2 | f1 + f2\",\n",
" data = data,\n",
" vcov = \"hetero\",\n",
" weights = \"weights\"\n",
" fml=\"Y ~ X1 + X2 | f1 + f2\", data=data, vcov=\"hetero\", weights=\"weights\"\n",
")"
]
},
Expand Down Expand Up @@ -661,7 +648,7 @@
}
],
"source": [
"pf.etable([fit, fit_weights], digits = 6)"
"pf.etable([fit, fit_weights], digits=6)"
]
},
{
Expand Down Expand Up @@ -794,7 +781,7 @@
}
],
"source": [
"pd.DataFrame(fixest.etable(fit_r, fit_weights_r, digits = 6)).T"
"pd.DataFrame(fixest.etable(fit_r, fit_weights_r, digits=6)).T"
]
},
{
Expand Down Expand Up @@ -828,29 +815,22 @@
}
],
"source": [
"fit = pf.feols(\n",
" fml = \"Y ~ X1 + X2 | f1 + f2\",\n",
" data = data,\n",
" vcov = {\"CRV1\": \"f1\"}\n",
")\n",
"fit = pf.feols(fml=\"Y ~ X1 + X2 | f1 + f2\", data=data, vcov={\"CRV1\": \"f1\"})\n",
"fit_weights = pf.feols(\n",
" fml = \"Y ~ X1 + X2 | f1 + f2\",\n",
" data = data,\n",
" vcov = {\"CRV1\":\"f1\"},\n",
" weights = \"weights\"\n",
" fml=\"Y ~ X1 + X2 | f1 + f2\", data=data, vcov={\"CRV1\": \"f1\"}, weights=\"weights\"\n",
")\n",
"\n",
"fit_r = fixest.feols(\n",
" ro.Formula(\"Y ~ X1 + X2 | f1 + f2\"),\n",
" data=data,\n",
" vcov= ro.Formula(\"~f1\"),\n",
" vcov=ro.Formula(\"~f1\"),\n",
" ssc=fixest.ssc(True, \"none\", True, \"min\", \"min\", False),\n",
")\n",
"fit_r_weights = fixest.feols(\n",
" ro.Formula(\"Y ~ X1 + X2 | f1 + f2\"),\n",
" data=data,\n",
" weights=ro.Formula(\"~weights\"),\n",
" vcov= ro.Formula(\"~f1\"),\n",
" vcov=ro.Formula(\"~f1\"),\n",
" ssc=fixest.ssc(True, \"none\", True, \"min\", \"min\", False),\n",
")"
]
Expand Down Expand Up @@ -997,7 +977,7 @@
}
],
"source": [
"pf.etable([fit, fit_weights], digits = 6)"
"pf.etable([fit, fit_weights], digits=6)"
]
},
{
Expand Down Expand Up @@ -1130,7 +1110,7 @@
}
],
"source": [
"pd.DataFrame(fixest.etable(fit_r, fit_r_weights, digits = 6)).T"
"pd.DataFrame(fixest.etable(fit_r, fit_r_weights, digits=6)).T"
]
},
{
Expand All @@ -1146,7 +1126,7 @@
"metadata": {},
"outputs": [],
"source": [
"data = pf.get_data(model = \"Fepois\")"
"data = pf.get_data(model=\"Fepois\")"
]
},
{
Expand All @@ -1168,22 +1148,12 @@
}
],
"source": [
"fit_iid = pf.fepois(\n",
" fml = \"Y ~ X1 + X2 | f1 + f2\",\n",
" data = data,\n",
" vcov = \"iid\",\n",
" iwls_tol = 1e-10\n",
")\n",
"fit_iid = pf.fepois(fml=\"Y ~ X1 + X2 | f1 + f2\", data=data, vcov=\"iid\", iwls_tol=1e-10)\n",
"fit_hetero = pf.fepois(\n",
" fml = \"Y ~ X1 + X2 | f1 + f2\", data = data,\n",
" vcov = \"hetero\",\n",
" iwls_tol = 1e-10\n",
" fml=\"Y ~ X1 + X2 | f1 + f2\", data=data, vcov=\"hetero\", iwls_tol=1e-10\n",
")\n",
"fit_crv = pf.fepois(\n",
" fml = \"Y ~ X1 + X2 | f1 + f2\",\n",
" data = data,\n",
" vcov = {\"CRV1\":\"f1\"},\n",
" iwls_tol = 1e-10\n",
" fml=\"Y ~ X1 + X2 | f1 + f2\", data=data, vcov={\"CRV1\": \"f1\"}, iwls_tol=1e-10\n",
")\n",
"\n",
"fit_r_iid = fixest.fepois(\n",
Expand Down Expand Up @@ -1380,7 +1350,7 @@
}
],
"source": [
"pf.etable([fit_iid, fit_hetero, fit_crv], digits = 6)"
"pf.etable([fit_iid, fit_hetero, fit_crv], digits=6)"
]
},
{
Expand Down Expand Up @@ -1549,7 +1519,7 @@
}
],
"source": [
"pd.DataFrame(fixest.etable(fit_r_iid, fit_r_hetero, fit_r_crv, digits = 6)).T"
"pd.DataFrame(fixest.etable(fit_r_iid, fit_r_hetero, fit_r_crv, digits=6)).T"
]
}
],
Expand Down
48 changes: 29 additions & 19 deletions docs/difference-in-differences.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@
}
],
"source": [
"\n",
"# multi-cohort adoption data\n",
"df_multi_cohort = pd.read_csv(\n",
" resources.files(\"pyfixest.did.data\").joinpath(\"df_het.csv\")\n",
Expand Down Expand Up @@ -426,11 +425,14 @@
"source": [
"panelview(\n",
" df_one_cohort,\n",
" unit=\"unit\", time=\"year\", treat=\"treat\",\n",
" unit=\"unit\",\n",
" time=\"year\",\n",
" treat=\"treat\",\n",
" collapse_to_cohort=True,\n",
" sort_by_timing=True,\n",
" ylab=\"Cohort\", xlab=\"Year\",\n",
" title = \"Treatment Assignment Cohorts\",\n",
" ylab=\"Cohort\",\n",
" xlab=\"Year\",\n",
" title=\"Treatment Assignment Cohorts\",\n",
")"
]
},
Expand Down Expand Up @@ -463,11 +465,14 @@
"source": [
"panelview(\n",
" df_multi_cohort,\n",
" unit=\"unit\", time=\"year\", treat=\"treat\",\n",
" unit=\"unit\",\n",
" time=\"year\",\n",
" treat=\"treat\",\n",
" collapse_to_cohort=True,\n",
" sort_by_timing=True,\n",
" ylab=\"Cohort\", xlab=\"Year\",\n",
" title = \"Treatment Assignment Cohorts\",\n",
" ylab=\"Cohort\",\n",
" xlab=\"Year\",\n",
" title=\"Treatment Assignment Cohorts\",\n",
")"
]
},
Expand Down Expand Up @@ -509,10 +514,13 @@
"source": [
"panelview(\n",
" df_multi_cohort,\n",
" unit=\"unit\", time=\"year\", treat=\"treat\",\n",
" unit=\"unit\",\n",
" time=\"year\",\n",
" treat=\"treat\",\n",
" sort_by_timing=True,\n",
" ylab=\"Unit\", xlab=\"Year\",\n",
" title = \"Treatment Assignment (all units)\",\n",
" ylab=\"Unit\",\n",
" xlab=\"Year\",\n",
" title=\"Treatment Assignment (all units)\",\n",
")"
]
},
Expand Down Expand Up @@ -695,7 +703,7 @@
" figsize=[1200, 400],\n",
" yintercept=0,\n",
" xintercept=13.5,\n",
" labels = rename_event_study_coefs(fit_dynamic_twfe._coefnames),\n",
" labels=rename_event_study_coefs(fit_dynamic_twfe._coefnames),\n",
")"
]
},
Expand Down Expand Up @@ -842,7 +850,7 @@
" yintercept=0,\n",
" xintercept=13.5,\n",
" joint=\"both\",\n",
" labels = rename_event_study_coefs(fit_dynamic_twfe._coefnames),\n",
" labels=rename_event_study_coefs(fit_dynamic_twfe._coefnames),\n",
")"
]
},
Expand Down Expand Up @@ -1060,7 +1068,7 @@
" figsize=figsize,\n",
" xintercept=18.5,\n",
" yintercept=0,\n",
" labels = rename_event_study_coefs(fit_twfe._coefnames), # rename coefficients\n",
" labels=rename_event_study_coefs(fit_twfe._coefnames), # rename coefficients\n",
").show()"
]
},
Expand Down Expand Up @@ -1179,7 +1187,7 @@
" figsize=figsize,\n",
" xintercept=18.5,\n",
" yintercept=0,\n",
" labels = rename_event_study_coefs(fit_twfe._coefnames),\n",
" labels=rename_event_study_coefs(fit_twfe._coefnames),\n",
").show()"
]
},
Expand Down Expand Up @@ -1422,11 +1430,13 @@
" post_window=20,\n",
" att=True,\n",
")\n",
"pd.concat([\n",
" fit_twfe.tidy().assign(estimator=\"TWFE\"),\n",
" fit_did2s.tidy().assign(estimator=\"DID2s\"),\n",
" fit_lpdid.tidy().assign(estimator=\"LPDID\").drop(\"N\", axis=1),\n",
"], axis=0\n",
"pd.concat(\n",
" [\n",
" fit_twfe.tidy().assign(estimator=\"TWFE\"),\n",
" fit_did2s.tidy().assign(estimator=\"DID2s\"),\n",
" fit_lpdid.tidy().assign(estimator=\"LPDID\").drop(\"N\", axis=1),\n",
" ],\n",
" axis=0,\n",
")"
]
}
Expand Down
Loading

0 comments on commit a6ca571

Please sign in to comment.