Skip to content

Commit 1352315

Browse files
authored
Merge pull request #230 from ljwolf/218
raise warning when islands are used in to_adjlist
2 parents c6812ee + 1bff027 commit 1352315

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

libpysal/weights/weights.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,14 @@ def to_adjlist(self,
257257
import pandas as pd
258258
except ImportError:
259259
raise ImportError('pandas must be installed to use this method')
260-
adjlist = pd.DataFrame(((idx, n, w) for idx, neighb in self
261-
for n, w in list(neighb.items())),
262-
columns=('focal', 'neighbor', 'weight'))
263-
return adjtools.filter_adjlist(
264-
adjlist) if remove_symmetric else adjlist
260+
n_islands = len(self.islands)
261+
if n_islands > 0 and (not self.silence_warnings):
262+
warnings.warn('{} islands in this weights matrix. Conversion to an '
263+
'adjacency list will drop these observations!')
264+
adjlist = pd.DataFrame(((idx, n,w) for idx, neighb in self
265+
for n,w in list(neighb.items())),
266+
columns = ('focal', 'neighbor', 'weight'))
267+
return adjtools.filter_adjlist(adjlist) if remove_symmetric else adjlist
265268

266269
def to_networkx(self):
267270
"""

0 commit comments

Comments
 (0)