-
Notifications
You must be signed in to change notification settings - Fork 39
Linting and Formatting: adding Pylint checks to Ruff #1025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6a9181b
7193e10
dd9c8ad
8bd78aa
b3085ea
fc79838
b2b747f
75e3740
8424854
e843b8a
940009b
8edceef
64e73d9
3f87772
b83d80f
dfc7248
719014f
6e6f25d
73f3119
86cd924
9b2d1ab
11a236d
467b493
819a42a
693944d
d57fedb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -42,6 +42,10 @@ | |||||||||
from power_grid_model._core.power_grid_meta import initialize_array, power_grid_meta_data | ||||||||||
from power_grid_model._core.typing import ComponentAttributeMapping, _ComponentAttributeMappingDict | ||||||||||
|
||||||||||
SINGULAR_NDIM = 1 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a fan of the name |
||||||||||
BATCH_NDIM = 2 | ||||||||||
UNSUPPORTED_NDIM = 3 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. creating this on a global level doesn't make sense. In fact, all amount of dimensions above |
||||||||||
|
||||||||||
|
||||||||||
def is_nan(data) -> bool: | ||||||||||
""" | ||||||||||
|
@@ -166,17 +170,17 @@ def get_batch_size( | |||||||||
for attribute, array in batch_data.items(): | ||||||||||
if attribute in sym_attributes: | ||||||||||
break | ||||||||||
if array.ndim == 1: | ||||||||||
if array.ndim == SINGULAR_NDIM: | ||||||||||
raise TypeError("Incorrect dimension present in batch data.") | ||||||||||
if array.ndim == 2: | ||||||||||
if array.ndim == BATCH_NDIM: | ||||||||||
return 1 | ||||||||||
return array.shape[0] | ||||||||||
sym_array = next(iter(batch_data.values())) | ||||||||||
|
||||||||||
sym_array = cast(DenseBatchArray | BatchColumn, sym_array) | ||||||||||
if sym_array.ndim == 3: | ||||||||||
if sym_array.ndim == UNSUPPORTED_NDIM: | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems like a bug to me
Suggested change
or (but please double-check whether
Suggested change
|
||||||||||
raise TypeError("Incorrect dimension present in batch data.") | ||||||||||
if sym_array.ndim == 1: | ||||||||||
if sym_array.ndim == SINGULAR_NDIM: | ||||||||||
return 1 | ||||||||||
return sym_array.shape[0] | ||||||||||
|
||||||||||
|
@@ -222,7 +226,7 @@ def _split_numpy_array_in_batches( | |||||||||
Returns: | ||||||||||
A list with a single numpy structured array per batch | ||||||||||
""" | ||||||||||
if data.ndim == 1: | ||||||||||
if data.ndim == SINGULAR_NDIM: | ||||||||||
return [data] | ||||||||||
if data.ndim in [2, 3]: | ||||||||||
return [data[i, ...] for i in range(data.shape[0])] | ||||||||||
|
@@ -325,7 +329,7 @@ def convert_dataset_to_python_dataset(data: Dataset) -> PythonDataset: | |||||||||
# It is batch dataset if it is 2D array or a indptr/data structure | ||||||||||
is_batch: bool | None = None | ||||||||||
for component, array in data.items(): | ||||||||||
is_dense_batch = isinstance(array, np.ndarray) and array.ndim == 2 | ||||||||||
is_dense_batch = isinstance(array, np.ndarray) and array.ndim == BATCH_NDIM | ||||||||||
is_sparse_batch = isinstance(array, dict) and "indptr" in array and "data" in array | ||||||||||
if is_batch is not None and is_batch != (is_dense_batch or is_sparse_batch): | ||||||||||
raise ValueError( | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is both not descriptive enough and also not correct. This is exactly why you should be very careful with magic values. I myself did not understand what it was about until I dug more deeply into this.
3
is NOT a supported amount of dimensions, UNLESS a very specific case. Therefore,supported_dim
is not a good name.if
statement is incorrect (i.e. we found a bug)Here's my proposal:
you can also invert the if statement:
Please do this fix in a separate PR off
main
together with a unit test that tries to trigger the issue from the lowest-level public function that calls this function (i.e.,get_buffer_view
).I recommend first creating the unit tests (don't forget to commit when if fails correctly) and then applying the fix