Skip to content

Commit

Permalink
Ruff: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
attack68 committed Jan 9, 2025
1 parent e007a50 commit ef58733
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 60 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ packages = [
"rateslib"
]
exclude = [
"/instruments/bonds/__init__.py",
"/instruments/bonds/futures.py",
"/instruments/bonds/securities.py",
"/instruments/fx_volatility.py",
Expand Down
119 changes: 77 additions & 42 deletions python/rateslib/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 _

Expand Down
4 changes: 2 additions & 2 deletions python/rateslib/fx/fx_forwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def __repr__(self) -> str:
if len(self.currencies_list) > 5:
return (
f"<rl.FXForwards:[{','.join(self.currencies_list[:2])},"
f"+{len(self.currencies_list)-2} others] at {hex(id(self))}>"
f"+{len(self.currencies_list) - 2} others] at {hex(id(self))}>"
)
else:
return f"<rl.FXForwards:[{','.join(self.currencies_list)}] at {hex(id(self))}>"
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions python/rateslib/fx/fx_rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def __copy__(self) -> FXRates:
def __repr__(self) -> str:
if len(self.currencies_list) > 5:
return (
f"<rl.FXRates:[{','.join(self.currencies_list[:2])},+{len(self.currencies_list)-2} "
f"others] at {hex(id(self))}>"
f"<rl.FXRates:[{','.join(self.currencies_list[:2])},"
f"+{len(self.currencies_list) - 2} others] at {hex(id(self))}>"
)
else:
return f"<rl.FXRates:[{','.join(self.currencies_list)}] at {hex(id(self))}>"
Expand Down
4 changes: 2 additions & 2 deletions python/rateslib/instruments/bonds/futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
],
}
Expand Down
7 changes: 3 additions & 4 deletions python/rateslib/periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
7 changes: 3 additions & 4 deletions python/rateslib/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion python/tests/test_periods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion rust/calendars/named/fed_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion rust/calendars/named/nyc_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ef58733

Please sign in to comment.