Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dlakaplan committed Aug 28, 2023
2 parents dbe69cc + 7943e1a commit 304ac52
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ the released changes.
### Fixed
- Fixed RTD by specifying theme explicitly.
- `.value()` now works for pairParameters
- Setting `model.PARAM1 = model.PARAM2` no longer overrides the name of `PARAM1`
### Removed
10 changes: 10 additions & 0 deletions src/pint/models/timing_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,16 @@ def __getattr__(self, name):
f"Attribute {name} not found in TimingModel or any Component"
)

def __setattr__(self, name, value):
"""Mostly this just sets ``self.name = value``. But in the case where they are both :class:`Parameter` instances
with different names, this copies the ``quantity``, ``uncertainty``, ``frozen`` attributes only.
"""
if isinstance(value, (Parameter, prefixParameter)) and name != value.name:
for p in ["quantity", "uncertainty", "frozen"]:
setattr(getattr(self, name), p, getattr(value, p))
else:
super().__setattr__(name, value)

@property_exists
def params_ordered(self):
"""List of all parameter names in this model and all its components.
Expand Down
42 changes: 42 additions & 0 deletions tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,3 +605,45 @@ def test_correct_number_of_params_and_FD_terms_after_add_or_remove_param():
m.remove_param("FD4")
assert len(m.components["FD"].params) == 3
assert len(m.get_prefix_mapping("FD")) == 3


def test_parameter_retains_name_on_set():
basic_par_str = """
PSR B1937+21
LAMBDA 301.9732445337270
BETA 42.2967523367957
PMLAMBDA -0.0175
PMBETA -0.3971
PX 0.1515
POSEPOCH 55321.0000
F0 641.9282333345536244 1 0.0000000000000132
F1 -4.330899370129D-14 1 2.149749089617D-22
PEPOCH 55321.000000
DM 71.016633
UNITS TDB
"""

m = get_model(io.StringIO(basic_par_str))
m.POSEPOCH = m.PEPOCH
assert m.POSEPOCH.name == "POSEPOCH"


def test_parameter_set_incompatible_fails():
basic_par_str = """
PSR B1937+21
LAMBDA 301.9732445337270
BETA 42.2967523367957
PMLAMBDA -0.0175
PMBETA -0.3971
PX 0.1515
POSEPOCH 55321.0000
F0 641.9282333345536244 1 0.0000000000000132
F1 -4.330899370129D-14 1 2.149749089617D-22
PEPOCH 55321.000000
DM 71.016633
UNITS TDB
"""

m = get_model(io.StringIO(basic_par_str))
with pytest.raises(u.core.UnitConversionError):
m.F0 = m.F1

0 comments on commit 304ac52

Please sign in to comment.