Skip to content

Commit

Permalink
Merge pull request #223 from DanRyanIrish/issue218
Browse files Browse the repository at this point in the history
Bugfix for Issue 218: NDCube slicing with numpy.int64
  • Loading branch information
Cadair authored Dec 28, 2019
2 parents 37d2db2 + 3e05ca4 commit d16eab8
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 d16eab8

Please sign in to comment.