Skip to content

Commit 34a7caf

Browse files
committed
RF: Remove Python < 3.5 hacks
1 parent 013741f commit 34a7caf

File tree

6 files changed

+13
-62
lines changed

6 files changed

+13
-62
lines changed

nibabel/dft.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,7 @@ def __exit__(self, type, value, traceback):
277277

278278
def _get_subdirs(base_dir, files_dict=None, followlinks=False):
279279
dirs = []
280-
# followlinks keyword not available for python 2.5.
281-
kwargs = {} if not followlinks else {'followlinks': True}
282-
for (dirpath, dirnames, filenames) in os.walk(base_dir, **kwargs):
280+
for (dirpath, dirnames, filenames) in os.walk(base_dir, followlinks=followlinks):
283281
abs_dir = os.path.realpath(dirpath)
284282
if abs_dir in dirs:
285283
raise CachingError('link cycle detected under %s' % base_dir)

nibabel/nicom/tests/test_csareader.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ def test_ice_dims():
130130

131131

132132
@dicom_test
133-
@skipif(sys.version_info < (2,7) and pydicom.__version__ < '1.0',
134-
'Known issue for python 2.6 and pydicom < 1.0')
135133
def test_missing_csa_elem():
136134
# Test that we get None instead of raising an Exception when the file has
137135
# the PrivateCreator element for the CSA dict but not the element with the

nibabel/tests/scriptrunner.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,8 @@
1818

1919
from subprocess import Popen, PIPE
2020

21-
try: # Python 2
22-
string_types = basestring,
23-
except NameError: # Python 3
24-
string_types = str,
2521

26-
27-
def _get_package():
28-
""" Workaround for missing ``__package__`` in Python 3.2
29-
"""
30-
if '__package__' in globals() and not __package__ is None:
31-
return __package__
32-
return __name__.split('.', 1)[0]
33-
34-
35-
# Same as __package__ for Python 2.6, 2.7 and >= 3.3
36-
MY_PACKAGE = _get_package()
22+
MY_PACKAGE = __package__
3723

3824

3925
def local_script_dir(script_sdir):
@@ -117,7 +103,7 @@ def run_command(self, cmd, check_code=True):
117103
stderr : bytes
118104
stderr from `cmd`
119105
"""
120-
if isinstance(cmd, string_types):
106+
if isinstance(cmd, str):
121107
cmd = [cmd]
122108
else:
123109
cmd = list(cmd)

nibabel/tests/test_arraywriters.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
See docstring of :mod:`nibabel.arraywriters` for API.
44
"""
55

6-
import sys
76
from platform import python_compiler, machine
8-
from distutils.version import LooseVersion
97
import itertools
108
import numpy as np
119

@@ -33,8 +31,6 @@
3331
IUINT_TYPES = INT_TYPES + UINT_TYPES
3432
NUMERIC_TYPES = CFLOAT_TYPES + IUINT_TYPES
3533

36-
NP_VERSION = LooseVersion(np.__version__)
37-
3834

3935
def round_trip(writer, order='F', apply_scale=True):
4036
sio = BytesIO()
@@ -65,29 +61,14 @@ def test_arraywriters():
6561
assert_array_equal(arr, round_trip(aw))
6662
# Byteswapped should be OK
6763
bs_arr = arr.byteswap().newbyteorder('S')
68-
# Except on some numpies for complex256, where the array does not
69-
# equal itself
70-
if not np.all(bs_arr == arr):
71-
assert_true(NP_VERSION <= LooseVersion('1.7.0'))
72-
assert_true(on_powerpc())
73-
assert_true(type == np.complex256)
74-
else:
75-
bs_aw = klass(bs_arr)
76-
bs_aw_rt = round_trip(bs_aw)
77-
# On Ubuntu 13.04 with python 3.3 __eq__ comparison on
78-
# arrays with complex numbers fails here for some
79-
# reason -- not our fault, and to test correct operation we
80-
# will just compare element by element
81-
if NP_VERSION == '1.7.1' and sys.version_info[:2] == (3, 3):
82-
assert_array_equal_ = lambda x, y: np.all([x_ == y_ for x_, y_ in zip(x, y)])
83-
else:
84-
assert_array_equal_ = assert_array_equal
85-
# assert against original array because POWER7 was running into
86-
# trouble using the byteswapped array (bs_arr)
87-
assert_array_equal_(arr, bs_aw_rt)
88-
bs_aw2 = klass(bs_arr, arr.dtype)
89-
bs_aw2_rt = round_trip(bs_aw2)
90-
assert_array_equal(arr, bs_aw2_rt)
64+
bs_aw = klass(bs_arr)
65+
bs_aw_rt = round_trip(bs_aw)
66+
# assert against original array because POWER7 was running into
67+
# trouble using the byteswapped array (bs_arr)
68+
assert_array_equal(arr, bs_aw_rt)
69+
bs_aw2 = klass(bs_arr, arr.dtype)
70+
bs_aw2_rt = round_trip(bs_aw2)
71+
assert_array_equal(arr, bs_aw2_rt)
9172
# 2D array
9273
arr2 = np.reshape(arr, (2, 5))
9374
a2w = klass(arr2)

nibabel/tests/test_rstutils.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
""" Test printable table
22
"""
33

4-
import sys
54
import numpy as np
65

76
from ..rstutils import rst_table
87

9-
from nose import SkipTest
108
from nose.tools import assert_equal, assert_raises
119

1210

1311
def test_rst_table():
1412
# Tests for printable table function
1513
R, C = 3, 4
1614
cell_values = np.arange(R * C).reshape((R, C))
17-
if (sys.version_info[:3] == (3, 2, 3) and np.__version__ == '1.6.1'):
18-
raise SkipTest("Known (later fixed) bug in python3.2/numpy "
19-
"treating np.int64 as str")
2015
assert_equal(rst_table(cell_values),
2116
"""+--------+--------+--------+--------+--------+
2217
| | col[0] | col[1] | col[2] | col[3] |

nibabel/trackvis.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@
1818
from .affines import apply_affine
1919
from .deprecated import deprecate_with_version
2020

21-
try:
22-
basestring
23-
except NameError: # python 3
24-
basestring = str
25-
2621
warnings.warn("The trackvis interface has been deprecated and will be removed "
2722
"in v4.0; please use the 'nibabel.streamlines' interface.",
2823
DeprecationWarning,
@@ -831,15 +826,13 @@ def __init__(self,
831826
@classmethod
832827
def from_file(klass, file_like, points_space=None):
833828
streamlines, header = read(file_like, points_space=points_space)
834-
filename = (file_like if isinstance(file_like, basestring)
835-
else None)
829+
filename = file_like if isinstance(file_like, str) else None
836830
return klass(streamlines, header, None, filename, points_space)
837831

838832
def to_file(self, file_like):
839833
write(file_like, self.streamlines, self.header, self.endianness,
840834
points_space=self.points_space)
841-
self.filename = (file_like if isinstance(file_like, basestring)
842-
else None)
835+
self.filename = file_like if isinstance(file_like, str) else None
843836

844837
def get_affine(self, atleast_v2=True):
845838
""" Get affine from header in object

0 commit comments

Comments
 (0)