fix: Basis.image_2d_from and dPIEPotential.convergence_2d_from return wrong wrapper types#425
Merged
Merged
Conversation
Two profile-return-type bugs surfaced while writing the autolens_workspace mass / light profile guides: 1. Basis.image_2d_list_from returned a raw xp.zeros((N,)) ndarray as the placeholder for LightProfileLinear constituents, so a basis composed entirely of linear profiles produced an image_2d_from = sum([ndarray, ndarray, ...]) that was itself a raw ndarray, contradicting the -> aa.Array2D return annotation. Wrap the placeholder in aa.Array2D so the return type is uniform. 2. dPIEPotential.convergence_2d_from was decorated with @aa.decorators.to_vector_yx (the deflections decorator directly above it) instead of @aa.decorators.to_array — the scalar convergence was being wrapped as a VectorYX2D. The Sph variant below already uses the correct decorator; this brings the elliptical variant in line. Adds regression tests for both fixes asserting the correct wrapper type. Closes #424. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Two profile-return-type bugs surfaced while writing the new
autolens_workspace/scripts/guides/profiles/{light,mass}.pyguides (#86 / #176 / #178 /#179). Both forced workarounds in the workspace guides; both are tiny library-side fixes
that tighten the type contract advertised by the methods' annotations.
Closes #424.
API Changes
None — return-type fix only.
Basis.image_2d_fromanddPIEPotential.convergence_2d_fromalready advertisedaa.Array2Dreturn types in theirannotations; this PR makes the runtime behaviour match. Any caller that already relies on
the (incorrect)
numpy.ndarray/VectorYX2Dreturns will see a tighter type — none inthe codebase or workspaces do, since both methods were unusable through
aplt.plot_arraybefore this fix.See full details below.
Test Plan
python -m pytest test_autogalaxy/passes (full test suite as baseline)test_basis.pyandtest_dual_pseudo_isothermal_potential.pypassaplt.plot_array(array=basis.image_2d_from(grid=grid))now works for a basis oflp_linearconstituents (no Galaxy wrap needed).aplt.plot_array(array=mp.dPIEPotential(...).convergence_2d_from(grid=grid))now works.Full API Changes (for automation & release notes)
Fixed
autogalaxy.profiles.basis.Basis.image_2d_from— previously returned a rawnumpy.ndarraywhen the basis contained onlyLightProfileLinearconstituents (the MGE case); now returnsaa.Array2Duniformly.autogalaxy.profiles.mass.total.dual_pseudo_isothermal_potential.dPIEPotential.convergence_2d_from— previously returnedaa.VectorYX2D(wrong wrapper from a copy-paste of the deflections decorator); now returnsaa.Array2Dmatching the correspondingdPIEPotentialSph.convergence_2d_fromalready in the same file.Added (tests only)
test_autogalaxy/profiles/test_basis.py::test__image_2d_from__returns_array2d_for_linear_only_basis— regression test for the Basis fix.test_autogalaxy/profiles/mass/total/test_dual_pseudo_isothermal_potential.py::test__convergence_2d_from__returns_array2d_not_vector— regression test for the dPIEPotential fix.Removed / Renamed / Changed Signature / Changed Behaviour / Migration
🤖 Generated with Claude Code