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

Update/integration iqair devices #4015

Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions src/workflows/airqo_etl_utils/data_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ def remove_outliers(data: pd.DataFrame) -> pd.DataFrame:
column_name=mapped_name, row_value=x
)
)
else:
data[col] = data[col].apply(
lambda x: DataValidationUtils.get_valid_value(
column_name=mapped_name, row_value=x
else:
data[col] = data[col].apply(
lambda x: DataValidationUtils.get_valid_value(
column_name=mapped_name, row_value=x
)
Comment on lines +163 to +166
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix potential loop variable binding issue.

The current implementation might lead to unexpected behavior as the lambda function captures the loop variable mapped_name from the outer scope.

Apply this fix to ensure proper variable binding:

-                data[col] = data[col].apply(
-                    lambda x: DataValidationUtils.get_valid_value(
-                        column_name=mapped_name, row_value=x
-                    )
-                )
+                mapped_name_current = mapped_name  # Capture current value
+                data[col] = data[col].apply(
+                    lambda x, name=mapped_name_current: DataValidationUtils.get_valid_value(
+                        column_name=name, row_value=x
+                    )
+                )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
data[col] = data[col].apply(
lambda x: DataValidationUtils.get_valid_value(
column_name=mapped_name, row_value=x
)
mapped_name_current = mapped_name # Capture current value
data[col] = data[col].apply(
lambda x, name=mapped_name_current: DataValidationUtils.get_valid_value(
column_name=name, row_value=x
)
)
🧰 Tools
🪛 Ruff (0.8.0)

165-165: Function definition does not bind loop variable mapped_name

(B023)

)
)
return data

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion src/workflows/airqo_etl_utils/data_warehouse_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def extract_hourly_bam_data(
},
inplace=True,
)
data.loc[:, "device_category"] = str(DeviceCategory.BAM)
data["device_category"] = str(DeviceCategory.BAM)
return DataWarehouseUtils.filter_valid_columns(data)

@staticmethod
Expand Down
Loading