Skip to content

Commit 679696c

Browse files
committed
add default option handling behavior in adjlist islands
1 parent ce1b1eb commit 679696c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

libpysal/weights/weights.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ def to_adjlist(
311311
raise ImportError(
312312
"pandas must be installed & importable to use this method"
313313
)
314+
if (drop_islands is None) and not (self.silence_warnings):
315+
warnings.warn(
316+
"In the next version of libpysal, observations with no neighbors will be included in adjacency lists as loops (row with the same focal and neighbor) with zero weight. In the current version, observations with no neighbors are dropped. If you would like to keep the current behavior, use drop_islands=True in this function",
317+
DeprecationWarning,
318+
)
319+
drop_islands = True
320+
314321
links = []
315322
focal_ix, neighbor_ix = self.sparse.nonzero()
316323
names = np.asarray(self.id_order)
@@ -1363,21 +1370,19 @@ def __init__(self, sparse, id_order=None, index=None):
13631370
self._cache["id_order"] = self._id_order
13641371
# temp addition of index attribute
13651372
import pandas as pd # will be removed after refactoring is done
1373+
13661374
if index is not None:
13671375
if not isinstance(index, (pd.Index, pd.MultiIndex, pd.RangeIndex)):
13681376
raise TypeError("index must be an instance of pandas.Index dtype")
13691377
if len(index) != self.n:
1370-
raise ValueError(
1371-
"Number of values in index must match shape of sparse"
1372-
)
1378+
raise ValueError("Number of values in index must match shape of sparse")
13731379
else:
13741380
index = pd.RangeIndex(self.n)
13751381
self.index = index
13761382

13771383
@property
13781384
def id_order(self):
1379-
"""An ordered list of ids, assumed to match the ordering in ``sparse``.
1380-
"""
1385+
"""An ordered list of ids, assumed to match the ordering in ``sparse``."""
13811386
# Temporary solution until the refactoring is finished
13821387
if "id_order" not in self._cache:
13831388
if hasattr(self, "index"):

0 commit comments

Comments
 (0)