Skip to content

Commit 1ba10e9

Browse files
committed
Testing 1d slicing issues
1 parent f688a39 commit 1ba10e9

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

arraypartition/partition.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ def _smooth_extent(self, extent):
150150
Replace values of None within each provided slice of the extent with integer
151151
values derived from the current shape.
152152
"""
153+
if len(extent) != self.ndim:
154+
# Ignore dimensions that have already been dropped
155+
extent = [e for e in extent if isinstance(e,slice)]
156+
153157
if len(extent) != self.ndim:
154158
raise ValueError(
155159
'Direct assignment of truncated extent is not supported.'
@@ -204,6 +208,7 @@ def __init__(self,
204208
position: Union[tuple,None] = None,
205209
extent: Union[tuple,None] = None,
206210
format: Union[str,None] = None,
211+
dropped_extent: Union[tuple,None] = None,
207212
**kwargs
208213
):
209214

@@ -256,7 +261,13 @@ def __init__(self,
256261

257262
super().__init__(shape, **kwargs)
258263

264+
self._dropped_extent = dropped_extent or [None for i in shape]
265+
259266
if extent:
267+
for x, ext in enumerate(extent):
268+
if isinstance(ext, int):
269+
self._dropped_extent[x] = ext
270+
260271
# Apply a specific extent if given by the initiator
261272
self.set_extent(extent)
262273

@@ -285,13 +296,18 @@ def __array__(self, *args, **kwargs):
285296
if hasattr(array, 'units'):
286297
self.units = array.units
287298

299+
apply_ext = self._extent
288300
if len(array.shape) != len(self._extent):
289-
self._correct_slice(array.dimensions)
301+
apply_ext = self._correct_slice(array.dimensions)
302+
303+
print(f'Applying Extent {apply_ext} to {self.address}')
304+
print(array)
305+
print(self.filename)
290306

291307
try:
292308
# Still allowed to request a specific dtype
293309
# Otherwise dtype casting prevented
294-
var = np.array(array[tuple(self._extent)], dtype=dtype)
310+
var = np.array(array[tuple(apply_ext)], dtype=dtype)
295311
except IndexError:
296312
raise ValueError(
297313
f"Unable to select required 'extent' of {self.extent} "
@@ -347,24 +363,19 @@ def _correct_slice(self, array_dims: tuple):
347363
dimensions from the ``extent`` if possible.
348364
"""
349365
extent = []
350-
for dim in range(len(self.named_dims)):
366+
dimcount = 0
367+
for dim in range(len(self._dropped_extent)):
368+
369+
if self._dropped_extent[dim] is not None:
370+
extent.append(self._dropped_extent[dim])
371+
continue
372+
351373
named_dim = self.named_dims[dim]
352374
if named_dim in array_dims:
353-
extent.append(self._extent[dim])
354-
355-
# named dim not present
356-
ext = self._extent[dim]
357-
358-
start = ext.start or 0
359-
stop = ext.stop or self.shape[dim]
360-
step = ext.step or 1
375+
extent.append(self._extent[dimcount])
361376

362-
if int(stop - start)/step > 1:
363-
raise ValueError(
364-
f'Attempted to slice dimension "{named_dim}" using slice "{ext}" '
365-
'but the requested dimension is not present'
366-
)
367-
self._extent = extent
377+
dimcount += 1
378+
return extent
368379

369380
def _post_process_data(self, data: np.array):
370381
"""
@@ -415,7 +426,8 @@ def get_kwargs(self):
415426
'shape': self.shape,
416427
'position': self.position,
417428
'extent': self._extent,
418-
'format': self.format
429+
'format': self.format,
430+
'dropped_extent':self._dropped_extent
419431
} | super().get_kwargs()
420432

421433
def copy(self, extent: Union[tuple,None] = None):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "arraypartition"
3-
version = "1.2.0"
3+
version = "1.3.0a0"
44
description = "Container module for ArrayLike Partition class behaviour"
55
authors = [
66
{name = "Daniel Westwood",email = "[email protected]"}

0 commit comments

Comments
 (0)