@@ -184,7 +184,7 @@ def get_context(cls, error_if_none=True) -> Optional[T]:
184
184
# Calling code expects to get a TypeError if the entity
185
185
# is unfound, and there's too much to fix.
186
186
if error_if_none :
187
- raise TypeError ("No %s on context stack" % str ( cls ) )
187
+ raise TypeError (f "No { cls } on context stack" )
188
188
return None
189
189
return candidate
190
190
@@ -200,9 +200,9 @@ def get_contexts(cls) -> List[T]:
200
200
# no race-condition here, contexts is a thread-local object
201
201
# be sure not to override contexts in a subclass however!
202
202
context_class = cls .context_class
203
- assert isinstance (context_class , type ), (
204
- "Name of context class, %s was not resolvable to a class" % context_class
205
- )
203
+ assert isinstance (
204
+ context_class , type
205
+ ), f"Name of context class, { context_class } was not resolvable to a class"
206
206
if not hasattr (context_class , "contexts" ):
207
207
context_class .contexts = threading .local ()
208
208
@@ -223,15 +223,14 @@ def resolve_type(c: Union[Type, str]) -> Type:
223
223
c = getattr (modules [cls .__module__ ], c )
224
224
if isinstance (c , type ):
225
225
return c
226
- raise ValueError ("Cannot resolve context class %s" % c )
226
+ raise ValueError (f "Cannot resolve context class { c } " )
227
227
228
228
assert cls is not None
229
229
if isinstance (cls ._context_class , str ):
230
230
cls ._context_class = resolve_type (cls ._context_class )
231
231
if not isinstance (cls ._context_class , (str , type )):
232
232
raise ValueError (
233
- "Context class for %s, %s, is not of the right type"
234
- % (cls .__name__ , cls ._context_class )
233
+ f"Context class for { cls .__name__ } , { cls ._context_class } , is not of the right type"
235
234
)
236
235
return cls ._context_class
237
236
@@ -334,7 +333,7 @@ def logpt(self):
334
333
else :
335
334
logp = self .logp_sum_unscaledt
336
335
if self .name is not None :
337
- logp .name = "__logp_%s" % self .name
336
+ logp .name = f "__logp_{ self .name } "
338
337
return logp
339
338
340
339
@property
@@ -345,7 +344,7 @@ def logp_nojact(self):
345
344
else :
346
345
logp = at .sum (self .logp_nojac_unscaledt )
347
346
if self .name is not None :
348
- logp .name = "__logp_%s" % self .name
347
+ logp .name = f "__logp_{ self .name } "
349
348
return logp
350
349
351
350
@@ -709,7 +708,7 @@ def logp_dlogp_function(self, grad_vars=None, tempered=False, **kwargs):
709
708
else :
710
709
for i , var in enumerate (grad_vars ):
711
710
if var .dtype not in continuous_types :
712
- raise ValueError ("Can only compute the gradient of continuous types: %s" % var )
711
+ raise ValueError (f "Can only compute the gradient of continuous types: { var } " )
713
712
# We allow one to pass the random variable terms as arguments
714
713
if hasattr (var .tag , "value_var" ):
715
714
grad_vars [i ] = var .tag .value_var
@@ -756,7 +755,7 @@ def logpt(self):
756
755
757
756
logp_var = at .sum ([at .sum (factor ) for factor in factors ])
758
757
if self .name :
759
- logp_var .name = "__logp_%s" % self .name
758
+ logp_var .name = f "__logp_{ self .name } "
760
759
else :
761
760
logp_var .name = "__logp"
762
761
return logp_var
@@ -786,7 +785,7 @@ def logp_nojact(self):
786
785
logp_var = at .sum ([at .sum (factor ) for factor in factors ])
787
786
788
787
if self .name :
789
- logp_var .name = "__logp_nojac_%s" % self .name
788
+ logp_var .name = f "__logp_nojac_{ self .name } "
790
789
else :
791
790
logp_var .name = "__logp_nojac"
792
791
return logp_var
@@ -990,10 +989,10 @@ def shape_from_dims(self, dims):
990
989
for dim in dims :
991
990
if dim not in self .coords :
992
991
raise ValueError (
993
- "Unknown dimension name '%s '. All dimension "
992
+ f "Unknown dimension name '{ dim } '. All dimension "
994
993
"names must be specified in the `coords` "
995
994
"argument of the model or through a pm.Data "
996
- "variable." % dim
995
+ "variable."
997
996
)
998
997
shape .extend (np .shape (self .coords [dim ]))
999
998
return tuple (shape )
@@ -1361,7 +1360,7 @@ def add_random_variable(self, var, dims: Optional[Tuple[Union[str, None], ...]]
1361
1360
1362
1361
@property
1363
1362
def prefix (self ):
1364
- return "%s_" % self .name if self .name else ""
1363
+ return f" { self .name } _" if self .name else ""
1365
1364
1366
1365
def name_for (self , name ):
1367
1366
"""Checks if name has prefix and adds if needed"""
@@ -1581,16 +1580,16 @@ def check_start_vals(self, start):
1581
1580
valid_keys = ", " .join (self .named_vars .keys ())
1582
1581
raise KeyError (
1583
1582
"Some start parameters do not appear in the model!\n "
1584
- "Valid keys are: {}, but {} was supplied" . format ( valid_keys , extra_keys )
1583
+ f "Valid keys are: { valid_keys } , but { extra_keys } was supplied"
1585
1584
)
1586
1585
1587
1586
initial_eval = self .point_logps (point = elem )
1588
1587
1589
1588
if not np .all (np .isfinite (initial_eval )):
1590
1589
raise SamplingError (
1591
1590
"Initial evaluation of model at starting point failed!\n "
1592
- "Starting values:\n {}\n \n "
1593
- "Initial evaluation results:\n {}" . format ( elem , str ( initial_eval ))
1591
+ f "Starting values:\n { elem } \n \n "
1592
+ f "Initial evaluation results:\n { initial_eval } "
1594
1593
)
1595
1594
1596
1595
def check_test_point (self , * args , ** kwargs ):
0 commit comments