Feat: Refactor ShipParams for Efficient Array Operations and Update Tests #51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This update addresses the issue of inefficient and repetitive array operations within the
ShipParams
class (inWeatherRoutingTool/ship/shipparams.py
).Problem:
The
ShipParams
class contained highly repetitive code in methods likedefine_courses
,select
,flip
,expand_axis_for_intermediate
,get_element
,get_single_object
, andget_reduced_2D_object
. Each numerical attribute was individually handled for array manipulations, leading to verbose, error-prone, and difficult-to-maintain code.Solution:
The
ShipParams
class has been refactored to introduce dedicated class attributes (_numeric_array_attributes
and_non_numeric_array_attributes
). These lists enable an iterative approach to array operations, replacing the redundant, individual attribute manipulations with a more generic and concise loop-based implementation. This significantly reduces code duplication.Benefits:
Test Updates:
The
tests/test_ship.py
file has been updated to align with these changes.test_shipparams_get_element
method's tuple unpacking has been adjusted to match the new order of attributes returned byShipParams.get_element
.message
array initialization within bothtest_shipparams_get_element
andtest_shipparams_get_single
has been corrected.This refactoring improves the overall quality and robustness of the
ShipParams
class.