Skip to content

Fix atom-structure pickle #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 18, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
MNT: add isiterable utility function
Also fix deprecation warning in Python 3.7 on `Iterable`
move to `collections.abc`.
  • Loading branch information
pavoljuhas committed Apr 17, 2019
commit 5ba9300ab2682d4a03d3a2b8a68a9aab087af7f2
4 changes: 2 additions & 2 deletions src/diffpy/structure/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""This module defines class Structure.
"""

import collections
import copy
import numpy
import codecs
Expand All @@ -25,6 +24,7 @@
from diffpy.structure.lattice import Lattice
from diffpy.structure.atom import Atom
from diffpy.structure.utils import _linkAtomAttribute, atomBareSymbol
from diffpy.structure.utils import isiterable

# ----------------------------------------------------------------------------

Expand Down Expand Up @@ -388,7 +388,7 @@ def __getitem__(self, idx):
# check if there is any string label that should be resolved
scalarstringlabel = isinstance(idx, six.string_types)
hasstringlabel = scalarstringlabel or (
isinstance(idx, collections.Iterable) and
isiterable(idx) and
any(isinstance(ii, six.string_types) for ii in idx))
# if not, use numpy indexing to resolve idx
if not hasstringlabel:
Expand Down
12 changes: 12 additions & 0 deletions src/diffpy/structure/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@
"""Small shared functions.
"""

import six
import numpy

if six.PY2:
from collections import Iterable as _Iterable
else:
from collections.abc import Iterable as _Iterable


def isiterable(obj):
"""True if argument is iterable."""
rv = isinstance(obj, _Iterable)
return rv


def isfloat(s):
"""True if argument can be converted to float"""
Expand Down