Skip to content

Commit 8fea2a8

Browse files
authored
Merge pull request #1243 from larsoner/deps
MAINT: Deprecations
2 parents 835b2fe + 5bb4d4c commit 8fea2a8

File tree

7 files changed

+23
-19
lines changed

7 files changed

+23
-19
lines changed

nibabel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
# module imports
4141
from . import analyze as ana
42-
from . import ecat, imagestats, mriutils
42+
from . import ecat, imagestats, mriutils, orientations
4343
from . import nifti1 as ni1
4444
from . import spm2analyze as spm2
4545
from . import spm99analyze as spm99

nibabel/nicom/utils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""Utilities for working with DICOM datasets
22
"""
33

4-
from numpy.compat.py3k import asstr
5-
64

75
def find_private_section(dcm_data, group_no, creator):
86
"""Return start element in group `group_no` given creator name `creator`
@@ -31,15 +29,20 @@ def find_private_section(dcm_data, group_no, creator):
3129
"""
3230
if hasattr(creator, 'search'):
3331
match_func = creator.search
34-
else: # assume string / bytes
35-
match_func = asstr(creator).__eq__
32+
else:
33+
if isinstance(creator, bytes):
34+
creator = creator.decode('latin-1')
35+
match_func = creator.__eq__
3636
# Group elements assumed ordered by tag (groupno, elno)
3737
for element in dcm_data.group_dataset(group_no):
3838
elno = element.tag.elem
3939
if elno > 0xFF:
4040
break
4141
if element.VR not in ('LO', 'OB'):
4242
continue
43-
if match_func(asstr(element.value)):
43+
val = element.value
44+
if isinstance(val, bytes):
45+
val = val.decode('latin-1')
46+
if match_func(val):
4447
return elno * 0x100
4548
return None

nibabel/nifti1.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import numpy as np
1919
import numpy.linalg as npl
20-
from numpy.compat.py3k import asstr
2120

2221
from . import analyze # module import
2322
from .arrayproxy import get_obj_dtype
@@ -1405,7 +1404,7 @@ def get_intent(self, code_repr='label'):
14051404
raise TypeError('repr can be "label" or "code"')
14061405
n_params = len(recoder.parameters[code]) if known_intent else 0
14071406
params = (float(hdr['intent_p%d' % (i + 1)]) for i in range(n_params))
1408-
name = asstr(hdr['intent_name'].item())
1407+
name = hdr['intent_name'].item().decode('latin-1')
14091408
return label, tuple(params), name
14101409

14111410
def set_intent(self, code, params=(), name='', allow_unknown=False):
@@ -1741,7 +1740,7 @@ def _chk_magic(hdr, fix=False):
17411740
magic = hdr['magic'].item()
17421741
if magic in (hdr.pair_magic, hdr.single_magic):
17431742
return hdr, rep
1744-
rep.problem_msg = f'magic string "{asstr(magic)}" is not valid'
1743+
rep.problem_msg = f'magic string {magic.decode("latin1")!r} is not valid'
17451744
rep.problem_level = 45
17461745
if fix:
17471746
rep.fix_msg = 'leaving as is, but future errors are likely'

nibabel/streamlines/trk.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import warnings
88

99
import numpy as np
10-
from numpy.compat.py3k import asstr
1110

1211
import nibabel as nib
1312
from nibabel.openers import Opener
@@ -180,7 +179,7 @@ def decode_value_from_name(encoded_name):
180179
value : int
181180
Value decoded from the name.
182181
"""
183-
encoded_name = asstr(encoded_name)
182+
encoded_name = encoded_name.decode('latin1')
184183
if len(encoded_name) == 0:
185184
return encoded_name, 0
186185

@@ -740,14 +739,18 @@ def __str__(self):
740739
vars[attr] = vars[hdr_field]
741740

742741
nb_scalars = self.header[Field.NB_SCALARS_PER_POINT]
743-
scalar_names = [asstr(s) for s in vars['scalar_name'][:nb_scalars] if len(s) > 0]
742+
scalar_names = [
743+
s.decode('latin-1') for s in vars['scalar_name'][:nb_scalars] if len(s) > 0
744+
]
744745
vars['scalar_names'] = '\n '.join(scalar_names)
745746
nb_properties = self.header[Field.NB_PROPERTIES_PER_STREAMLINE]
746-
property_names = [asstr(s) for s in vars['property_name'][:nb_properties] if len(s) > 0]
747+
property_names = [
748+
s.decode('latin-1') for s in vars['property_name'][:nb_properties] if len(s) > 0
749+
]
747750
vars['property_names'] = '\n '.join(property_names)
748751
# Make all byte strings into strings
749752
# Fixes recursion error on Python 3.3
750-
vars = {k: asstr(v) if hasattr(v, 'decode') else v for k, v in vars.items()}
753+
vars = {k: v.decode('latin-1') if hasattr(v, 'decode') else v for k, v in vars.items()}
751754
return """\
752755
MAGIC NUMBER: {MAGIC_NUMBER}
753756
v.{version}

nibabel/tests/test_nifti1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def test_magic_offset_checks(self):
251251
fhdr, message, raiser = self.log_chk(hdr, 45)
252252
assert fhdr['magic'] == b'ooh'
253253
assert (
254-
message == 'magic string "ooh" is not valid; '
254+
message == "magic string 'ooh' is not valid; "
255255
'leaving as is, but future errors are likely'
256256
)
257257
# For pairs, any offset is OK, but should be divisible by 16

nibabel/tests/test_openers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from unittest import mock
1818

1919
import pytest
20-
from numpy.compat.py3k import asbytes, asstr
2120
from packaging.version import Version
2221

2322
from ..deprecator import ExpiredDeprecationError
@@ -342,10 +341,10 @@ def test_iter():
342341
for input, does_t in files_to_test:
343342
with Opener(input, 'wb') as fobj:
344343
for line in lines:
345-
fobj.write(asbytes(line + os.linesep))
344+
fobj.write(str.encode(line + os.linesep))
346345
with Opener(input, 'rb') as fobj:
347346
for back_line, line in zip(fobj, lines):
348-
assert asstr(back_line).rstrip() == line
347+
assert back_line.decode().rstrip() == line
349348
if not does_t:
350349
continue
351350
with Opener(input, 'rt') as fobj:

nibabel/tests/test_scripts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def test_nib_nifti_dx():
228228
expected = f"""Picky header check output for "{dirty_hdr}"
229229
230230
pixdim[0] (qfac) should be 1 (default) or -1
231-
magic string "" is not valid
231+
magic string '' is not valid
232232
sform_code 11776 not valid"""
233233
# Split strings to remove line endings
234234
assert stdout == expected

0 commit comments

Comments
 (0)