Skip to content

Commit

Permalink
Use implicit string concatenation instead of explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
Armavica committed Jul 12, 2024
1 parent f75434f commit a6b9585
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 47 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ line-length = 88
exclude = ["doc/", "pytensor/_version.py"]

[tool.ruff.lint]
select = ["C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH"]
ignore = ["C408", "C901", "E501", "E741", "RUF012", "PERF203"]
select = ["C", "E", "F", "I", "UP", "W", "RUF", "PERF", "PTH", "ISC"]
ignore = ["C408", "C901", "E501", "E741", "RUF012", "PERF203", "ISC001"]


[tool.ruff.lint.isort]
Expand Down
4 changes: 1 addition & 3 deletions pytensor/bin/pytensor_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def print_help(exit_status):
print('Type "pytensor-cache clear" to erase the cache')
print('Type "pytensor-cache list" to print the cache content')
print('Type "pytensor-cache unlock" to unlock the cache directory')
print(
'Type "pytensor-cache cleanup" to delete keys in the old ' "format/code version"
)
print('Type "pytensor-cache cleanup" to delete keys in the old format/code version')
print('Type "pytensor-cache purge" to force deletion of the cache directory')
print(
'Type "pytensor-cache basecompiledir" '
Expand Down
26 changes: 9 additions & 17 deletions pytensor/compile/debugmode.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,14 +1614,10 @@ def f():
opt = str(reason[0][0])
msg = (
f"An optimization (probably {opt}) inserted an "
"apply node that raise an error."
+ "\nThe information we have about this "
"optimizations is:"
+ str(reason[0][1])
+ "\n"
+ reason[0][2]
+ "\n\nThe original exception: \n"
+ str(e)
"apply node that raise an error.\n"
"The information we have about this optimization is:"
f"{reason[0][1]}\n{reason[0][2]}\n"
f"\nThe original exception: \n{e}"
)
new_e = e.__class__(msg)
exc_type, exc_value, exc_trace = sys.exc_info()
Expand Down Expand Up @@ -1725,15 +1721,11 @@ def f():
raise
opt = str(reason[0][0])
msg = (
f"An optimization (probably {opt}) inserted "
"an apply node that raise an error."
+ "\nThe information we have about this "
"optimizations is:"
+ str(reason[0][1])
+ "\n"
+ reason[0][2]
+ "\n\nThe original exception: \n"
+ str(e)
f"An optimization (probably {opt}) inserted an "
"apply node that raise an error.\n"
"The information we have about this optimization is:"
f"{reason[0][1]}\n{reason[0][2]}\n"
f"\nThe original exception: \n{e}"
)
new_e = e.__class__(msg)
exc_type, exc_value, exc_trace = sys.exc_info()
Expand Down
10 changes: 5 additions & 5 deletions pytensor/gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,20 +802,20 @@ def _node_to_pattern(node):
if not isinstance(connection_pattern, list):
raise TypeError(
"Op.connection_pattern should return "
+ f"list of list of bool, but for Op={node.op}"
+ f"got {connection_pattern} with type {type(connection_pattern)}."
f"list of list of bool, but for Op={node.op}"
f"got {connection_pattern} with type {type(connection_pattern)}."
)
if len(connection_pattern) != len(node.inputs):
raise ValueError(
f"{node.op}.connection_pattern should have {len(node.inputs)}"
+ f" rows but has {len(connection_pattern)}."
f" rows but has {len(connection_pattern)}."
)
for ii, output_pattern in enumerate(connection_pattern):
if not isinstance(output_pattern, list):
raise TypeError(
f"{node.op}.connection_pattern should return"
+ f" a list of lists, but element {int(ii)}"
+ f"is {output_pattern} of type {type(output_pattern)}."
f" a list of lists, but element {int(ii)}"
f"is {output_pattern} of type {type(output_pattern)}."
)
else:
connection_pattern = [[True for output in node.outputs] for ipt in node.inputs]
Expand Down
8 changes: 4 additions & 4 deletions pytensor/graph/rewriting/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ def __init__(
def __str__(self):
return (
"RewriteDatabaseQuery("
+ f"inc={self.include},ex={self.exclude},"
+ f"require={self.require},subquery={self.subquery},"
+ f"position_cutoff={self.position_cutoff},"
+ f"extra_rewrites={self.extra_rewrites})"
f"inc={self.include},ex={self.exclude},"
f"require={self.require},subquery={self.subquery},"
f"position_cutoff={self.position_cutoff},"
f"extra_rewrites={self.extra_rewrites})"
)

def __setstate__(self, state):
Expand Down
8 changes: 2 additions & 6 deletions pytensor/link/c/cmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -1744,9 +1744,7 @@ def std_lib_dirs_and_libs() -> tuple[list[str], ...] | None:
if not os.path.exists(os.path.join(libdir, f)):
print(
"Your Python version is from Canopy. "
+ "You need to install the package '"
+ lib
+ "' from Canopy package manager."
f"You need to install the package '{lib}' from Canopy package manager."
)
libdirs = [
# Used in older Canopy
Expand All @@ -1763,9 +1761,7 @@ def std_lib_dirs_and_libs() -> tuple[list[str], ...] | None:
):
print(
"Your Python version is from Canopy. "
+ "You need to install the package '"
+ lib
+ "' from Canopy package manager."
f"You need to install the package '{lib}' from Canopy package manager."
)
python_lib_dirs.insert(0, libdir)
std_lib_dirs_and_libs.data = [libname], python_lib_dirs
Expand Down
4 changes: 2 additions & 2 deletions pytensor/link/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ def raise_with_op(
clients = [[c[0] for c in fgraph.clients[var]] for var in node.outputs]
detailed_err_msg += (
f"Inputs shapes: {shapes}"
+ f"\nInputs strides: {strides}"
+ f"\nInputs values: {scalar_values}"
f"\nInputs strides: {strides}"
f"\nInputs values: {scalar_values}"
)
if verbosity == "high":
inpts = [
Expand Down
4 changes: 2 additions & 2 deletions pytensor/scalar/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ def c_code(self, node, name, inputs, outputs, sub):
if any(i.type in complex_types for i in node.inputs):
raise NotImplementedError()
# Test for both y>x and x>=y to detect NaN
return f"{z} = (({y})>({x})? ({y}): " f'(({x})>=({y})? ({x}): nan("")));'
return f'{z} = (({y})>({x})? ({y}): (({x})>=({y})? ({x}): nan("")));'

def L_op(self, inputs, outputs, gout):
(x, y) = inputs
Expand Down Expand Up @@ -1795,7 +1795,7 @@ def c_code(self, node, name, inputs, outputs, sub):
(z,) = outputs
if any(i.type in complex_types for i in node.inputs):
raise NotImplementedError()
return f"{z} = (({y})<({x})? ({y}): " f'(({x})<=({y})? ({x}): nan("")));'
return f'{z} = (({y})<({x})? ({y}): (({x})<=({y})? ({x}): nan("")));'

def L_op(self, inputs, outputs, gout):
(x, y) = inputs
Expand Down
4 changes: 2 additions & 2 deletions pytensor/sparse/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,8 +1382,8 @@ def make_node(self, x, index):
isinstance(ind, Variable) and getattr(ind, "ndim", -1) == 0
) or np.isscalar(ind):
raise NotImplementedError(
"PyTensor has no sparse vector"
+ "Use X[a:b, c:d], X[a:b, c:c+1] or X[a:b] instead."
"PyTensor has no sparse vector. "
"Use X[a:b, c:d], X[a:b, c:c+1] or X[a:b] instead."
)
else:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion pytensor/tensor/conv/abstract_conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2284,7 +2284,7 @@ def conv(
"""
if mode not in ("valid", "full"):
raise ValueError(
f"invalid mode {mode}, which must be either " '"valid" or "full"'
f'invalid mode {mode}, which must be either "valid" or "full"'
)
if isinstance(dilation, int):
dilation = (dilation,) * self.convdim
Expand Down
2 changes: 1 addition & 1 deletion pytensor/tensor/fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def make_node(self, a, s=None):
if a.ndim < 3:
raise TypeError(
f"{self.__class__.__name__}: input must have dimension >= 3, with "
+ "first dimension batches and last real/imag parts"
"first dimension batches and last real/imag parts"
)

if s is None:
Expand Down
4 changes: 2 additions & 2 deletions tests/tensor/test_blas_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def test_force_gemv_init(self):
if check_force_gemv_init():
warn(
"WARNING: The current BLAS requires PyTensor to initialize"
+ " memory for some GEMV calls which will result in a minor"
+ " degradation in performance for such calls."
" memory for some GEMV calls which will result in a minor"
" degradation in performance for such calls."
)

def t_gemv1(self, m_shp):
Expand Down

0 comments on commit a6b9585

Please sign in to comment.