From ef58733674b3a915cd0636ffdca9c578ec926e1d Mon Sep 17 00:00:00 2001 From: "JHM Darbyshire (M1)" Date: Thu, 9 Jan 2025 23:08:42 +0100 Subject: [PATCH] Ruff: fmt --- pyproject.toml | 1 - python/rateslib/default.py | 119 ++++++++++++------- python/rateslib/fx/fx_forwards.py | 4 +- python/rateslib/fx/fx_rates.py | 4 +- python/rateslib/instruments/bonds/futures.py | 4 +- python/rateslib/periods.py | 7 +- python/rateslib/solver.py | 7 +- python/tests/test_periods.py | 2 +- rust/calendars/named/fed_script.py | 2 +- rust/calendars/named/nyc_script.py | 2 +- 10 files changed, 92 insertions(+), 60 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3192df67..e51bb7f6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -149,7 +149,6 @@ packages = [ "rateslib" ] exclude = [ - "/instruments/bonds/__init__.py", "/instruments/bonds/futures.py", "/instruments/bonds/securities.py", "/instruments/fx_volatility.py", diff --git a/python/rateslib/default.py b/python/rateslib/default.py index 06f87839..f08c9ef8 100644 --- a/python/rateslib/default.py +++ b/python/rateslib/default.py @@ -294,52 +294,87 @@ def _t_n(v: str) -> str: # teb-newline _: str = f"""\ Scheduling:\n -{''.join([_t_n(f'{attribute}: {getattr(self, attribute)}') for attribute in [ - 'stub', - 'stub_length', - 'modifier', - 'eom', - 'eom_fx', - 'eval_mode', - 'frequency_months', -]])} +{ + "".join( + [ + _t_n(f"{attribute}: {getattr(self, attribute)}") + for attribute in [ + "stub", + "stub_length", + "modifier", + "eom", + "eom_fx", + "eval_mode", + "frequency_months", + ] + ] + ) + } Instruments:\n -{''.join([_t_n(f'{attribute}: {getattr(self, attribute)}') for attribute in [ - 'convention', - 'payment_lag', - 'payment_lag_exchange', - 'payment_lag_specific', - 'notional', - 'fixing_method', - 'fixing_method_param', - 'spread_compound_method', - 'base_currency', - 'fx_delivery_lag', - 'fx_delta_type', - 'fx_option_metric', - 'cds_premium_accrued', - 'cds_recovery_rate', - 'cds_protection_discretization', -]])} +{ + "".join( + [ + _t_n(f"{attribute}: {getattr(self, attribute)}") + for attribute in [ + "convention", + "payment_lag", + "payment_lag_exchange", + "payment_lag_specific", + "notional", + "fixing_method", + "fixing_method_param", + "spread_compound_method", + "base_currency", + "fx_delivery_lag", + "fx_delta_type", + "fx_option_metric", + "cds_premium_accrued", + "cds_recovery_rate", + "cds_protection_discretization", + ] + ] + ) + } Curves:\n -{''.join([_t_n(f'{attribute}: {getattr(self, attribute)}') for attribute in [ - 'interpolation', - 'endpoints', - 'multi_csa_steps', - 'curve_caching', -]])} +{ + "".join( + [ + _t_n(f"{attribute}: {getattr(self, attribute)}") + for attribute in [ + "interpolation", + "endpoints", + "multi_csa_steps", + "curve_caching", + ] + ] + ) + } Solver:\n -{''.join([_t_n(f'{attribute}: {getattr(self, attribute)}') for attribute in [ - 'algorithm', - 'tag', - 'curve_not_in_solver', -]])} +{ + "".join( + [ + _t_n(f"{attribute}: {getattr(self, attribute)}") + for attribute in [ + "algorithm", + "tag", + "curve_not_in_solver", + ] + ] + ) + } Miscellaneous:\n -{''.join([_t_n(f'{attribute}: {getattr(self, attribute)}') for attribute in [ - 'headers', - 'no_fx_fixings_for_xcs', - 'pool', -]])} +{ + "".join( + [ + _t_n(f"{attribute}: {getattr(self, attribute)}") + for attribute in [ + "headers", + "no_fx_fixings_for_xcs", + "pool", + ] + ] + ) + } """ # noqa: W291 return _ diff --git a/python/rateslib/fx/fx_forwards.py b/python/rateslib/fx/fx_forwards.py index 50ddb1fd..b1399688 100644 --- a/python/rateslib/fx/fx_forwards.py +++ b/python/rateslib/fx/fx_forwards.py @@ -333,7 +333,7 @@ def __repr__(self) -> str: if len(self.currencies_list) > 5: return ( f"" + f"+{len(self.currencies_list) - 2} others] at {hex(id(self))}>" ) else: return f"" @@ -374,7 +374,7 @@ def _get_forwards_transformation_matrix( ) elif T.sum() < (2 * q) - 1: raise ValueError( - f"`fx_curves` is underspecified. {2 * q -1} curves are expected " + f"`fx_curves` is underspecified. {2 * q - 1} curves are expected " f"but {len(fx_curves.keys())} provided.", ) elif np.linalg.matrix_rank(T) != q: diff --git a/python/rateslib/fx/fx_rates.py b/python/rateslib/fx/fx_rates.py index 252e1de5..7f7184d5 100644 --- a/python/rateslib/fx/fx_rates.py +++ b/python/rateslib/fx/fx_rates.py @@ -153,8 +153,8 @@ def __copy__(self) -> FXRates: def __repr__(self) -> str: if len(self.currencies_list) > 5: return ( - f"" + f"" ) else: return f"" diff --git a/python/rateslib/instruments/bonds/futures.py b/python/rateslib/instruments/bonds/futures.py index 3149eb55..f991050c 100644 --- a/python/rateslib/instruments/bonds/futures.py +++ b/python/rateslib/instruments/bonds/futures.py @@ -409,7 +409,7 @@ def dlv( dirty=dirty, ) df["Bond"] = [ - f"{bond.fixed_rate:,.3f}% " f"{bond.leg1.schedule.termination.strftime('%d-%m-%Y')}" + f"{bond.fixed_rate:,.3f}% {bond.leg1.schedule.termination.strftime('%d-%m-%Y')}" for bond in self.basket ] return df @@ -483,7 +483,7 @@ def cms( data = { "Bond": [ - f"{bond.fixed_rate:,.3f}% " f"{bond.leg1.schedule.termination.strftime('%d-%m-%Y')}" + f"{bond.fixed_rate:,.3f}% {bond.leg1.schedule.termination.strftime('%d-%m-%Y')}" for bond in self.basket ], } diff --git a/python/rateslib/periods.py b/python/rateslib/periods.py index a5c26943..b1209ae9 100644 --- a/python/rateslib/periods.py +++ b/python/rateslib/periods.py @@ -637,7 +637,7 @@ def _validate_float_args( ) elif fixing_method_ == "rfr_lockout" and method_param_ < 1: raise ValueError( - f'`method_param` must be >0 for "rfr_lockout" `fixing_method`, ' f"got {method_param_}", + f'`method_param` must be >0 for "rfr_lockout" `fixing_method`, got {method_param_}', ) spread_compound_method_: str = _drb( @@ -1280,7 +1280,7 @@ def _rate_rfr_avg_with_spread( # dcf_vals = dcf_vals.set_axis(rates.index) if self.spread_compound_method != "none_simple": raise ValueError( - "`spread_compound` method must be 'none_simple' in an RFR averaging " "period.", + "`spread_compound` method must be 'none_simple' in an RFR averaging period.", ) else: _: DualTypes = (dcf_vals * rates).sum() / dcf_vals.sum() + self.float_spread / 100 @@ -1366,8 +1366,7 @@ def _rfr_get_series_with_populated_fixings( elif isinstance(self.fixings, Series): if not self.fixings.index.is_monotonic_increasing: # type: ignore[attr-defined] raise ValueError( - "`fixings` as a Series must have a monotonically increasing " - "datetimeindex.", + "`fixings` as a Series must have a monotonically increasing datetimeindex.", ) # [-2] is used because the last rfr fixing is 1 day before the end fixing_rates = self.fixings.loc[obs_dates.iloc[0] : obs_dates.iloc[-2]] # type: ignore[attr-defined, misc] diff --git a/python/rateslib/solver.py b/python/rateslib/solver.py index 1e7c5433..37160f4f 100644 --- a/python/rateslib/solver.py +++ b/python/rateslib/solver.py @@ -70,7 +70,7 @@ def J2(self): if self._J2 is None: if self._ad != 2: raise ValueError( - "Cannot perform second derivative calculations when ad mode is " f"{self._ad}.", + f"Cannot perform second derivative calculations when ad mode is {self._ad}.", ) rates = np.array([_[0].rate(*_[1], **_[2]) for _ in self.instruments]) @@ -237,7 +237,7 @@ def J2_pre(self): if self._J2_pre is None: if self._ad != 2: raise ValueError( - "Cannot perform second derivative calculations when ad mode is " f"{self._ad}.", + f"Cannot perform second derivative calculations when ad mode is {self._ad}.", ) J2 = np.zeros(shape=(self.pre_n, self.pre_n, self.pre_m)) @@ -952,8 +952,7 @@ def __init__( # validate `s` and `instruments` with a naive length comparison if len(s) != len(instruments): raise ValueError( - f"`s: {len(s)}` (rates) must be same length as " - f"`instruments: {len(instruments)}`." + f"`s: {len(s)}` (rates) must be same length as `instruments: {len(instruments)}`." ) self.s = np.asarray(s) diff --git a/python/tests/test_periods.py b/python/tests/test_periods.py index 160d6014..08b4ac7d 100644 --- a/python/tests/test_periods.py +++ b/python/tests/test_periods.py @@ -324,7 +324,7 @@ def test_rfr_avg_method_raises(self, curve) -> None: fixing_method="rfr_payment_delay_avg", spread_compound_method="isda_compounding", ) - msg = "`spread_compound` method must be 'none_simple' in an RFR averaging " "period." + msg = "`spread_compound` method must be 'none_simple' in an RFR averaging period." with pytest.raises(ValueError, match=msg): period.rate(curve) diff --git a/rust/calendars/named/fed_script.py b/rust/calendars/named/fed_script.py index dba07f93..1d62365d 100644 --- a/rust/calendars/named/fed_script.py +++ b/rust/calendars/named/fed_script.py @@ -19,7 +19,7 @@ day=1, offset=DateOffset(weekday=MO(3)), ), - Holiday("US President" "s Day", month=2, day=1, offset=DateOffset(weekday=MO(3))), + Holiday("US Presidents Day", month=2, day=1, offset=DateOffset(weekday=MO(3))), # Holiday("Good Friday", month=1, day=1, offset=[Easter(), Day(-2)]), Holiday("US Memorial Day", month=5, day=31, offset=DateOffset(weekday=MO(-1))), Holiday( diff --git a/rust/calendars/named/nyc_script.py b/rust/calendars/named/nyc_script.py index 2640d6d7..74e7c797 100644 --- a/rust/calendars/named/nyc_script.py +++ b/rust/calendars/named/nyc_script.py @@ -19,7 +19,7 @@ day=1, offset=DateOffset(weekday=MO(3)), ), - Holiday("US President" "s Day", month=2, day=1, offset=DateOffset(weekday=MO(3))), + Holiday("US Presidents Day", month=2, day=1, offset=DateOffset(weekday=MO(3))), Holiday("Good Friday", month=1, day=1, offset=[Easter(), Day(-2)]), Holiday("US Memorial Day", month=5, day=31, offset=DateOffset(weekday=MO(-1))), Holiday(