Skip to content

Commit 51ad1e0

Browse files
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8e2d64a commit 51ad1e0

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

rocketpy/mathutils/function.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,6 @@ def __determine_2d_domain_bounds(self, lower, upper, samples):
679679
if self.__cropped_domain__[i][1] < domain[i][1]:
680680
domain[i][1] = self.__cropped_domain__[i][1]
681681

682-
lower = lower if lower is not None else [domain[0][0], domain[1][0]]
683682
lower = [domain[0][0], domain[1][0]] if lower is None else lower
684683
lower = 2 * [lower] if isinstance(lower, NUMERICAL_TYPES) else lower
685684
upper = [domain[0][1], domain[1][1]] if upper is None else upper
@@ -1020,7 +1019,7 @@ def __set_cropped_domain_2d(self, cropped_func, x_lim):
10201019
Range of values with lower and upper limits.
10211020
"""
10221021
if len(x_lim) < 2:
1023-
raise IndexError("x_lim must be of index 2 for 2-D function")
1022+
raise IndexError("x_lim must have a length of 2 for 2-D function")
10241023

10251024
if x_lim[0] is not None and x_lim[0][0] < x_lim[0][1]:
10261025
cropped_func.__cropped_domain__ = [x_lim[0]]
@@ -1183,9 +1182,9 @@ def clipped_function(*args):
11831182
except ValueError as e:
11841183
raise ValueError(
11851184
"Cannot clip function as function reduces to "
1186-
f"{len(clipped_func.source)} points (too few data points to define"
1187-
" a domain). Number of rows must be equal to number of "
1188-
"columns after applying clipping function."
1185+
f"{len(clipped_func.source) if isinstance(clipped_func.source, (list, np.ndarray)) else 'unknown'} points (too few data points to define"
1186+
" a domain). Ensure that the source is array-like and has "
1187+
"sufficient data points after applying the clipping function."
11891188
) from e
11901189

11911190
return clipped_func
@@ -1821,7 +1820,7 @@ def plot_1d( # pylint: disable=too-many-statements
18211820
if self.__cropped_domain__ is not None:
18221821
if self.__cropped_domain__[0] > domain[0]:
18231822
domain[0] = self.__cropped_domain__[0]
1824-
if self.__cropped_domain__[1] > domain[1]:
1823+
if self.__cropped_domain__[1] < domain[1]:
18251824
domain[1] = self.__cropped_domain__[1]
18261825
lower = domain[0] if lower is None else lower
18271826
upper = domain[1] if upper is None else upper

tests/unit/test_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def test_crop_ndarray(array3dsource, array3dcropped): # pylint: disable=unused-
276276
The source is initialized as a ndarray before cropping.
277277
"""
278278
func = Function(array3dsource, inputs=["x1", "x2"], outputs="y")
279-
cropped_func = func.crop([(-1, 1), (-2, 2)]) # pylint: disable=unused-argument
279+
cropped_func = func.crop([(-1, 1), (-2, 2)])
280280

281281
assert isinstance(func, Function)
282282
assert isinstance(cropped_func, Function)

0 commit comments

Comments
 (0)