Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for Issue 218: NDCube slicing with numpy.int64 #223

Merged
merged 1 commit into from
Dec 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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