Repository: pyfar/pyfar (python)

Issue:
Coordinates __getitem__, slicing bug
## Description

Slicing of coordinates changes the original object instead of returning a new object.

## What I Did

```
import pyfar
coords = pyfar.Coordinates([0,1], [0,1], [0,1])
coords_sliced = coords[0]
coords.cshape == (2,)
```

Pull request:
Coordinates __getitem__ bugfix
### Which issue(s) are closed by this pull request?

Closes #122 

### Changes proposed in this pull request:

- New Coordinates object is returned by calling self.copy()
- Added test

Patch:
diff --git a/pyfar/coordinates.py b/pyfar/coordinates.py
index acf494a0..38f3848e 100644
--- a/pyfar/coordinates.py
+++ b/pyfar/coordinates.py
@@ -1632,9 +1632,9 @@ class Coordinates(object):
         return kdtree
 
     def __getitem__(self, index):
-        """Return mutable slice of Coordinates object at index."""
+        """Return copied slice of Coordinates object at index."""
 
-        new = self
+        new = self.copy()
         # slice points
         new._points = new._points[index]
         # slice weights


Test patch:
diff --git a/tests/test_coordinates.py b/tests/test_coordinates.py
index 5e863d88..13df4bc3 100644
--- a/tests/test_coordinates.py
+++ b/tests/test_coordinates.py
@@ -413,6 +413,13 @@ def test_getitem():
     assert isinstance(new, Coordinates)
     assert new.cshape == (1, 5)
 
+    # test if sliced object stays untouched
+    coords = Coordinates([0, 1], [0, 1], [0, 1])
+    new = coords[0]
+    new.set_cart(2, 2, 2)
+    assert coords.cshape == (2,)
+    npt.assert_allclose(coords.get_cart()[0], np.array([0, 0, 0]))
+
 
 def test_get_nearest_k():
     # 1D cartesian, nearest point