Ensure freq_axis metadata propagation during NumPy ufunc evaluation#147
Ensure freq_axis metadata propagation during NumPy ufunc evaluation#147vishwas-droid wants to merge 1 commit intosunpy:mainfrom
Conversation
08b21d4 to
44e0b0f
Compare
|
This is not specific to this PR. I'm posting this to all open PRs. Please be aware of the update to our AI usage policy, specifically on the disclosure of and acceptable uses of AI. |
|
Is there an issue this PR is addressing? I'm not sure we want to support such operations of if this will be possible if/when we change the underling data model. |
|
Thanks for the question. Yes — this PR addresses a concrete issue where The goal here is not to expand supported operations, but to preserve existing metadata for operations that already return valid If the underlying data model changes in the future, this implementation can be adapted or removed accordingly — but currently it ensures consistency with user expectations and prevents silent metadata loss. If this behavior is not something we want to guarantee long-term, I’m happy to adjust the scope or explore alternative approaches. |
|
Sorry I meant an issue as in a GitHub issue not as in a code problem/bug. Generally requires PR to address open issue where the scope and direction of the solution can be discussed before any coding. |
|
Thanks for clarifying. I’ll open an issue to discuss the scope first and adjust the PR accordingly. |
Spectrumobjects were losing theirfreq_axismetadata when passed through NumPy ufuncs(e.g.,
np.sqrt,np.log, arithmetic operations such asspec + 2).Although the resulting object remained a
Spectruminstance, the associated metadatawas silently dropped, which could lead to incorrect downstream scientific interpretation.
What This PR Does
This PR implements a custom
__array_ufunc__override to:Spectrumfreq_axismetadata (deep copy)Tests
Regression tests have been added to ensure:
freq_axisis preserved after unary ufuncs (e.g.,np.sqrt)freq_axisis preserved after binary operations (e.g.,spec + 5)These tests prevent future silent metadata loss.
Rationale
Preserving metadata integrity is critical in scientific workflows, especially
for radio spectrogram analysis where frequency alignment is essential.