Repository: wright-group/WrightTools

Issue:
chop fails when axes do not span data shape
```
import WrightTools as wt
import numpy as np

x = np.arange(6)

d = wt.Data(name="test")
d.create_variable("x", values=x[:, None, None])
d.create_variable("y", values=x[None, :, None])
d.create_variable("z", values=x[None, None, :])
d.transform("x", "y")  # note no z

d.chop(0)
```

raises IndexError in chop:
```
~\wrighttools\WrightTools\data\_data.py in chop(self, at, parent, verbose, *args)
    458             idx = np.array(idx, dtype=object)
    459             idx[np.array(removed_shape) == 1] = slice(None)
--> 460             idx[at_axes] = at_idx[at_axes]
    461             self._from_slice(idx, name=name, parent=out)
    462             out[name].transform(*transform_expression)

IndexError: boolean index did not match indexed array along dimension 0; dimension is 3 but corresponding boolean dimension is 2
```

Looking into fix...


Discussion:
ksunden: LGTM, I would run the attune tests off of this branch and honestly just do another release (can even be in this same PR) because its a bug that affects our current usage.
ddkohler: attune tests pass; good to go

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc750e8..011bf2f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
 
 ## [Unreleased]
 
+## [3.4.6]
+
+### Fixed
+
+- `Data.chop` : fixed bug where chop did not succeed if axes did not span data ndim
+
 ## [3.4.5]
 
 ### Added
@@ -329,7 +335,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
 ### Added
 - initial release
 
-[Unreleased]: https://github.com/wright-group/WrightTools/-/compare/3.4.4...master
+[Unreleased]: https://github.com/wright-group/WrightTools/-/compare/3.4.6...master
+[3.4.6]: https://github.com/wright-group/WrightTools/compare/3.4.5...3.4.6
 [3.4.5]: https://github.com/wright-group/WrightTools/compare/3.4.4...3.4.5
 [3.4.4]: https://github.com/wright-group/WrightTools/compare/3.4.3...3.4.4
 [3.4.3]: https://github.com/wright-group/WrightTools/compare/3.4.2...3.4.3
diff --git a/WrightTools/VERSION b/WrightTools/VERSION
index 4f5e697..1cf8253 100644
--- a/WrightTools/VERSION
+++ b/WrightTools/VERSION
@@ -1,1 +1,1 @@
-3.4.5
+3.4.6
diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py
index 105a0d3..662c68a 100644
--- a/WrightTools/data/_data.py
+++ b/WrightTools/data/_data.py
@@ -482,7 +482,7 @@ class Data(Group):
         for k in at.keys():
             if k not in self.axis_names:
                 raise ValueError(f"Axis identifier {k} not in Axes: {self.axis_names}")
-        idx = np.array([slice(None)] * len(self._axes))
+        idx = np.array([slice(None)] * len(self.shape))
         for axis, point in at.items():
             point, units = point
             destination_units = self._axes[self.axis_names.index(axis)].units


Test patch:
diff --git a/tests/data/chop.py b/tests/data/chop.py
index af3d0f6..e01c023 100755
--- a/tests/data/chop.py
+++ b/tests/data/chop.py
@@ -186,12 +186,32 @@ def test_rmd_axis_full_shape():
     assert c[0].shape == (6, 3)
 
 
+def test_non_spanning_axes():
+    """axes do not span shape of data"""
+
+    x = np.arange(6)
+
+    d = wt.Data(name="test")
+    d.create_variable("x", values=x[:, None, None])
+    d.create_variable("y", values=x[None, ::2, None])
+    d.create_variable("z", values=x[None, None, ::3])
+    d.transform("x", "y")
+
+    c = d.chop(1)
+    assert c[0].axis_names == ("y",)
+    assert c[0].shape == d.shape[1:]
+
+    d.close()
+    c.close()
+
+
 # --- run -----------------------------------------------------------------------------------------
 
 
 if __name__ == "__main__":
     test_transformed()
     test_axes_order()
+    test_non_spanning_axes()
     test_2D_to_1D()
     test_3D_to_1D()
     test_3D_to_1D_at()