Skip to content

Commit

Permalink
Merge pull request nanograv#1794 from dlakaplan/removepar
Browse files Browse the repository at this point in the history
Fix removal of top-level parameter
  • Loading branch information
paulray authored Jun 27, 2024
2 parents e66d250 + 6b4df4b commit c28fc87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ the released changes.
- Moved the test in `test_pmtransform_units.py` into a function.
- Fixed bug in residual calculation when adding or removing phase wraps
- Fix #1766 by correcting logic and more clearly naming argument (clkcorr->undo_clkcorr)
- Fix removal of top-level parameter
- Minimal fixes to allow usage of numpy 2.0
### Removed
2 changes: 1 addition & 1 deletion src/pint/models/timing_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ def remove_param(self, param):
param_map = self.get_params_mapping()
if param not in param_map:
raise AttributeError(f"Can not find '{param}' in timing model.")
if param_map[param] == "timing_model":
if param_map[param] == "TimingModel":
delattr(self, param)
self.top_level_params.remove(param)
else:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,15 @@ def test_fitter_construction_success_after_remove_param():
f = pint.fitter.GLSFitter(toas=t, model=m)


def test_fitter_construction_success_after_remove_param_toplevel():
"""Checks that remove_param succeeds when removing a paramter from the top-level model (not always meaningful)"""
m = get_model(os.path.join(datadir, "B1855+09_NANOGrav_9yv1.gls.par"))
t = get_TOAs(os.path.join(datadir, "B1855+09_NANOGrav_9yv1.tim"))
m.remove_component("BinaryDD")
m.remove_param("BINARY")
f = pint.fitter.GLSFitter(toas=t, model=m)


def test_correct_number_of_params_and_FD_terms_after_add_or_remove_param():
"""Checks that the number of parameters in some component after add_param or remove_param is correct. Similarly checks that len(m.get_prefix_mapping('FD')) (i.e. num_FD_terms) is correct after seeing a bug where the length didn't change after FD param removal (see #1260)."""
m = get_model(os.path.join(datadir, "B1855+09_NANOGrav_9yv1.gls.par"))
Expand Down

0 comments on commit c28fc87

Please sign in to comment.