Skip to content

Commit 7553098

Browse files
authored
Merge pull request #1226 from wright-group/issue-1225
Channels have units
2 parents 45575f9 + a4b4195 commit 7553098

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
77

88
### Fixed
99
- fixed bug where numpy>2.4 broke `data.join`
10+
- fixed bug which prevented channels from having units
1011

1112
### Changed
1213
- per [PEP 765](https://peps.python.org/pep-0765/), `return` is removed from `finally` blocks

WrightTools/data/_channel.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def __init__(
6161
super().__init__(id)
6262
self.label = label
6363
self.label_seed = label_seed
64-
self.units = units
64+
if units is not None:
65+
self.units = units
6566
self.dimensionality = len(self.shape)
6667
# attrs
6768
if self._parent.file.mode is not None and self._parent.file.mode != "r":

tests/data/channel/units.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Tests to do with null."""
2+
3+
# --- import --------------------------------------------------------------------------------------
4+
5+
6+
import WrightTools as wt
7+
import numpy as np
8+
9+
10+
def test_assignment():
11+
d = wt.Data()
12+
d.create_channel("x", values=np.arange(5), units="Hz")
13+
assert d["x"].units == "Hz"
14+
15+
16+
if __name__ == "__main__":
17+
test_assignment()

0 commit comments

Comments
 (0)