-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix: slice numpy array values in custom_data per row in CSVSink
#2199
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: develop
Are you sure you want to change the base?
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -144,7 +144,13 @@ def parse_detection_data( | |||||
| row[key] = value[i] if hasattr(value, "__getitem__") else value | ||||||
|
|
||||||
| if custom_data: | ||||||
| row.update(custom_data) | ||||||
| for key, value in custom_data.items(): | ||||||
| if isinstance(value, np.ndarray) and value.ndim == 0: | ||||||
| row[key] = value | ||||||
| elif isinstance(value, np.ndarray): | ||||||
| row[key] = value[i] | ||||||
| else: | ||||||
| row[key] = value | ||||||
|
||||||
| row[key] = value | |
| row[key] = value[i] if hasattr(value, "__getitem__") else value |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,7 +118,13 @@ def parse_detection_data( | |
| ) | ||
|
|
||
| if custom_data: | ||
| row.update(custom_data) | ||
| for key, value in custom_data.items(): | ||
| if isinstance(value, np.ndarray) and value.ndim == 0: | ||
| row[key] = str(value) | ||
| elif isinstance(value, np.ndarray): | ||
| row[key] = str(value[i]) | ||
| else: | ||
|
Comment on lines
+121
to
+126
|
||
| row[key] = value | ||
|
Comment on lines
120
to
+127
|
||
| parsed_rows.append(row) | ||
|
Comment on lines
120
to
128
|
||
| return parsed_rows | ||
|
|
||
|
|
||
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.
Indexing
custom_datanumpy arrays withvalue[i]can raiseIndexErrorwhen the provided array length doesn't match the number of detections (including a 1-element array intended to broadcast). Consider validating lengths and either broadcasting or raising a clearValueErrordescribing the expected shape to make failures easier to debug.