Repository: wright-group/WrightTools

Issue:
chop: respect axes order in method call
The recent overhaul of chop left behind an unintended bug where the axis order in the call was not respected e.g.
```
data.chop("y", "x")[0]
print(data.axis_names)
```
This should return ("y","x"), but it might return ("x", "y"), depending on the original transform. 


Discussion:
ksunden: Well, I thought it looked good, but tests are failing...

Initially wondered if it would handle the case of being passed ints in, but we get everything as strings.
ksunden: I think you took the opposite meaning from my comment...

I meant that I thought it was wrong initially, but upon closer inspection decided that it was correct _because_ we translate the ints to strings.

I did not think that was the error causing tests to fail...

Patch:
diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py
index 7c90cc6..105a0d3 100644
--- a/WrightTools/data/_data.py
+++ b/WrightTools/data/_data.py
@@ -420,6 +420,8 @@ class Data(Group):
                 arg = arg.strip()
                 args[i] = wt_kit.string2identifier(arg, replace=operator_to_identifier)
 
+        transform_expression = [self._axes[self.axis_names.index(a)].expression for a in args]
+
         if at is None:
             at = {}
         # normalize the at keys to the natural name
@@ -457,6 +459,7 @@ class Data(Group):
             idx[np.array(removed_shape) == 1] = slice(None)
             idx[at_axes] = at_idx[at_axes]
             self._from_slice(idx, name=name, parent=out)
+            out[name].transform(*transform_expression)
         out.flush()
         # return
         if verbose:


Test patch:
diff --git a/tests/data/chop.py b/tests/data/chop.py
index ddaeb08..af3d0f6 100755
--- a/tests/data/chop.py
+++ b/tests/data/chop.py
@@ -123,6 +123,23 @@ def test_parent():
     assert chop.parent is parent
 
 
+def test_axes_order():
+    x = np.arange(6)
+    y = x[::2].copy()
+    z = x[::3].copy()
+    chan = np.arange(x.size * y.size * z.size).reshape(x.size, y.size, z.size).astype("float")
+    data = wt.data.Data(name="data")
+    data.create_channel("chan", values=chan, signed=False)
+    data.create_variable("x", values=x[:, None, None], units="wn")
+    data.create_variable("y", values=y[None, :, None], units="wn")
+    data.create_variable("z", values=z[None, None, :], units="wn")
+
+    data.transform("y", "x", "z")
+
+    d = data.chop("z", "x", at={"y": (2, "wn")})[0]
+    assert d.axis_names == ("z", "x")
+
+
 def test_transformed():
     x = np.arange(6)
     y = x[::2].copy()
@@ -174,6 +191,7 @@ def test_rmd_axis_full_shape():
 
 if __name__ == "__main__":
     test_transformed()
+    test_axes_order()
     test_2D_to_1D()
     test_3D_to_1D()
     test_3D_to_1D_at()