Skip to content

Commit

Permalink
Merge pull request #1097 from wright-group/expression-spaces
Browse files Browse the repository at this point in the history
Update _axis.py
  • Loading branch information
kameyer226 committed Aug 29, 2022
2 parents 49501c4 + c359934 commit 3c6c8ca
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
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]

## Changed
- `Axis`: space character ("\s") in expressions are culled.

## [3.4.6]

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions WrightTools/data/_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def __init__(self, parent, expression, units=None):
parent : WrightTools.Data
Parent data object.
expression : string
Axis expression.
Axis expression. Space characters are ignored.
units : string (optional)
Axis units. Default is None.
"""
self.parent = parent
self.expression = expression
self.expression = expression.replace(" ", "") # ignore spaces
if units is None:
self.units = self.variables[0].units
else:
Expand Down
1 change: 1 addition & 0 deletions docs/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Axis
The :class:`WrightTools.data.Axis` class defines the coordinates of a data object.
Each ``Axis`` contains an ``expression``, which dictates its relationship with one or more variables.
Given 5 variables with names [``'w1'``, ``'w2'``, ``'wm'``, ``'d1'``, ``'d2'``] , example valid expressions include ``'w1'``, ``'w1=wm'``, ``'w1+w2'``, ``'2*w1'``, ``'d1-d2'``, and ``'wm-w1+w2'``.
WrightTools ignores the space character in expressions, so ``'w1 = w2'`` will be interpreted as ``'w1=w2'``.
Axes behave like arrays: you can slice into them, view their shape, get a min and max etc.
But actually axes do not contain any new array information: they simply refer to the Variable arrays.
Axes have the following key attributes:
Expand Down
14 changes: 14 additions & 0 deletions tests/data/axis/expressions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import WrightTools as wt


def test_space_character():
d = wt.Data()
d.create_variable("w1")
d.create_variable("w2")
d.transform("w1 + w2")
assert d.axis_names == ("w1__p__w2",)
assert d.axis_expressions == ("w1+w2",)


if __name__ == "__main__":
test_space_character()

0 comments on commit 3c6c8ca

Please sign in to comment.