Skip to content

Commit

Permalink
Use Index.duplicated() rather than MultiIndex.has_duplicates in Inter…
Browse files Browse the repository at this point in the history
…face/Pattern validation due to pandas bug #9075, require pandas 0.15.0 to ensure presence of Index.duplicated().
  • Loading branch information
lebedov committed Dec 15, 2014
1 parent f5c3ee3 commit 00cbc59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
11 changes: 4 additions & 7 deletions neurokernel/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,13 @@ def __init__(self, selector='', columns=['interface', 'io', 'type']):
idx = self.sel.make_index(selector, names)
self.__validate_index__(idx)
self.data = pd.DataFrame(index=idx, columns=columns, dtype=object)

def __validate_index__(self, idx):
"""
Raise an exception if the specified index will result in an invalid interface.
"""

if (hasattr(idx, 'has_duplicates') and idx.has_duplicates) or \
len(idx.unique()) < len(idx):
if idx.duplicated().any():
raise ValueError('Duplicate interface index entries detected.')

def __getitem__(self, key):
Expand Down Expand Up @@ -1177,16 +1176,14 @@ def __validate_index__(self, idx):
"""

# Prohibit duplicate connections:
if (hasattr(idx, 'has_duplicates') and idx.has_duplicates) or \
len(idx.unique()) < len(idx):
if idx.duplicated().any():
raise ValueError('Duplicate pattern entries detected.')

# Prohibit fan-in connections (i.e., patterns whose index has duplicate
# 'from' port identifiers):
from_idx, to_idx = self.split_multiindex(idx,
self.from_slice, self.to_slice)
if (hasattr(to_idx, 'has_duplicates') and to_idx.has_duplicates) or \
len(to_idx.unique()) < len(to_idx):
if to_idx.duplicated().any():
raise ValueError('Fan-in pattern entries detected.')

# Prohibit ports that both receive input and send output:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
'networkx >= 1.9',
'numexpr >= 2.3',
'numpy >= 1.2.0',
'pandas >= 0.14.1',
'pandas >= 0.15.0',
'ply >= 3.4',
'pycuda >= 2014.1',
'pyzmq >= 13.0',
Expand Down

0 comments on commit 00cbc59

Please sign in to comment.