Skip to content

Commit

Permalink
Update ndcube/meta.py
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRyanIrish authored Dec 13, 2024
1 parent db18ebb commit 59e2b75
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions ndcube/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,25 +387,8 @@ def __getitem__(self, item):

# Edit data shape and calculate which axis will be dropped.
dropped_axes = np.zeros(naxes, dtype=bool)
new_shape = new_meta.data_shape
for i, axis_item in enumerate(item):
if isinstance(axis_item, numbers.Integral):
dropped_axes[i] = True
elif isinstance(axis_item, slice):
start = axis_item.start
if start is None:
start = 0
if start < 0:
start = data_shape[i] - start
stop = axis_item.stop
if stop is None:
stop = data_shape[i]
if stop < 0:
stop = data_shape[i] - stop
new_shape[i] = stop - start
else:
raise TypeError("Unrecognized slice type. "
"Must be an int, slice and tuple of the same.")
new_shape = np.broadcast_to(1, new_meta.data_shape)[item].shape
dropped_axes = np.array([True if isinstance(axis_item, numbers.Integral) else False for axis_item in item], dtype=bool)
kept_axes = np.invert(dropped_axes)
new_meta._data_shape = new_shape[kept_axes]

Expand Down

0 comments on commit 59e2b75

Please sign in to comment.