From 171309d8aab34e5f7f22b17a897304b8824745a6 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 11 Jan 2019 11:17:23 -0500 Subject: [PATCH 1/3] BUG: Fix deprecated imports --- nibabel/cifti2/cifti2.py | 27 +++++++++++++++------------ nibabel/externals/oset.py | 5 ++++- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/nibabel/cifti2/cifti2.py b/nibabel/cifti2/cifti2.py index 73126b6dea..eb33e9ac73 100644 --- a/nibabel/cifti2/cifti2.py +++ b/nibabel/cifti2/cifti2.py @@ -21,8 +21,11 @@ ''' from __future__ import division, print_function, absolute_import import re -import collections - +try: + from collections.abc import MutableSequence, MutableMapping, Iterable +except ImportError: + 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 +107,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 +127,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 +176,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 +194,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 +430,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 +512,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 +736,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 +892,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 +1079,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 +1125,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..fcd253e91d 100644 --- a/nibabel/externals/oset.py +++ b/nibabel/externals/oset.py @@ -15,7 +15,10 @@ from __future__ import absolute_import -from collections import MutableSet +try: + from collections.abc import MutableSet +except ImportError: + from collections import MutableSet KEY, PREV, NEXT = range(3) From 43b1ab767dbe305be75c00c806bca5b01acf4c74 Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Sun, 13 Jan 2019 22:08:08 -0500 Subject: [PATCH 2/3] Update nibabel/cifti2/cifti2.py Co-Authored-By: larsoner --- nibabel/cifti2/cifti2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nibabel/cifti2/cifti2.py b/nibabel/cifti2/cifti2.py index eb33e9ac73..0ffe45a169 100644 --- a/nibabel/cifti2/cifti2.py +++ b/nibabel/cifti2/cifti2.py @@ -24,6 +24,7 @@ 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 8fa9b29e3459134cc9cf89cc515348eaeeee86cf Mon Sep 17 00:00:00 2001 From: Chris Markiewicz Date: Sun, 13 Jan 2019 22:08:14 -0500 Subject: [PATCH 3/3] Update nibabel/externals/oset.py Co-Authored-By: larsoner --- nibabel/externals/oset.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nibabel/externals/oset.py b/nibabel/externals/oset.py index fcd253e91d..83b1e3e24d 100644 --- a/nibabel/externals/oset.py +++ b/nibabel/externals/oset.py @@ -18,6 +18,7 @@ try: from collections.abc import MutableSet except ImportError: + # PY2 compatibility from collections import MutableSet KEY, PREV, NEXT = range(3) @@ -85,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