From ee8291b7472aa2f4f4deb3bec92cf30873f73cf2 Mon Sep 17 00:00:00 2001 From: BalzaniEdoardo Date: Wed, 23 Oct 2024 10:10:26 -0400 Subject: [PATCH] linted --- src/nemos/basis.py | 5 +- tests/test_basis.py | 127 +++++++++++++++++++++++++++++++++----------- 2 files changed, 99 insertions(+), 33 deletions(-) diff --git a/src/nemos/basis.py b/src/nemos/basis.py index b5116632..796a8f3c 100644 --- a/src/nemos/basis.py +++ b/src/nemos/basis.py @@ -473,7 +473,7 @@ class Basis(Base, abc.ABC): **kwargs : Only used in "conv" mode. Additional keyword arguments that are passed to `nemos.convolve.create_convolutional_predictor` - + Raises ------ ValueError: @@ -521,7 +521,8 @@ def __init__( ) convolve_params = inspect.signature(create_convolutional_predictor).parameters convolve_configs = { - key for key, param in convolve_params.items() + key + for key, param in convolve_params.items() if param.default is not inspect.Parameter.empty } if not set(kwargs.keys()).issubset(convolve_configs): diff --git a/tests/test_basis.py b/tests/test_basis.py index dfb23c53..a584468e 100644 --- a/tests/test_basis.py +++ b/tests/test_basis.py @@ -500,13 +500,22 @@ def test_init_mode(self, mode, expectation): [ (dict(), does_not_raise()), (dict(axis=0), does_not_raise()), - (dict(axis=1), pytest.raises(ValueError, match="Invalid `axis=1` provided")), + ( + dict(axis=1), + pytest.raises(ValueError, match="Invalid `axis=1` provided"), + ), (dict(shift=True), does_not_raise()), (dict(shift=True, axis=0), does_not_raise()), - (dict(shifts=True, axis=0), pytest.raises(ValueError, match="Unrecognized keyword arguments")), + ( + dict(shifts=True, axis=0), + pytest.raises(ValueError, match="Unrecognized keyword arguments"), + ), (dict(shift=True, axis=0, predictor_causality="causal"), does_not_raise()), - (dict(shift=True, axis=0, time_series=np.arange(10)), pytest.raises(ValueError, match="Unrecognized keyword arguments")), - ] + ( + dict(shift=True, axis=0, time_series=np.arange(10)), + pytest.raises(ValueError, match="Unrecognized keyword arguments"), + ), + ], ) def test_init_conv_kwargs(self, conv_kwargs, expectation): with expectation: @@ -584,7 +593,10 @@ def test_set_params( for i in range(len(pars)): for j in range(i + 1, len(pars)): - with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "): + with pytest.raises( + AttributeError, + match="can't set attribute 'mode'|property 'mode' of ", + ): par_set = { keys[i]: pars[keys[i]], keys[j]: pars[keys[j]], @@ -1166,14 +1178,22 @@ def test_init_mode(self, mode, expectation): [ (dict(), does_not_raise()), (dict(axis=0), does_not_raise()), - (dict(axis=1), pytest.raises(ValueError, match="Invalid `axis=1` provided")), + ( + dict(axis=1), + pytest.raises(ValueError, match="Invalid `axis=1` provided"), + ), (dict(shift=True), does_not_raise()), (dict(shift=True, axis=0), does_not_raise()), - (dict(shifts=True, axis=0), pytest.raises(ValueError, match="Unrecognized keyword arguments")), + ( + dict(shifts=True, axis=0), + pytest.raises(ValueError, match="Unrecognized keyword arguments"), + ), (dict(shift=True, axis=0, predictor_causality="causal"), does_not_raise()), - (dict(shift=True, axis=0, time_series=np.arange(10)), - pytest.raises(ValueError, match="Unrecognized keyword arguments")), - ] + ( + dict(shift=True, axis=0, time_series=np.arange(10)), + pytest.raises(ValueError, match="Unrecognized keyword arguments"), + ), + ], ) def test_init_conv_kwargs(self, conv_kwargs, expectation): with expectation: @@ -1237,7 +1257,10 @@ def test_set_params( for i in range(len(pars)): for j in range(i + 1, len(pars)): - with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "): + with pytest.raises( + AttributeError, + match="can't set attribute 'mode'|property 'mode' of ", + ): par_set = { keys[i]: pars[keys[i]], keys[j]: pars[keys[j]], @@ -1818,14 +1841,22 @@ def test_init_mode(self, mode, expectation): [ (dict(), does_not_raise()), (dict(axis=0), does_not_raise()), - (dict(axis=1), pytest.raises(ValueError, match="Invalid `axis=1` provided")), + ( + dict(axis=1), + pytest.raises(ValueError, match="Invalid `axis=1` provided"), + ), (dict(shift=True), does_not_raise()), (dict(shift=True, axis=0), does_not_raise()), - (dict(shifts=True, axis=0), pytest.raises(ValueError, match="Unrecognized keyword arguments")), + ( + dict(shifts=True, axis=0), + pytest.raises(ValueError, match="Unrecognized keyword arguments"), + ), (dict(shift=True, axis=0, predictor_causality="causal"), does_not_raise()), - (dict(shift=True, axis=0, time_series=np.arange(10)), - pytest.raises(ValueError, match="Unrecognized keyword arguments")), - ] + ( + dict(shift=True, axis=0, time_series=np.arange(10)), + pytest.raises(ValueError, match="Unrecognized keyword arguments"), + ), + ], ) def test_init_conv_kwargs(self, conv_kwargs, expectation): with expectation: @@ -1889,7 +1920,10 @@ def test_set_params( for i in range(len(pars)): for j in range(i + 1, len(pars)): - with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "): + with pytest.raises( + AttributeError, + match="can't set attribute 'mode'|property 'mode' of ", + ): par_set = { keys[i]: pars[keys[i]], keys[j]: pars[keys[j]], @@ -2548,18 +2582,32 @@ def test_init_mode(self, mode, expectation): [ (dict(), does_not_raise()), (dict(axis=0), does_not_raise()), - (dict(axis=1), pytest.raises(ValueError, match="Invalid `axis=1` provided")), + ( + dict(axis=1), + pytest.raises(ValueError, match="Invalid `axis=1` provided"), + ), (dict(shift=True), does_not_raise()), (dict(shift=True, axis=0), does_not_raise()), - (dict(shifts=True, axis=0), pytest.raises(ValueError, match="Unrecognized keyword arguments")), + ( + dict(shifts=True, axis=0), + pytest.raises(ValueError, match="Unrecognized keyword arguments"), + ), (dict(shift=True, axis=0, predictor_causality="causal"), does_not_raise()), - (dict(shift=True, axis=0, time_series=np.arange(10)), - pytest.raises(ValueError, match="Unrecognized keyword arguments")), - ] + ( + dict(shift=True, axis=0, time_series=np.arange(10)), + pytest.raises(ValueError, match="Unrecognized keyword arguments"), + ), + ], ) def test_init_conv_kwargs(self, conv_kwargs, expectation): with expectation: - self.cls(5, mode="conv", window_size=200, decay_rates=np.arange(1, 6), **conv_kwargs) + self.cls( + 5, + mode="conv", + window_size=200, + decay_rates=np.arange(1, 6), + **conv_kwargs, + ) @pytest.mark.parametrize( "mode, ws, expectation", @@ -2628,7 +2676,10 @@ def test_set_params( for i in range(len(pars)): for j in range(i + 1, len(pars)): - with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "): + with pytest.raises( + AttributeError, + match="can't set attribute 'mode'|property 'mode' of ", + ): par_set = { keys[i]: pars[keys[i]], keys[j]: pars[keys[j]], @@ -3154,14 +3205,22 @@ def test_init_mode(self, mode, expectation): [ (dict(), does_not_raise()), (dict(axis=0), does_not_raise()), - (dict(axis=1), pytest.raises(ValueError, match="Invalid `axis=1` provided")), + ( + dict(axis=1), + pytest.raises(ValueError, match="Invalid `axis=1` provided"), + ), (dict(shift=True), does_not_raise()), (dict(shift=True, axis=0), does_not_raise()), - (dict(shifts=True, axis=0), pytest.raises(ValueError, match="Unrecognized keyword arguments")), + ( + dict(shifts=True, axis=0), + pytest.raises(ValueError, match="Unrecognized keyword arguments"), + ), (dict(shift=True, axis=0, predictor_causality="causal"), does_not_raise()), - (dict(shift=True, axis=0, time_series=np.arange(10)), - pytest.raises(ValueError, match="Unrecognized keyword arguments")), - ] + ( + dict(shift=True, axis=0, time_series=np.arange(10)), + pytest.raises(ValueError, match="Unrecognized keyword arguments"), + ), + ], ) def test_init_conv_kwargs(self, conv_kwargs, expectation): with expectation: @@ -3225,7 +3284,10 @@ def test_set_params( for i in range(len(pars)): for j in range(i + 1, len(pars)): - with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "): + with pytest.raises( + AttributeError, + match="can't set attribute 'mode'|property 'mode' of ", + ): par_set = { keys[i]: pars[keys[i]], keys[j]: pars[keys[j]], @@ -3881,7 +3943,10 @@ def test_set_params( for i in range(len(pars)): for j in range(i + 1, len(pars)): - with pytest.raises(AttributeError, match="can't set attribute 'mode'|property 'mode' of "): + with pytest.raises( + AttributeError, + match="can't set attribute 'mode'|property 'mode' of ", + ): par_set = { keys[i]: pars[keys[i]], keys[j]: pars[keys[j]],