Skip to content

Commit

Permalink
Merge pull request #686 from effigies/deprecate/numpy_asscalar
Browse files Browse the repository at this point in the history
MNT: Remove deprecated numpy.asscalar
  • Loading branch information
effigies authored Oct 23, 2018
2 parents 408627d + 93dc8cf commit d5494f3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
6 changes: 2 additions & 4 deletions nibabel/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,8 @@ def to_file_map(self, file_map=None):
# Store consumable values for later restore
offset = hdr.get_data_offset()
# Scalars of slope, offset to get immutable values
slope = (np.asscalar(hdr['scl_slope']) if hdr.has_data_slope
else np.nan)
inter = (np.asscalar(hdr['scl_inter']) if hdr.has_data_intercept
else np.nan)
slope = hdr['scl_slope'].item() if hdr.has_data_slope else np.nan
inter = hdr['scl_inter'].item() if hdr.has_data_intercept else np.nan
# Check whether to calculate slope / inter
scale_me = np.all(np.isnan((slope, inter)))
if scale_me:
Expand Down
4 changes: 2 additions & 2 deletions nibabel/ecat.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ def data_from_fileobj(self, frame=0, orientation=None):
subhdr = self.subheaders[frame]
raw_data = self.raw_data_from_fileobj(frame, orientation)
# Scale factors have to be set to scalars to force scalar upcasting
data = raw_data * np.asscalar(header['ecat_calibration_factor'])
data = data * np.asscalar(subhdr['scale_factor'])
data = raw_data * header['ecat_calibration_factor'].item()
data = data * subhdr['scale_factor'].item()
return data


Expand Down
8 changes: 4 additions & 4 deletions nibabel/nifti1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ def get_intent(self, code_repr='label'):
raise TypeError('repr can be "label" or "code"')
n_params = len(recoder.parameters[code]) if known_intent else 0
params = (float(hdr['intent_p%d' % (i + 1)]) for i in range(n_params))
name = asstr(np.asscalar(hdr['intent_name']))
name = asstr(hdr['intent_name'].item())
return label, tuple(params), name

def set_intent(self, code, params=(), name='', allow_unknown=False):
Expand Down Expand Up @@ -1679,7 +1679,7 @@ def _chk_qfac(hdr, fix=False):
@staticmethod
def _chk_magic(hdr, fix=False):
rep = Report(HeaderDataError)
magic = np.asscalar(hdr['magic'])
magic = hdr['magic'].item()
if magic in (hdr.pair_magic, hdr.single_magic):
return hdr, rep
rep.problem_msg = ('magic string "%s" is not valid' %
Expand All @@ -1693,8 +1693,8 @@ def _chk_magic(hdr, fix=False):
def _chk_offset(hdr, fix=False):
rep = Report(HeaderDataError)
# for ease of later string formatting, use scalar of byte string
magic = np.asscalar(hdr['magic'])
offset = np.asscalar(hdr['vox_offset'])
magic = hdr['magic'].item()
offset = hdr['vox_offset'].item()
if offset == 0:
return hdr, rep
if magic == hdr.single_magic and offset < hdr.single_vox_offset:
Expand Down
10 changes: 5 additions & 5 deletions nibabel/trackvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def read(fileobj, as_generator=False, points_space=None, strict=True):
hdr = np.ndarray(shape=(),
dtype=header_2_dtype,
buffer=hdr_str)
if np.asscalar(hdr['id_string'])[:5] != b'TRACK':
if hdr['id_string'].item()[:5] != b'TRACK':
raise HeaderError('Expecting TRACK as first '
'5 characters of id_string')
if hdr['hdr_size'] == 1000:
Expand Down Expand Up @@ -492,7 +492,7 @@ def _check_hdr_points_space(hdr, points_space):
raise HeaderError('Affine zooms %s differ from voxel_size '
'field value %s' % (aff_zooms, zooms))
aff_order = ''.join(aff2axcodes(affine))
voxel_order = asstr(np.asscalar(hdr['voxel_order']))
voxel_order = asstr(hdr['voxel_order'].item())
if voxel_order == '':
voxel_order = 'LPS' # trackvis default
if not voxel_order == aff_order:
Expand Down Expand Up @@ -526,7 +526,7 @@ def _hdr_from_mapping(hdr=None, mapping=None, endianness=native_code):
for key, value in mapping.items():
hdr[key] = value
# check header values
if np.asscalar(hdr['id_string'])[:5] != b'TRACK':
if hdr['id_string'].item()[:5] != b'TRACK':
raise HeaderError('Expecting TRACK as first '
'5 characaters of id_string')
if hdr['version'] not in (1, 2):
Expand Down Expand Up @@ -556,7 +556,7 @@ def empty_header(endianness=None, version=2):
>>> hdr = empty_header()
>>> print(hdr['version'])
2
>>> np.asscalar(hdr['id_string']) == b'TRACK'
>>> hdr['id_string'].item() == b'TRACK'
True
>>> endian_codes[hdr['version'].dtype.byteorder] == native_code
True
Expand Down Expand Up @@ -654,7 +654,7 @@ def aff_from_hdr(trk_hdr, atleast_v2=None):
aff = np.dot(DPCS_TO_TAL, aff)
# Next we check against the 'voxel_order' field if present and not empty.
try:
voxel_order = asstr(np.asscalar(trk_hdr['voxel_order']))
voxel_order = asstr(trk_hdr['voxel_order'].item())
except (KeyError, ValueError):
voxel_order = ''
if voxel_order == '':
Expand Down
2 changes: 1 addition & 1 deletion nibabel/volumeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ def rec2dict(rec):
for key in rec.dtype.fields:
val = rec[key]
try:
val = np.asscalar(val)
val = val.item()
except ValueError:
pass
dct[key] = val
Expand Down

0 comments on commit d5494f3

Please sign in to comment.