Skip to content

Commit

Permalink
Fix crashing bug when slicing NDCube.
Browse files Browse the repository at this point in the history
If an axis after the first axis was sliced with a non-native int type,
e.g. numpy.int64, the slixing would crash due to missing_axes not being
altered.  This commit adds support for nupy.int64 and numpy.int32 types.
  • Loading branch information
DanRyanIrish committed Dec 16, 2019
1 parent 37d2db2 commit 3e05ca4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/223.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crashing bug when an NDCube axis after the first is sliced with a numpy.int64.
8 changes: 6 additions & 2 deletions ndcube/utils/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
from copy import deepcopy
from collections import UserDict
import numbers

import numpy as np
from astropy import wcs
Expand Down Expand Up @@ -163,7 +164,7 @@ def _wcs_slicer(wcs, missing_axes, item):
item_checked.append(slice(0, 1))
new_wcs = wcs.slice(item_checked)
# item is int then slicing axis.
elif isinstance(item, int) or isinstance(item, np.int64):
elif isinstance(item, numbers.Integral):
# using index to keep track of whether the int(which is converted to
# slice(int_value, int_value+1)) is already added or not. It checks
# the dead axis i.e missing_axes to check if it is dead than slice(0,1)
Expand Down Expand Up @@ -207,7 +208,10 @@ def _wcs_slicer(wcs, missing_axes, item):
item_ = _slice_list(item_checked)
new_wcs = wcs.slice(item_)
for i, it in enumerate(item_checked):
if isinstance(it, int):
# If an axis is sliced out, i.e. it's item is an int,
# set missing axis to True.
# numbers.Integral captures all int types, int, np.int64, etc.
if isinstance(it, numbers.Integral):
missing_axes[i] = True
else:
raise NotImplementedError("Slicing FITS-WCS by {} not supported.".format(type(item)))
Expand Down

0 comments on commit 3e05ca4

Please sign in to comment.