Skip to content

Commit f3ff932

Browse files
committed
RF: Drop six.*_types
1 parent e4b8cfd commit f3ff932

File tree

11 files changed

+28
-41
lines changed

11 files changed

+28
-41
lines changed

nibabel/brikhead.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import re
3434

3535
import numpy as np
36-
from six import string_types
3736

3837
from .arrayproxy import ArrayProxy
3938
from .fileslice import strided_scalar
@@ -203,7 +202,7 @@ def parse_AFNI_header(fobj):
203202
[1, 1, 1]
204203
"""
205204
# edge case for being fed a filename instead of a file object
206-
if isinstance(fobj, string_types):
205+
if isinstance(fobj, str):
207206
with open(fobj, 'rt') as src:
208207
return parse_AFNI_header(src)
209208
# unpack variables in HEAD file

nibabel/cifti2/cifti2_axes.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"""
121121
import numpy as np
122122
from . import cifti2
123-
from six import string_types, integer_types
124123
from operator import xor
125124
import abc
126125

@@ -288,7 +287,7 @@ def __init__(self, name, voxel=None, vertex=None, affine=None,
288287
else:
289288
self.vertex = np.asanyarray(vertex, dtype=int)
290289

291-
if isinstance(name, string_types):
290+
if isinstance(name, str):
292291
name = [self.to_cifti_brain_structure_name(name)] * self.vertex.size
293292
self.name = np.asanyarray(name, dtype='U')
294293

@@ -504,7 +503,7 @@ def to_cifti_brain_structure_name(name):
504503
"""
505504
if name in cifti2.CIFTI_BRAIN_STRUCTURES:
506505
return name
507-
if not isinstance(name, string_types):
506+
if not isinstance(name, str):
508507
if len(name) == 1:
509508
structure = name[0]
510509
orientation = 'both'
@@ -588,7 +587,7 @@ def volume_shape(self, value):
588587
value = tuple(value)
589588
if len(value) != 3:
590589
raise ValueError("Volume shape should be a tuple of length 3")
591-
if not all(isinstance(v, integer_types) for v in value):
590+
if not all(isinstance(v, int) for v in value):
592591
raise ValueError("All elements of the volume shape should be integers")
593592
self._volume_shape = value
594593

@@ -678,9 +677,9 @@ def __getitem__(self, item):
678677
679678
Otherwise returns a new BrainModelAxis
680679
"""
681-
if isinstance(item, integer_types):
680+
if isinstance(item, int):
682681
return self.get_element(item)
683-
if isinstance(item, string_types):
682+
if isinstance(item, str):
684683
raise IndexError("Can not index an Axis with a string (except for ParcelsAxis)")
685684
return self.__class__(self.name[item], self.voxel[item], self.vertex[item],
686685
self.affine, self.volume_shape, self.nvertices)
@@ -913,7 +912,7 @@ def volume_shape(self, value):
913912
value = tuple(value)
914913
if len(value) != 3:
915914
raise ValueError("Volume shape should be a tuple of length 3")
916-
if not all(isinstance(v, integer_types) for v in value):
915+
if not all(isinstance(v, int) for v in value):
917916
raise ValueError("All elements of the volume shape should be integers")
918917
self._volume_shape = value
919918

@@ -988,14 +987,14 @@ def __getitem__(self, item):
988987
- `string`: 2-element tuple of (parcel voxels, parcel vertices
989988
- other object that can index 1D arrays: new Parcel axis
990989
"""
991-
if isinstance(item, string_types):
990+
if isinstance(item, str):
992991
idx = np.where(self.name == item)[0]
993992
if len(idx) == 0:
994993
raise IndexError("Parcel %s not found" % item)
995994
if len(idx) > 1:
996995
raise IndexError("Multiple parcels with name %s found" % item)
997996
return self.voxels[idx[0]], self.vertices[idx[0]]
998-
if isinstance(item, integer_types):
997+
if isinstance(item, int):
999998
return self.get_element(item)
1000999
return self.__class__(self.name[item], self.voxels[item], self.vertices[item],
10011000
self.affine, self.volume_shape, self.nvertices)
@@ -1124,7 +1123,7 @@ def __add__(self, other):
11241123
)
11251124

11261125
def __getitem__(self, item):
1127-
if isinstance(item, integer_types):
1126+
if isinstance(item, int):
11281127
return self.get_element(item)
11291128
return self.__class__(self.name[item], self.meta[item])
11301129

@@ -1269,7 +1268,7 @@ def __add__(self, other):
12691268
)
12701269

12711270
def __getitem__(self, item):
1272-
if isinstance(item, integer_types):
1271+
if isinstance(item, int):
12731272
return self.get_element(item)
12741273
return self.__class__(self.name[item], self.label[item], self.meta[item])
12751274

@@ -1436,7 +1435,7 @@ def __getitem__(self, item):
14361435
nelements = 0
14371436
return SeriesAxis(idx_start * self.step + self.start, self.step * step,
14381437
nelements, self.unit)
1439-
elif isinstance(item, integer_types):
1438+
elif isinstance(item, int):
14401439
return self.get_element(item)
14411440
raise IndexError('SeriesAxis can only be indexed with integers or slices '
14421441
'without breaking the regular structure')

nibabel/externals/netcdf.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
from numpy import little_endian as LITTLE_ENDIAN
4141
from functools import reduce
4242

43-
from six import integer_types
44-
4543

4644
ABSENT = b'\x00\x00\x00\x00\x00\x00\x00\x00'
4745
ZERO = b'\x00\x00\x00\x00'
@@ -479,8 +477,8 @@ def _write_values(self, values):
479477
if hasattr(values, 'dtype'):
480478
nc_type = REVERSE[values.dtype.char, values.dtype.itemsize]
481479
else:
482-
types = [(t, NC_INT) for t in integer_types]
483-
types += [
480+
types = [
481+
(int, NC_INT),
484482
(float, NC_FLOAT),
485483
(str, NC_CHAR),
486484
]

nibabel/filebasedimages.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import io
1212
from copy import deepcopy
13-
from six import string_types
1413
from .fileholders import FileHolder
1514
from .filename_parser import (types_filenames, TypesFilenamesError,
1615
splitext_addext)
@@ -374,7 +373,7 @@ def make_file_map(klass, mapping=None):
374373
for key, ext in klass.files_types:
375374
file_map[key] = FileHolder()
376375
mapval = mapping.get(key, None)
377-
if isinstance(mapval, string_types):
376+
if isinstance(mapval, str):
378377
file_map[key].filename = mapval
379378
elif hasattr(mapval, 'tell'):
380379
file_map[key].fileobj = mapval

nibabel/gifti/tests/test_gifti.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import numpy as np
88

99
import nibabel as nib
10-
from six import string_types
1110
from nibabel.gifti import (GiftiImage, GiftiDataArray, GiftiLabel,
1211
GiftiLabelTable, GiftiMetaData, GiftiNVPairs,
1312
GiftiCoordSystem)
@@ -176,11 +175,11 @@ def test_to_xml_open_close_deprecations():
176175
da = GiftiDataArray(np.ones((1,)), 'triangle')
177176
with clear_and_catch_warnings() as w:
178177
warnings.filterwarnings('always', category=DeprecationWarning)
179-
assert_true(isinstance(da.to_xml_open(), string_types))
178+
assert_true(isinstance(da.to_xml_open(), str))
180179
assert_equal(len(w), 1)
181180
with clear_and_catch_warnings() as w:
182181
warnings.filterwarnings('once', category=DeprecationWarning)
183-
assert_true(isinstance(da.to_xml_close(), string_types))
182+
assert_true(isinstance(da.to_xml_close(), str))
184183
assert_equal(len(w), 1)
185184

186185

nibabel/nifti1.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
'''
1313
import warnings
1414
from io import BytesIO
15-
from six import string_types
1615

1716
import numpy as np
1817
import numpy.linalg as npl
@@ -1389,7 +1388,7 @@ def set_intent(self, code, params=(), name='', allow_unknown=False):
13891388
if not known_intent:
13901389
# We can set intent via an unknown integer code, but can't via an
13911390
# unknown string label
1392-
if not allow_unknown or isinstance(code, string_types):
1391+
if not allow_unknown or isinstance(code, str):
13931392
raise KeyError('Unknown intent code: ' + str(code))
13941393
if known_intent:
13951394
icode = intent_codes.code[code]

nibabel/optpkg.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
""" Routines to support optional packages """
22
import pkgutil
33
from distutils.version import LooseVersion
4-
from six import string_types
54
from .tripwire import TripWire
65

76
if pkgutil.find_loader('nose'):
@@ -12,7 +11,7 @@
1211

1312
def _check_pkg_version(pkg, min_version):
1413
# Default version checking function
15-
if isinstance(min_version, string_types):
14+
if isinstance(min_version, str):
1615
min_version = LooseVersion(min_version)
1716
try:
1817
return min_version <= pkg.__version__

nibabel/streamlines/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""
33
import os
44
import warnings
5-
from six import string_types
65

76
from .header import Field
87
from .array_sequence import ArraySequence
@@ -57,7 +56,7 @@ def detect_format(fileobj):
5756
except IOError:
5857
pass
5958

60-
if isinstance(fileobj, string_types):
59+
if isinstance(fileobj, str):
6160
_, ext = os.path.splitext(fileobj)
6261
return FORMATS.get(ext.lower())
6362

nibabel/tests/test_image_api.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import warnings
2828
from functools import partial
2929
from itertools import product
30-
from six import string_types
3130

3231
import numpy as np
3332

@@ -577,7 +576,7 @@ def validate_path_maybe_image(self, imaker, params):
577576
assert_true(isinstance(test, bool))
578577
if sniff is not None:
579578
assert isinstance(sniff[0], bytes)
580-
assert isinstance(sniff[1], string_types)
579+
assert isinstance(sniff[1], str)
581580

582581

583582
class MakeImageAPI(LoadImageAPI):

nibabel/tests/test_nifti1.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import warnings
1212
import struct
1313

14-
import six
15-
1614
import numpy as np
1715

1816
from nibabel import nifti1 as nifti1
@@ -942,16 +940,16 @@ def test_set_sform(self):
942940
def test_sqform_code_type(self):
943941
# make sure get_s/qform returns codes as integers
944942
img = self.image_class(np.zeros((2, 3, 4)), None)
945-
assert isinstance(img.get_sform(coded=True)[1], six.integer_types)
946-
assert isinstance(img.get_qform(coded=True)[1], six.integer_types)
943+
assert isinstance(img.get_sform(coded=True)[1], int)
944+
assert isinstance(img.get_qform(coded=True)[1], int)
947945
img.set_sform(None, 3)
948946
img.set_qform(None, 3)
949-
assert isinstance(img.get_sform(coded=True)[1], six.integer_types)
950-
assert isinstance(img.get_qform(coded=True)[1], six.integer_types)
947+
assert isinstance(img.get_sform(coded=True)[1], int)
948+
assert isinstance(img.get_qform(coded=True)[1], int)
951949
img.set_sform(None, 2.0)
952950
img.set_qform(None, 4.0)
953-
assert isinstance(img.get_sform(coded=True)[1], six.integer_types)
954-
assert isinstance(img.get_qform(coded=True)[1], six.integer_types)
951+
assert isinstance(img.get_sform(coded=True)[1], int)
952+
assert isinstance(img.get_qform(coded=True)[1], int)
955953
img.set_sform(None, img.get_sform(coded=True)[1])
956954
img.set_qform(None, img.get_qform(coded=True)[1])
957955

nibabel/tests/test_proxy_api.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
import numpy as np
3737

38-
from six import string_types
3938
from ..volumeutils import apply_read_scaling
4039
from ..analyze import AnalyzeHeader
4140
from ..spm99analyze import Spm99AnalyzeHeader
@@ -152,7 +151,7 @@ def validate_header_isolated(self, pmaker, params):
152151
def validate_fileobj_isolated(self, pmaker, params):
153152
# Check file position of read independent of file-like object
154153
prox, fio, hdr = pmaker()
155-
if isinstance(fio, string_types):
154+
if isinstance(fio, str):
156155
return
157156
assert_array_equal(prox, params['arr_out'])
158157
fio.read() # move to end of file

0 commit comments

Comments
 (0)