Skip to content

Commit

Permalink
Merge pull request #4971 from nden/numpy-integer-indexing
Browse files Browse the repository at this point in the history
Numpy integer indexing
  • Loading branch information
nden committed May 26, 2016
2 parents 28bf334 + b4f7b06 commit 2bcf3c8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions astropy/modeling/core.py
Expand Up @@ -1310,7 +1310,7 @@ def _initialize_parameters(self, args, kwargs):
n_models = kwargs.pop('n_models', None)

if not (n_models is None or
(isinstance(n_models, int) and n_models >=1)):
(isinstance(n_models, (int, np.integer)) and n_models >=1)):
raise ValueError(
"n_models must be either None (in which case it is "
"determined from the model_set_axis of the parameter initial "
Expand Down Expand Up @@ -1795,7 +1795,7 @@ class _CompoundModelMeta(_ModelMeta):
def __getitem__(cls, index):
index = cls._normalize_index(index)

if isinstance(index, int):
if isinstance(index, (int, np.integer)):
return cls._get_submodels()[index]
else:
return cls._get_slice(index.start, index.stop)
Expand Down Expand Up @@ -2265,9 +2265,9 @@ def check_for_negative_index(index):
start = index.start if index.start is not None else 0
stop = (index.stop
if index.stop is not None else len(cls.submodel_names))
if isinstance(start, int):
if isinstance(start, (int, np.integer)):
start = check_for_negative_index(start)
if isinstance(stop, int):
if isinstance(stop, (int, np.integer)):
stop = check_for_negative_index(stop)
if isinstance(start, six.string_types):
start = get_index_from_name(start)
Expand All @@ -2281,7 +2281,7 @@ def check_for_negative_index(index):
raise ValueError("Empty slice of a compound model.")

return slice(start, stop)
elif isinstance(index, int):
elif isinstance(index, (int, np.integer)):
if index >= len(cls.submodel_names):
raise IndexError(
"Model index {0} out of range.".format(index))
Expand Down
2 changes: 1 addition & 1 deletion astropy/table/groups.py
Expand Up @@ -182,7 +182,7 @@ def next(self):
def __getitem__(self, item):
parent = self.parent

if isinstance(item, int):
if isinstance(item, (int, np.integer)):
i0, i1 = self.indices[item], self.indices[item + 1]
out = parent[i0:i1]
out.groups._keys = parent.groups.keys[item]
Expand Down
2 changes: 1 addition & 1 deletion astropy/table/index.py
Expand Up @@ -194,7 +194,7 @@ def get_row_specifier(self, row_specifier):
----------
row_specifier : int, list, ndarray, or slice
'''
if isinstance(row_specifier, int):
if isinstance(row_specifier, (int, np.integer)):
# single row
return (row_specifier,)
elif isinstance(row_specifier, (list, np.ndarray)):
Expand Down
2 changes: 1 addition & 1 deletion astropy/table/table.py
Expand Up @@ -96,7 +96,7 @@ def __getitem__(self, item):
"""
if isinstance(item, six.string_types):
return OrderedDict.__getitem__(self, item)
elif isinstance(item, int):
elif isinstance(item, (int, np.integer)):
return self.values()[item]
elif isinstance(item, tuple):
return self.__class__([self[x] for x in item])
Expand Down

0 comments on commit 2bcf3c8

Please sign in to comment.