FXC-4440: outer_dot output frequencies order not matching input #3061
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.
Tom noticed that
outer_dotwould always return the overlap data with frequency coords that are sorted in increasing order, making them mismatch the original data if it e.g. had them in decreasing order. This fixes that.Greptile Overview
Greptile Summary
This PR fixes a bug in the
outer_dotmethod where frequency coordinates were being sorted in increasing order, breaking alignment when the original data had frequencies in a different order (e.g., decreasing). The fix replaces the old implementation that usedsorted(set(...).intersection(...))with pandasIndex.intersection(sort=False)to preserve the frequency order from the first dataset.Key changes:
get_indexerto properly map frequencies between datasetsas eremoved where not used)Confidence Score: 5/5
Important Files Changed
File Analysis
outer_dotSequence Diagram
sequenceDiagram participant Client as Client Code participant Self as ElectromagneticFieldData (self) participant Other as ElectromagneticFieldData (other) participant PI as pandas.Index Client->>Self: outer_dot(field_data) Self->>Self: Get tangential fields from self Self->>Other: _interpolated_tangential_fields() Other-->>Self: Return interpolated fields Self->>Self: Extract frequency coords from both datasets Self->>PI: Index(coords[0]["f"].values) PI-->>Self: freq_self Index Self->>PI: Index(coords[1]["f"].values) PI-->>Self: freq_other Index Self->>PI: freq_self.intersection(freq_other, sort=False) Note over PI: Preserves order from freq_self<br/>(unlike old sorted approach) PI-->>Self: common_freqs Index Self->>PI: freq_self.get_indexer(common_freqs) PI-->>Self: isel1 (indices for self) Self->>PI: freq_other.get_indexer(common_freqs) PI-->>Self: isel2 (indices for other) Self->>Self: Apply isel1 to self fields Self->>Other: Apply isel2 to other fields Self->>Self: Compute dot product with aligned frequencies Self-->>Client: Return result with original frequency order