Skip to content

Fix two bugs in decompose and add test coverage for Stoner.analysis.functions#38

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/0-10-x-find-data-decompose
Draft

Fix two bugs in decompose and add test coverage for Stoner.analysis.functions#38
Copilot wants to merge 2 commits intomainfrom
copilot/0-10-x-find-data-decompose

Conversation

Copy link
Contributor

Copilot AI commented Mar 25, 2026

Data.decompose is defined in Stoner/analysis/functions.py and bound onto Data via the @class_modifier decorator in Stoner/core/data.py. Two bugs were present in the implementation.

Bugs fixed

  • Wrong column header for asymmetric output — when asym= was explicitly provided, the added column was labelled "Symmetric Data" instead of "Asymmetric Data".

  • Shape broadcast error with explicit sym=/asym= columnsycol is always promoted to a list internally, causing interp1d to return (n, 1) arrays. add_column does np.atleast_2d(data).T, which transposes (n, 1)(1, n), producing a ValueError on assignment. Fixed by applying np.squeeze() to symd/asymd before use.

# Previously raised ValueError: could not broadcast shape (40401,1) into (201,201)
x = np.linspace(-5, 5, 201)
d = Data(np.column_stack([x, x**2, np.zeros_like(x), np.zeros_like(x)]),
         setas="xy..", column_headers=["X", "Y", "Sym", "Asym"])
d.decompose(sym="Sym", asym="Asym", replace=True)  # now works correctly

Tests added

New tests/Stoner/analysis/test_functions.py covering:

  • decompose is importable from Stoner.analysis.functions and accessible as Data.decompose
  • Pure symmetric (even) and antisymmetric (odd) component extraction
  • Mixed even+odd decomposition
  • Explicit output column writing with correct headers

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Investigate where Data.decompose is defined in 0.10.x branch Fix two bugs in decompose and add test coverage for Stoner.analysis.functions Mar 25, 2026
Copilot AI requested a review from gb119 March 25, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants