Skip to content

Commit d5048d9

Browse files
Fixing ptype for ParticleSetView
And also updating one repr test
1 parent f9cb72a commit d5048d9

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

src/parcels/_core/particlesetview.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __getitem__(self, index):
5656
raise ValueError(
5757
f"Boolean index has incompatible length {arr.size} for selection of size {int(np.sum(base))}"
5858
)
59-
return ParticleSetView(self._data, new_index)
59+
return ParticleSetView(self._data, new_index, self._ptype)
6060

6161
# Integer array/list, slice or single integer relative to the local view
6262
# (boolean masks were handled above). Normalize and map to global
@@ -71,12 +71,12 @@ def __getitem__(self, index):
7171
base_arr = np.asarray(base)
7272
sel = base_arr[idx]
7373
new_index[sel] = True
74-
return ParticleSetView(self._data, new_index)
74+
return ParticleSetView(self._data, new_index, self._ptype)
7575

7676
# Fallback: try to assign directly (preserves previous behaviour for other index types)
7777
try:
7878
new_index[base] = index
79-
return ParticleSetView(self._data, new_index)
79+
return ParticleSetView(self._data, new_index, self._ptype)
8080
except Exception as e:
8181
raise TypeError(f"Unsupported index type for ParticleSetView.__getitem__: {type(index)!r}") from e
8282

tests/test_particle.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ def test_particleclass_invalid_vars():
8080
Variable("varc", dtype=np.float32, to_write=True),
8181
]
8282
),
83-
"""ParticleClass(variables=[
84-
Variable(name='vara', dtype=dtype('float32'), initial=0, to_write=True, attrs={}),
85-
Variable(name='varb', dtype=dtype('float32'), initial=0, to_write=False, attrs={}),
86-
Variable(name='varc', dtype=dtype('float32'), initial=0, to_write=True, attrs={})
87-
])""",
83+
"""Variable(name='vara', dtype=dtype('float32'), initial=0, to_write=True, attrs={})
84+
Variable(name='varb', dtype=dtype('float32'), initial=0, to_write=False, attrs={})
85+
Variable(name='varc', dtype=dtype('float32'), initial=0, to_write=True, attrs={})""",
8886
),
8987
],
9088
)

0 commit comments

Comments
 (0)