Skip to content

Commit 2a0b761

Browse files
authored
Merge pull request #90 from osyris-project/revert_vector_slicing
2 parents 9c22f90 + 0640fae commit 2a0b761

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

docs/loading_data.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
"metadata": {},
308308
"outputs": [],
309309
"source": [
310-
"center = data['sink']['position'][0]\n",
310+
"center = data['sink']['position'][0:1]\n",
311311
"dx = 200 * osyris.units('au')"
312312
]
313313
},
@@ -353,7 +353,7 @@
353353
"osyris.map(data[\"hydro\"][\"density\"],\n",
354354
" {\"data\": data[\"sink\"][\"position\"], \"mode\": \"scatter\", \"c\": \"white\",\n",
355355
" \"s\": 20. * osyris.units(\"au\"), \"alpha\": 0.7},\n",
356-
" norm='log', direction=\"z\", origin=center)"
356+
" norm='log', direction=\"z\", origin=center[0])"
357357
]
358358
}
359359
],

src/osyris/core/array.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,10 @@ def __init__(self, values=0, unit=None, parent=None, name=""):
4343
# return self._array
4444

4545
def __getitem__(self, slice_):
46-
out = self.__class__(values=self._array[slice_],
47-
unit=self._unit,
48-
parent=self._parent,
49-
name=self._name)
50-
if isinstance(slice_, int) and self.ndim > 1:
51-
return out.reshape(1, len(out))
52-
return out
46+
return self.__class__(values=self._array[slice_],
47+
unit=self._unit,
48+
parent=self._parent,
49+
name=self._name)
5350

5451
def __len__(self):
5552
if self._array.shape:

test/test_array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def test_slicing():
339339

340340
def test_slicing_vector():
341341
a = osyris.Array(values=np.arange(12.).reshape(4, 3), unit='m')
342-
assert all(np.ravel(a[2] == osyris.Array(values=[[6., 7., 8.]], unit='m')))
343-
assert a[2].shape == (1, 3)
342+
assert all(np.ravel(a[2:3] == osyris.Array(values=[[6., 7., 8.]], unit='m')))
343+
assert a[2:3].shape == (1, 3)
344344
assert all(
345345
np.ravel(a[:2] == osyris.Array(values=[[0., 1., 2.], [3., 4., 5.]], unit='m')))

0 commit comments

Comments
 (0)