Skip to content
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

Fix column order validation #182

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions sdrf_pipelines/sdrf/sdrf_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,19 +280,19 @@ def validate_columns_order(panda_sdrf):
error_columns_order = []
if "assay name" in list(panda_sdrf):
cnames = list(panda_sdrf)
index = cnames.index("assay name")
assay_index = cnames.index("assay name")
factor_tag = False
for column in cnames:
if ("comment" in column or "technology type" in column) and cnames.index(column) < index:
error_message = "The column " + column + "cannot be before the assay name"
for idx, column in enumerate(cnames):
if "comment" in column and idx < assay_index:
error_message = "The column " + column + " cannot be before the assay name"
error_columns_order.append(LogicError(error_message, error_type=logging.ERROR))
if (
"characteristics" in column or ("material type" in column and "factor value" not in column)
) and cnames.index(column) > index:
error_message = "The column " + column + "cannot be after the assay name"
or "technology type" in column) and idx > assay_index:
error_message = "The column " + column + " cannot be after the assay name"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor Conditional Statement for Improved Readability.

The complex conditional can be refactored for better readability by restructuring the conditions.

Consider reorganizing the condition:

if idx > assay_index and (
    "characteristics" in column
    or ("material type" in column and "factor value" not in column)
    or "technology type" in column
):

This places the index check upfront and groups the column-related conditions together, making the logic clearer.

error_columns_order.append(LogicError(error_message, error_type=logging.ERROR))
if "factor value" in column and not factor_tag:
factor_index = cnames.index(column)
factor_index = idx
factor_tag = True
if factor_tag:
temp = []
Expand Down
Loading