Skip to content

Commit

Permalink
Merge pull request #1163 from wright-group/issue-1105
Browse files Browse the repository at this point in the history
constants propagate units
  • Loading branch information
kameyer226 authored Mar 20, 2024
2 parents 98f2283 + 50b7e96 commit 4147cc6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

## [Unreleased]

### Fixed
- constants in chopped data will inherit the units of the original data

## [3.5.2]

### Added
Expand Down
5 changes: 5 additions & 0 deletions WrightTools/data/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ def _from_slice(self, idx, name=None, parent=None) -> Data:

for const in list(self.constant_expressions) + constants:
out.create_constant(const, verbose=False)
if const in self.constant_expressions:
dest_units = self.constants[self.constant_expressions.index(const)].units
else:
dest_units = self.axes[self.axis_expressions.index(const)].units
out.constants[out.constant_expressions.index(const)].convert(dest_units)
for j, units in enumerate(new_axis_units):
out.axes[j].convert(units)

Expand Down
4 changes: 3 additions & 1 deletion tests/data/chop.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ def test_3D_to_2D_units():
assert d.w2.size == 11
assert d.axis_expressions == ("wm", "w2")
assert d.units == ("eV", "eV")
data.close()
w1 = d.constants[d.constant_names.index("w1")]
assert w1.units == "eV"
chop.close()
data.close()


def test_parent():
Expand Down

0 comments on commit 4147cc6

Please sign in to comment.