Skip to content

Commit f6ce66e

Browse files
[pre-commit.ci] pre-commit autoupdate (#789)
1 parent 306da82 commit f6ce66e

File tree

11 files changed

+120
-110
lines changed

11 files changed

+120
-110
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ repos:
1414
- id: check-added-large-files
1515
exclude: pixi.lock
1616
- repo: https://github.com/python-jsonschema/check-jsonschema
17-
rev: 0.30.0
17+
rev: 0.31.0
1818
hooks:
1919
- id: check-github-workflows
2020
args: ["--verbose"]
2121

2222
- repo: https://github.com/astral-sh/ruff-pre-commit
23-
rev: v0.8.6
23+
rev: v0.9.1
2424
hooks:
2525
- id: ruff
2626
args: ["--fix", "--output-format=full"]

pyfixest/estimation/feols_.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,13 +1341,13 @@ def ccv(
13411341
fit.ccv(treatment="D", pk=0.05, qk=0.5, n_splits=8, seed=123).head()
13421342
```
13431343
"""
1344-
assert (
1345-
self._supports_cluster_causal_variance
1346-
), "The model does not support the causal cluster variance estimator."
1344+
assert self._supports_cluster_causal_variance, (
1345+
"The model does not support the causal cluster variance estimator."
1346+
)
13471347
assert isinstance(treatment, str), "treatment must be a string."
1348-
assert (
1349-
isinstance(cluster, str) or cluster is None
1350-
), "cluster must be a string or None."
1348+
assert isinstance(cluster, str) or cluster is None, (
1349+
"cluster must be a string or None."
1350+
)
13511351
assert isinstance(seed, int) or seed is None, "seed must be an integer or None."
13521352
assert isinstance(n_splits, int), "n_splits must be an integer."
13531353
assert isinstance(pk, (int, float)) and 0 <= pk <= 1
@@ -1398,9 +1398,9 @@ def ccv(
13981398
data = self._data
13991399
Y = self._Y.flatten()
14001400
W = data[treatment].to_numpy()
1401-
assert np.all(
1402-
np.isin(W, [0, 1])
1403-
), "Treatment variable must be binary with values 0 and 1"
1401+
assert np.all(np.isin(W, [0, 1])), (
1402+
"Treatment variable must be binary with values 0 and 1"
1403+
)
14041404
X = self._X
14051405
cluster_vec = data[cluster].to_numpy()
14061406
unique_clusters = np.unique(cluster_vec)
@@ -1950,8 +1950,8 @@ def tidy(
19501950
"Std. Error": _se,
19511951
"t value": _tstat,
19521952
"Pr(>|t|)": _pvalue,
1953-
f"{lb*100:.1f}%": _conf_int[0],
1954-
f"{ub*100:.1f}%": _conf_int[1],
1953+
f"{lb * 100:.1f}%": _conf_int[0],
1954+
f"{ub * 100:.1f}%": _conf_int[1],
19551955
}
19561956
)
19571957

@@ -2117,8 +2117,8 @@ def confint(
21172117

21182118
df = pd.DataFrame(
21192119
{
2120-
f"{alpha / 2*100:.1f}%": lb,
2121-
f"{(1-alpha / 2)*100:.1f}%": ub,
2120+
f"{alpha / 2 * 100:.1f}%": lb,
2121+
f"{(1 - alpha / 2) * 100:.1f}%": ub,
21222122
}
21232123
)
21242124
# df = pd.DataFrame({f"{alpha / 2}%": lb, f"{1-alpha / 2}%": ub})
@@ -2349,8 +2349,8 @@ def ritest(
23492349
)
23502350

23512351
alpha = 1 - level
2352-
ci_lower_name = str(f"{alpha/2*100:.1f}% (Pr(>|t|))")
2353-
ci_upper_name = str(f"{(1-alpha/2)*100:.1f}% (Pr(>|t|))")
2352+
ci_lower_name = str(f"{alpha / 2 * 100:.1f}% (Pr(>|t|))")
2353+
ci_upper_name = str(f"{(1 - alpha / 2) * 100:.1f}% (Pr(>|t|))")
23542354
res[ci_lower_name] = ci_pvalue[0]
23552355
res[ci_upper_name] = ci_pvalue[1]
23562356

@@ -2648,17 +2648,17 @@ def _check_vcov_input(vcov: Union[str, dict[str, str]], data: pd.DataFrame):
26482648
"CRV1",
26492649
"CRV3",
26502650
], "vcov dict key must be CRV1 or CRV3"
2651-
assert isinstance(
2652-
next(iter(vcov.values())), str
2653-
), "vcov dict value must be a string"
2651+
assert isinstance(next(iter(vcov.values())), str), (
2652+
"vcov dict value must be a string"
2653+
)
26542654
deparse_vcov = next(iter(vcov.values())).split("+")
26552655
assert len(deparse_vcov) <= 2, "not more than twoway clustering is supported"
26562656

26572657
if isinstance(vcov, list):
26582658
assert all(isinstance(v, str) for v in vcov), "vcov list must contain strings"
2659-
assert all(
2660-
v in data.columns for v in vcov
2661-
), "vcov list must contain columns in the data"
2659+
assert all(v in data.columns for v in vcov), (
2660+
"vcov list must contain columns in the data"
2661+
)
26622662
if isinstance(vcov, str):
26632663
assert vcov in [
26642664
"iid",

pyfixest/report/summarize.py

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,17 @@ def etable(
142142
"""
143143
if signif_code is None:
144144
signif_code = [0.001, 0.01, 0.05]
145-
assert (
146-
isinstance(signif_code, list) and len(signif_code) == 3
147-
), "signif_code must be a list of length 3"
145+
assert isinstance(signif_code, list) and len(signif_code) == 3, (
146+
"signif_code must be a list of length 3"
147+
)
148148
if signif_code:
149-
assert all(
150-
[0 < i < 1 for i in signif_code]
151-
), "All values of signif_code must be between 0 and 1"
149+
assert all([0 < i < 1 for i in signif_code]), (
150+
"All values of signif_code must be between 0 and 1"
151+
)
152152
if signif_code:
153-
assert (
154-
signif_code[0] < signif_code[1] < signif_code[2]
155-
), "signif_code must be in increasing order"
153+
assert signif_code[0] < signif_code[1] < signif_code[2], (
154+
"signif_code must be in increasing order"
155+
)
156156

157157
models = _post_processing_input_checks(models)
158158

@@ -166,12 +166,12 @@ def etable(
166166
if custom_stats:
167167
assert isinstance(custom_stats, dict), "custom_stats must be a dict"
168168
for key in custom_stats:
169-
assert isinstance(
170-
custom_stats[key], list
171-
), "custom_stats values must be a list"
172-
assert len(custom_stats[key]) == len(
173-
models
174-
), f"custom_stats {key} must have the same number as models"
169+
assert isinstance(custom_stats[key], list), (
170+
"custom_stats values must be a list"
171+
)
172+
assert len(custom_stats[key]) == len(models), (
173+
f"custom_stats {key} must have the same number as models"
174+
)
175175

176176
assert type in [
177177
"df",
@@ -182,9 +182,9 @@ def etable(
182182
], "type must be either 'df', 'md', 'html', 'gt' or 'tex'"
183183

184184
if model_heads is not None:
185-
assert len(model_heads) == len(
186-
models
187-
), "model_heads must have the same length as models"
185+
assert len(model_heads) == len(models), (
186+
"model_heads must have the same length as models"
187+
)
188188

189189
# Check if head_order is allowed string & remove h when no model_heads provided
190190
assert head_order in [
@@ -203,9 +203,9 @@ def etable(
203203
for stat, values in custom_model_stats.items():
204204
assert isinstance(stat, str), "custom_model_stats keys must be strings"
205205
assert isinstance(values, list), "custom_model_stats values must lists"
206-
assert len(values) == len(
207-
models
208-
), "lists in custom_model_stats values must have the same length as models"
206+
assert len(values) == len(models), (
207+
"lists in custom_model_stats values must have the same length as models"
208+
)
209209

210210
dep_var_list = []
211211
nobs_list = []
@@ -336,9 +336,11 @@ def etable(
336336
_number_formatter, **kwargs
337337
)
338338
elif element in custom_stats:
339-
assert (
340-
len(custom_stats[element][i]) == len(model_tidy_df["Estimate"])
341-
), f"custom_stats {element} has unequal length to the number of coefficients in model_tidy_df {i}"
339+
assert len(custom_stats[element][i]) == len(
340+
model_tidy_df["Estimate"]
341+
), (
342+
f"custom_stats {element} has unequal length to the number of coefficients in model_tidy_df {i}"
343+
)
342344
model_tidy_df[coef_fmt_title] += pd.Series(
343345
custom_stats[element][i]
344346
).apply(_number_formatter, **kwargs)
@@ -357,7 +359,7 @@ def etable(
357359
model_tidy_df,
358360
id_vars=["Coefficient"],
359361
var_name="Metric",
360-
value_name=f"est{i+1}",
362+
value_name=f"est{i + 1}",
361363
)
362364
model_tidy_df = model_tidy_df.drop("Metric", axis=1).set_index("Coefficient")
363365
etable_list.append(model_tidy_df)
@@ -833,9 +835,9 @@ def make_table(
833835
A table in the specified format.
834836
"""
835837
assert isinstance(df, pd.DataFrame), "df must be a pandas DataFrame."
836-
assert (
837-
not isinstance(df.index, pd.MultiIndex) or df.index.nlevels <= 2
838-
), "Row index can have at most two levels."
838+
assert not isinstance(df.index, pd.MultiIndex) or df.index.nlevels <= 2, (
839+
"Row index can have at most two levels."
840+
)
839841
assert type in ["gt", "tex"], "type must be either 'gt' or 'tex'."
840842
assert rgroup_sep in [
841843
"tb",
@@ -1250,16 +1252,16 @@ def dtable(
12501252
if stats_labels is None:
12511253
stats_labels = {}
12521254
assert isinstance(df, pd.DataFrame), "df must be a pandas DataFrame."
1253-
assert all(
1254-
pd.api.types.is_numeric_dtype(df[var]) for var in vars
1255-
), "Variables must be numerical."
1255+
assert all(pd.api.types.is_numeric_dtype(df[var]) for var in vars), (
1256+
"Variables must be numerical."
1257+
)
12561258
assert type in ["gt", "tex", "df"], "type must be either 'gt' or 'tex' or 'df'."
1257-
assert (
1258-
byrow is None or byrow in df.columns
1259-
), "byrow must be a column in the DataFrame."
1260-
assert bycol is None or all(
1261-
col in df.columns for col in bycol
1262-
), "bycol must be a list of columns in the DataFrame."
1259+
assert byrow is None or byrow in df.columns, (
1260+
"byrow must be a column in the DataFrame."
1261+
)
1262+
assert bycol is None or all(col in df.columns for col in bycol), (
1263+
"bycol must be a list of columns in the DataFrame."
1264+
)
12631265

12641266
# Default stats labels dictionary
12651267
stats_dict = {

pyfixest/report/visualize.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def _coefplot_lets_plot(
411411
width=0.05,
412412
position=position_dodge(0.5),
413413
)
414-
+ ylab(rf"Estimate and {round((1-alpha)*100, 1)}% Confidence Interval")
414+
+ ylab(rf"Estimate and {round((1 - alpha) * 100, 1)}% Confidence Interval")
415415
)
416416

417417
if flip_coord:
@@ -544,7 +544,9 @@ def _coefplot_matplotlib(
544544
ax.axvline(x=yintercept, color="black", linestyle="--")
545545
if xintercept is not None:
546546
ax.axhline(y=xintercept, color="black", linestyle="--")
547-
ax.set_xlabel(rf"Estimate and {round((1-alpha)*100, 1)}% Confidence Interval")
547+
ax.set_xlabel(
548+
rf"Estimate and {round((1 - alpha) * 100, 1)}% Confidence Interval"
549+
)
548550
ax.set_ylabel("Coefficient")
549551
ax.set_yticks(range(len(unique_coefficients)))
550552
ax.set_yticklabels(unique_coefficients)
@@ -553,7 +555,9 @@ def _coefplot_matplotlib(
553555
ax.axhline(y=yintercept, color="black", linestyle="--")
554556
if xintercept is not None:
555557
ax.axvline(x=xintercept, color="black", linestyle="--")
556-
ax.set_ylabel(rf"Estimate and {round((1-alpha)*100, 1)}% Confidence Interval")
558+
ax.set_ylabel(
559+
rf"Estimate and {round((1 - alpha) * 100, 1)}% Confidence Interval"
560+
)
557561
ax.set_xlabel("Coefficient")
558562
ax.set_xticks(range(len(unique_coefficients)))
559563
ax.set_xticklabels(unique_coefficients)
@@ -596,10 +600,10 @@ def _get_model_df(
596600
A tidy model frame.
597601
"""
598602
df_model = fxst.tidy(alpha=alpha).reset_index() # Coefficient -> simple column
599-
df_model["fml"] = f"{fxst._model_name_plot}: {(1- alpha) *100:.1f}%"
603+
df_model["fml"] = f"{fxst._model_name_plot}: {(1 - alpha) * 100:.1f}%"
600604

601605
if joint in ["both", True]:
602-
lb, ub = f"{alpha / 2*100:.1f}%", f"{(1 - alpha / 2)*100:.1f}%"
606+
lb, ub = f"{alpha / 2 * 100:.1f}%", f"{(1 - alpha / 2) * 100:.1f}%"
603607
df_joint = fxst.confint(joint=True, alpha=alpha, seed=seed)
604608
df_joint.reset_index(inplace=True)
605609
df_joint = df_joint.rename(columns={"index": "Coefficient"})
@@ -609,7 +613,7 @@ def _get_model_df(
609613
.merge(df_joint, on="Coefficient", how="left")
610614
)
611615
df_joint_full["fml"] = (
612-
f"{fxst._model_name_plot}: {(1- alpha) *100:.1f}% joint CIs"
616+
f"{fxst._model_name_plot}: {(1 - alpha) * 100:.1f}% joint CIs"
613617
)
614618
if joint == "both":
615619
df_model = pd.concat([df_model, df_joint_full], axis=0)

tests/test_confint.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ def test_against_doubleml():
7171
np.c_[y, X], columns=["y"] + ["X_" + str(x) for x in range(n_vars)]
7272
)
7373
m = feols(
74-
f"y ~ -1 + {'+'.join(['X_'+str(x) for x in range(n_vars)])}", df, vcov="hetero"
74+
f"y ~ -1 + {'+'.join(['X_' + str(x) for x in range(n_vars)])}",
75+
df,
76+
vcov="hetero",
7577
)
7678
pyfixest_res = m.confint(keep="X_.$", reps=10_000, joint=True)
7779

tests/test_decomposition.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,16 @@ def decompose_and_compare(
140140
lower_diff = filtered_df.xs(g)["CI Lower"] - ci[g][0]
141141
upper_diff = filtered_df.xs(g)["CI Upper"] - ci[g][1]
142142

143-
assert np.all(
144-
np.abs(coef_diff) < 1e-6
145-
), f"Failed for {g} with values {filtered_df.xs(g).Coefficient} and {contribution_dict[g]}"
143+
assert np.all(np.abs(coef_diff) < 1e-6), (
144+
f"Failed for {g} with values {filtered_df.xs(g).Coefficient} and {contribution_dict[g]}"
145+
)
146146
if False:
147-
assert np.all(
148-
np.abs(lower_diff) < 1e-4
149-
), f"Failed for {g} with values {filtered_df.xs(g)['CI Lower']} and {ci[g][0]}"
150-
assert np.all(
151-
np.abs(upper_diff) < 1e-4
152-
), f"Failed for {g} with values {filtered_df.xs(g)['CI Upper']} and {ci[g][1]}"
147+
assert np.all(np.abs(lower_diff) < 1e-4), (
148+
f"Failed for {g} with values {filtered_df.xs(g)['CI Lower']} and {ci[g][0]}"
149+
)
150+
assert np.all(np.abs(upper_diff) < 1e-4), (
151+
f"Failed for {g} with values {filtered_df.xs(g)['CI Upper']} and {ci[g][1]}"
152+
)
153153

154154
# Agg 1: Heteroskedastic SE
155155
decompose_and_compare(

tests/test_event_study.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ def test_event_study_twfe(data):
2525

2626
twfe_feols = pf.feols("dep_var ~ treat | state + year", data=data)
2727

28-
assert np.allclose(
29-
twfe.coef().values, twfe_feols.coef().values
30-
), "TWFE coefficients are not the same."
31-
assert np.allclose(
32-
twfe.se().values, twfe_feols.se().values
33-
), "TWFE standard errors are not the same."
34-
assert np.allclose(
35-
twfe.pvalue().values, twfe_feols.pvalue().values
36-
), "TWFE p-values are not the same."
28+
assert np.allclose(twfe.coef().values, twfe_feols.coef().values), (
29+
"TWFE coefficients are not the same."
30+
)
31+
assert np.allclose(twfe.se().values, twfe_feols.se().values), (
32+
"TWFE standard errors are not the same."
33+
)
34+
assert np.allclose(twfe.pvalue().values, twfe_feols.pvalue().values), (
35+
"TWFE p-values are not the same."
36+
)
3737

3838
# TODO - minor difference, likely due to how z statistic is
3939
# calculated
@@ -63,15 +63,15 @@ def test_event_study_did2s(data):
6363
cluster="state",
6464
)
6565

66-
assert np.allclose(
67-
event_study_did2s.coef().values, fit_did2s.coef().values
68-
), "DID2S coefficients are not the same."
69-
assert np.allclose(
70-
event_study_did2s.se().values, fit_did2s.se().values
71-
), "DID2S standard errors are not the same."
72-
assert np.allclose(
73-
event_study_did2s.pvalue().values, fit_did2s.pvalue().values
74-
), "DID2S p-values are not the same."
66+
assert np.allclose(event_study_did2s.coef().values, fit_did2s.coef().values), (
67+
"DID2S coefficients are not the same."
68+
)
69+
assert np.allclose(event_study_did2s.se().values, fit_did2s.se().values), (
70+
"DID2S standard errors are not the same."
71+
)
72+
assert np.allclose(event_study_did2s.pvalue().values, fit_did2s.pvalue().values), (
73+
"DID2S p-values are not the same."
74+
)
7575
assert np.allclose(
7676
event_study_did2s.confint().values, fit_did2s.confint().values
7777
), "DID2S confidence intervals are not the same."

tests/test_feols_compressed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ def test_different_seed():
162162
fit4 = pf.feols("Y ~ f1", data=data, use_compression=True, seed=125, reps=1000)
163163

164164
assert np.allclose(fit3.coef().xs("f1"), fit4.coef().xs("f1")), "Error in seed"
165-
assert np.all(
166-
np.abs(fit3.se().xs("f1") / fit4.se().xs("f1")) < RTOL_BOOT
167-
), "Error in se"
165+
assert np.all(np.abs(fit3.se().xs("f1") / fit4.se().xs("f1")) < RTOL_BOOT), (
166+
"Error in se"
167+
)
168168
assert np.all(
169169
np.abs(fit3.pvalue().xs("f1") / fit4.pvalue().xs("f1")) < RTOL_BOOT
170170
), "Error in pvalue"

0 commit comments

Comments
 (0)