Skip to content

Commit 35ca943

Browse files
committed
CLN: Enable more ruff
1 parent 4007feb commit 35ca943

37 files changed

+192
-189
lines changed

ci/azure_template_posix.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ jobs:
9898
black --check linearmodels
9999
isort --check linearmodels
100100
ruff check linearmodels
101+
flake8 linearmodels
101102
displayName: 'Check style and formatting'
102103
103104
- script: |

linearmodels/asset_pricing/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def fit(
348348
kernel=kernel,
349349
)
350350
bw = cov_est.bandwidth
351-
_cov_config = {k: v for k, v in cov_config.items()}
351+
_cov_config = dict(cov_config.items())
352352
_cov_config["bandwidth"] = bw
353353
rp_cov_est = KernelCovariance(
354354
fe,

linearmodels/iv/absorbing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ def fit(
10891089
FutureWarning,
10901090
stacklevel=2,
10911091
)
1092-
absorb_options = {k: v for k, v in lsmr_options.items()}
1092+
absorb_options = dict(lsmr_options.items())
10931093
if self._absorbed_dependent is None:
10941094
self._first_time_fit(use_cache, absorb_options, method)
10951095

@@ -1104,7 +1104,7 @@ def fit(
11041104
cov_estimator = COVARIANCE_ESTIMATORS[cov_type]
11051105
cov_config["debiased"] = debiased
11061106
cov_config["kappa"] = 0.0
1107-
cov_config_copy = {k: v for k, v in cov_config.items()}
1107+
cov_config_copy = dict(cov_config.items())
11081108
cov_config_copy.pop("center", None)
11091109
cov_estimator_inst = cov_estimator(
11101110
exog_resid, dep_resid, exog_resid, params, **cov_config_copy

linearmodels/iv/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def fit(
693693
cov_estimator = COVARIANCE_ESTIMATORS[cov_type]
694694
cov_config["debiased"] = debiased
695695
cov_config["kappa"] = est_kappa
696-
cov_config_copy = {k: v for k, v in cov_config.items()}
696+
cov_config_copy = dict(cov_config.items())
697697
cov_config_copy.pop("center", None)
698698
cov_estimator_inst = cov_estimator(wx, wy, wz, params, **cov_config_copy)
699699

linearmodels/panel/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ def _setup_clusters(
763763
if not common:
764764
return cov_config_upd
765765

766-
cov_config_upd = {k: v for k, v in cov_config.items()}
766+
cov_config_upd = dict(cov_config.items())
767767

768768
clusters = get_panel_data_like(cov_config, "clusters")
769769
clusters_frame: DataFrame | None = None

linearmodels/tests/asset_pricing/test_covariance.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ def data():
2020

2121

2222
def test_kernel_errors(data):
23-
with pytest.raises(ValueError, match="Unknown kernel"):
23+
with pytest.raises(ValueError, match=r"Unknown kernel"):
2424
KernelWeight(data.moments, kernel="unknown")
25-
with pytest.raises(ValueError, match="bandwidth must be non-negative"):
25+
with pytest.raises(ValueError, match=r"bandwidth must be non-negative"):
2626
KernelWeight(data.moments, bandwidth=-0.5)
27-
with pytest.raises(ValueError, match="Unknown kernel"):
27+
with pytest.raises(ValueError, match=r"Unknown kernel"):
2828
KernelCovariance(data.moments, jacobian=data.jacobian, kernel="unknown")
29-
with pytest.raises(ValueError, match="bandwidth must be non-negative"):
29+
with pytest.raises(ValueError, match=r"bandwidth must be non-negative"):
3030
KernelCovariance(data.moments, jacobian=data.jacobian, bandwidth=-4)
3131

3232

3333
def test_no_jacobian(data):
34-
with pytest.raises(ValueError, match="One and only one of jacobian"):
34+
with pytest.raises(ValueError, match=r"One and only one of jacobian"):
3535
KernelCovariance(data.moments)
36-
with pytest.raises(ValueError, match="One and only one of jacobian "):
36+
with pytest.raises(ValueError, match=r"One and only one of jacobian "):
3737
KernelCovariance(
3838
data.moments, jacobian=data.jacobian, inv_jacobian=data.inv_jacobian
3939
)

linearmodels/tests/asset_pricing/test_formulas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_starting_values_options(data):
111111
res3 = mod2.fit(starting=sv[:, None], opt_options=oo, disp=0)
112112
assert_frame_equal(res2.params, res3.params)
113113

114-
with pytest.raises(ValueError, match="tarting values"):
114+
with pytest.raises(ValueError, match=r"tarting values"):
115115
mod2.fit(starting=sv[:-3], opt_options=oo, disp=0)
116116

117117

linearmodels/tests/asset_pricing/test_linear_factor_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,5 +338,5 @@ def test_linear_model_parameters_risk_free_gls(data):
338338
@pytest.mark.parametrize("output", ["numpy", "pandas"])
339339
def test_infeasible(output):
340340
data = generate_data(nfactor=10, nportfolio=20, nobs=10, output=output)
341-
with pytest.raises(ValueError, match="Model cannot be estimated"):
341+
with pytest.raises(ValueError, match=r"Model cannot be estimated"):
342342
LinearFactorModel(data.portfolios, data.factors)

linearmodels/tests/asset_pricing/test_model.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test_linear_model_time_series_kernel_smoke(data):
127127

128128
def test_linear_model_time_series_error(data):
129129
mod = TradedFactorModel(data.portfolios, data.factors)
130-
with pytest.raises(ValueError, match="Unknown cov_type"):
130+
with pytest.raises(ValueError, match=r"Unknown cov_type"):
131131
mod.fit(cov_type="unknown")
132132

133133

@@ -161,19 +161,19 @@ def test_errors(data):
161161
f2 = np.c_[f, f[:, [0]]]
162162
f = np.c_[np.ones((f.shape[0], 1)), f]
163163

164-
with pytest.raises(ValueError, match="portfolios must not contain"):
164+
with pytest.raises(ValueError, match=r"portfolios must not contain"):
165165
TradedFactorModel(p, data.factors)
166-
with pytest.raises(ValueError, match="portfolios must not contain"):
166+
with pytest.raises(ValueError, match=r"portfolios must not contain"):
167167
TradedFactorModel(p2, data.factors)
168-
with pytest.raises(ValueError, match="The number of observations"):
168+
with pytest.raises(ValueError, match=r"The number of observations"):
169169
TradedFactorModel(p3, data.factors)
170-
with pytest.raises(ValueError, match="factors must not contain"):
170+
with pytest.raises(ValueError, match=r"factors must not contain"):
171171
TradedFactorModel(data.portfolios, f)
172-
with pytest.raises(ValueError, match="factors must not contain"):
172+
with pytest.raises(ValueError, match=r"factors must not contain"):
173173
TradedFactorModel(data.portfolios, f2)
174-
with pytest.raises(ValueError, match="Model cannot be estimated"):
174+
with pytest.raises(ValueError, match=r"Model cannot be estimated"):
175175
TradedFactorModel(p5, f5)
176-
with pytest.raises(ValueError, match="The number of test portfolio"):
176+
with pytest.raises(ValueError, match=r"The number of test portfolio"):
177177
LinearFactorModel(p4, data.factors)
178178

179179

@@ -198,17 +198,17 @@ def test_drop_missing(data):
198198

199199
def test_unknown_kernel(data):
200200
mod = LinearFactorModel(data.portfolios, data.factors)
201-
with pytest.raises(ValueError, match="Unknown weight"):
201+
with pytest.raises(ValueError, match=r"Unknown weight"):
202202
mod.fit(cov_type="unknown")
203203
mod = LinearFactorModelGMM(data.portfolios, data.factors)
204-
with pytest.raises(ValueError, match="Unknown weight"):
204+
with pytest.raises(ValueError, match=r"Unknown weight"):
205205
mod.fit(cov_type="unknown")
206206

207207

208208
def test_all_missing():
209209
p = np.nan * np.ones((1000, 10))
210210
f = np.nan * np.ones((1000, 3))
211-
with pytest.raises(ValueError, match="All observations contain missing data"):
211+
with pytest.raises(ValueError, match=r"All observations contain missing data"):
212212
TradedFactorModel(p, f)
213213

214214

linearmodels/tests/iv/test_absorbing.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,23 +265,23 @@ def test_smoke(data):
265265
def test_absorbing_exceptions(random_gen):
266266
absorbed = random_gen.standard_normal((NOBS, 2))
267267
assert isinstance(absorbed, np.ndarray)
268-
with pytest.raises(TypeError, match="absorb must ba a DataFrame"):
268+
with pytest.raises(TypeError, match=r"absorb must ba a DataFrame"):
269269
AbsorbingLS(
270270
random_gen.standard_normal(NOBS),
271271
random_gen.standard_normal((NOBS, 2)),
272272
absorb=absorbed,
273273
)
274-
with pytest.raises(ValueError, match="ASDF"):
274+
with pytest.raises(ValueError, match=r"ASDF"):
275275
AbsorbingLS(
276276
random_gen.standard_normal(NOBS), random_gen.standard_normal((NOBS - 1, 2))
277277
)
278-
with pytest.raises(ValueError, match="ASDF"):
278+
with pytest.raises(ValueError, match=r"ASDF"):
279279
AbsorbingLS(
280280
random_gen.standard_normal(NOBS),
281281
random_gen.standard_normal((NOBS, 2)),
282282
absorb=pd.DataFrame(random_gen.standard_normal((NOBS - 1, 1))),
283283
)
284-
with pytest.raises(ValueError, match="ASDF"):
284+
with pytest.raises(ValueError, match=r"ASDF"):
285285
AbsorbingLS(
286286
random_gen.standard_normal(NOBS),
287287
random_gen.standard_normal((NOBS, 2)),
@@ -298,7 +298,7 @@ def test_absorbing_exceptions(random_gen):
298298
assert isinstance(mod.absorbed_exog, pd.DataFrame)
299299
interactions = random_gen.randint(0, 10, size=(NOBS, 2))
300300
assert isinstance(interactions, np.ndarray)
301-
with pytest.raises(TypeError, match="ASDF"):
301+
with pytest.raises(TypeError, match=r"ASDF"):
302302
AbsorbingLS(
303303
random_gen.standard_normal(NOBS),
304304
random_gen.standard_normal((NOBS, 2)),
@@ -346,15 +346,15 @@ def test_category_product_too_large(random_gen):
346346
for i in range(20):
347347
dfc[str(i)] = random_cat(10, 1000)
348348
cat = pd.DataFrame(dfc)
349-
with pytest.raises(ValueError, match="There are too many cats"):
349+
with pytest.raises(ValueError, match=r"There are too many cats"):
350350
category_product(cat)
351351

352352

353353
def test_category_product_not_cat(random_gen):
354354
cat = pd.DataFrame(
355355
{str(i): pd.Series(random_gen.randint(0, 10, 1000)) for i in range(3)}
356356
)
357-
with pytest.raises(TypeError, match="cats must contain only"):
357+
with pytest.raises(TypeError, match=r"cats must contain only"):
358358
category_product(cat)
359359

360360

@@ -442,9 +442,9 @@ def test_interaction_from_frame(cat, cont):
442442

443443

444444
def test_interaction_cat_bad_nobs():
445-
with pytest.raises(ValueError, match="nobs must be provided when cat"):
445+
with pytest.raises(ValueError, match=r"nobs must be provided when cat"):
446446
Interaction()
447-
with pytest.raises(ValueError, match="ASDF"):
447+
with pytest.raises(ValueError, match=r"ASDF"):
448448
Interaction(cat=np.empty((100, 0)), cont=np.empty((100, 0)))
449449

450450

@@ -704,7 +704,7 @@ def test_fully_absorb(random_gen):
704704
y = df.y
705705
x = pd.get_dummies(df.c, drop_first=False)
706706
mod = AbsorbingLS(y, x, absorb=df[["c"]], drop_absorbed=True)
707-
with pytest.raises(ValueError, match="All columns in exog"):
707+
with pytest.raises(ValueError, match=r"All columns in exog"):
708708
mod.fit()
709709

710710

@@ -719,9 +719,9 @@ def test_lsmr_options(random_gen):
719719
y = df.y
720720
x = df.iloc[:, :3]
721721
mod = AbsorbingLS(y, x, absorb=df[["c"]], drop_absorbed=True)
722-
with pytest.warns(FutureWarning, match="lsmr_options"):
722+
with pytest.warns(FutureWarning, match=r"lsmr_options"):
723723
mod.fit(lsmr_options={})
724-
with pytest.raises(ValueError, match="absorb_options cannot"):
724+
with pytest.raises(ValueError, match=r"absorb_options cannot"):
725725
mod.fit(lsmr_options={}, absorb_options={})
726726

727727

@@ -740,7 +740,7 @@ def test_options(random_gen):
740740
mod.fit(absorb_options={"atol": 1e-7, "btol": 1e-7}, method="lsmr")
741741

742742
mod = AbsorbingLS(y, x[["x0", "x1"]], absorb=df[["x2", "c"]], drop_absorbed=True)
743-
with pytest.raises(RuntimeError, match="HDFE has been"):
743+
with pytest.raises(RuntimeError, match=r"HDFE has been"):
744744
mod.fit(absorb_options={"atol": 1e-7, "btol": 1e-7}, method="hdfe")
745745

746746

0 commit comments

Comments
 (0)