diff --git a/nibabel/cifti2/cifti2.py b/nibabel/cifti2/cifti2.py index 73126b6dea..0ffe45a169 100644 --- a/nibabel/cifti2/cifti2.py +++ b/nibabel/cifti2/cifti2.py @@ -21,8 +21,12 @@ ''' from __future__ import division, print_function, absolute_import import re -import collections - +try: + from collections.abc import MutableSequence, MutableMapping, Iterable +except ImportError: + # PY2 compatibility + from collections import MutableSequence, MutableMapping, Iterable +from collections import OrderedDict from .. import xmlutils as xml from ..filebasedimages import FileBasedHeader from ..dataobj_images import DataobjImage @@ -104,7 +108,7 @@ def _underscore(string): return re.sub(r'([a-z0-9])([A-Z])', r'\1_\2', string).lower() -class Cifti2MetaData(xml.XmlSerializable, collections.MutableMapping): +class Cifti2MetaData(xml.XmlSerializable, MutableMapping): """ A list of name-value pairs * Description - Provides a simple method for user-supplied metadata that @@ -124,7 +128,7 @@ class Cifti2MetaData(xml.XmlSerializable, collections.MutableMapping): data : list of (name, value) tuples """ def __init__(self, metadata=None): - self.data = collections.OrderedDict() + self.data = OrderedDict() if metadata is not None: self.update(metadata) @@ -173,7 +177,7 @@ def _to_xml_element(self): return metadata -class Cifti2LabelTable(xml.XmlSerializable, collections.MutableMapping): +class Cifti2LabelTable(xml.XmlSerializable, MutableMapping): """ CIFTI2 label table: a sequence of ``Cifti2Label``s * Description - Used by NamedMap when IndicesMapToDataType is @@ -191,7 +195,7 @@ class Cifti2LabelTable(xml.XmlSerializable, collections.MutableMapping): """ def __init__(self): - self._labels = collections.OrderedDict() + self._labels = OrderedDict() def __len__(self): return len(self._labels) @@ -427,7 +431,7 @@ def _to_xml_element(self): return surf -class Cifti2VoxelIndicesIJK(xml.XmlSerializable, collections.MutableSequence): +class Cifti2VoxelIndicesIJK(xml.XmlSerializable, MutableSequence): """CIFTI2 VoxelIndicesIJK: Set of voxel indices contained in a structure * Description - Identifies the voxels that model a brain structure, or @@ -509,7 +513,7 @@ def _to_xml_element(self): return vox_ind -class Cifti2Vertices(xml.XmlSerializable, collections.MutableSequence): +class Cifti2Vertices(xml.XmlSerializable, MutableSequence): """CIFTI2 vertices - association of brain structure and a list of vertices * Description - Contains a BrainStructure type and a list of vertex indices @@ -733,7 +737,7 @@ def _to_xml_element(self): return volume -class Cifti2VertexIndices(xml.XmlSerializable, collections.MutableSequence): +class Cifti2VertexIndices(xml.XmlSerializable, MutableSequence): """CIFTI2 vertex indices: vertex indices for an associated brain model The vertex indices (which are independent for each surface, and @@ -889,7 +893,7 @@ def _to_xml_element(self): return brain_model -class Cifti2MatrixIndicesMap(xml.XmlSerializable, collections.MutableSequence): +class Cifti2MatrixIndicesMap(xml.XmlSerializable, MutableSequence): """Class for Matrix Indices Map * Description - Provides a mapping between matrix indices and their @@ -1076,7 +1080,7 @@ def _to_xml_element(self): return mat_ind_map -class Cifti2Matrix(xml.XmlSerializable, collections.MutableSequence): +class Cifti2Matrix(xml.XmlSerializable, MutableSequence): """ CIFTI2 Matrix object This is a list-like container where the elements are instances of @@ -1122,7 +1126,7 @@ def _get_indices_from_mim(self, mim): applies_to_matrix_dimension = mim.applies_to_matrix_dimension if not isinstance( applies_to_matrix_dimension, - collections.Iterable + Iterable ): applies_to_matrix_dimension = (int(applies_to_matrix_dimension),) return applies_to_matrix_dimension diff --git a/nibabel/externals/oset.py b/nibabel/externals/oset.py index 6bc6ed67a3..83b1e3e24d 100644 --- a/nibabel/externals/oset.py +++ b/nibabel/externals/oset.py @@ -15,7 +15,11 @@ from __future__ import absolute_import -from collections import MutableSet +try: + from collections.abc import MutableSet +except ImportError: + # PY2 compatibility + from collections import MutableSet KEY, PREV, NEXT = range(3) @@ -82,4 +86,4 @@ def __eq__(self, other): return set(self) == set(other) def __del__(self): - self.clear() # remove circular references \ No newline at end of file + self.clear() # remove circular references