Skip to content

Commit 1508219

Browse files
kshitij-mathskshitij-maths
andauthored
Fix typos and error messages (#284)
Co-authored-by: kshitij-maths <kpandey@penelope.ma.sissa.it>
1 parent 491c625 commit 1508219

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

ezyrb/database.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ class Database:
1515
1616
:param array_like parameters: the input parameters
1717
:param array_like snapshots: the input snapshots
18-
:param Scale scaler_parameters: the scaler for the parameters. Default
19-
is None meaning no scaling.
20-
:param Scale scaler_snapshots: the scaler for the snapshots. Default is
21-
None meaning no scaling.
2218
:param array_like space: the input spatial data
2319
2420
:Example:
@@ -46,6 +42,7 @@ def __init__(self, parameters=None, snapshots=None, space=None):
4642
)
4743
self._pairs = []
4844

45+
4946
if parameters is None and snapshots is None:
5047
logger.debug("Empty database created")
5148
return
@@ -149,19 +146,19 @@ def add(self, parameter, snapshot):
149146
"""
150147
if not isinstance(parameter, Parameter):
151148
logger.error("Invalid parameter type: %s", type(parameter))
152-
raise ValueError
149+
raise TypeError(f"Expected a Parameter object, got {type(parameter)}")
153150

154151
if not isinstance(snapshot, Snapshot):
155152
logger.error("Invalid snapshot type: %s", type(snapshot))
156-
raise ValueError
153+
raise TypeError(f"Expected a Snapshot object, got {type(snapshot)}")
157154

158155
self._pairs.append((parameter, snapshot))
159156
logger.debug(
160157
"Added parameter-snapshot pair. Total pairs: %d", len(self._pairs)
161158
)
162159

163160
return self
164-
161+
165162
def split(self, chunks, seed=None):
166163
"""
167164
@@ -209,7 +206,7 @@ def split(self, chunks, seed=None):
209206

210207
else:
211208
logger.error("Invalid chunk type")
212-
ValueError
209+
raise TypeError(f"Invalid chunk type. Expected a list of integers or floats, but got {type(chunks)}.")
213210

214211
new_database = [Database() for _ in range(len(chunks))]
215212
for i, chunk in enumerate(chunks):
@@ -235,4 +232,4 @@ def get_snapshot_space(self, index):
235232
"""
236233
if index < 0 or index >= len(self._pairs):
237234
raise IndexError("Snapshot index out of range.")
238-
return self._pairs[index][1].space
235+
return self._pairs[index][1].space

ezyrb/plugin/scaler.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ class DatabaseScaler(Plugin):
1010
"""
1111
The plugin to rescale the database of the reduced order model. It uses a
1212
user defined `scaler`, which has to have implemented the `fit`, `transform`
13-
and `inverse_trasform` methods (i.e. `sklearn` interface), to rescale
13+
and `inverse_transform` methods (i.e. `sklearn` interface), to rescale
1414
the parameters and/or the snapshots. It can be applied at the full order
15-
(`mode='full'`), at the reduced one (`mode='reduced'`) or both of them
16-
(`mode='both'`).
15+
(`mode='full'`) or at the reduced one (`mode='reduced'`).
1716
1817
:param obj scaler: a generic object which has to have implemented the
19-
`fit`, `transform` and `inverse_trasform` methods (i.e. `sklearn`
18+
`fit`, `transform` and `inverse_transform` methods (i.e. `sklearn`
2019
interface).
2120
:param {'full', 'reduced'} mode: define if the rescaling has to be
2221
applied at the full order ('full') or at the reduced one ('reduced').
@@ -62,11 +61,14 @@ def target(self):
6261
rtype: str
6362
"""
6463
return self._target
64+
6565

6666
@target.setter
6767
def target(self, new_target):
6868
if new_target not in ["snapshots", "parameters"]:
69-
raise ValueError
69+
error_msg = f"Invalid target: '{new_target}' must be 'snapshots' or 'parameters'."
70+
logger.error(error_msg)
71+
raise ValueError(error_msg)
7072

7173
self._target = new_target
7274

@@ -82,10 +84,13 @@ def mode(self):
8284
@mode.setter
8385
def mode(self, new_mode):
8486
if new_mode not in ["full", "reduced"]:
85-
raise ValueError
87+
error_msg = f"Invalid mode: '{new_mode}' must be 'full' or 'reduced'."
88+
logger.error(error_msg)
89+
raise ValueError(error_msg)
8690

8791
self._mode = new_mode
8892

93+
8994
def _select_matrix(self, db):
9095
"""
9196
Helper function to select the proper matrix to rescale.

0 commit comments

Comments
 (0)