Skip to content

Commit 028e552

Browse files
authored
COMPAT: pandas 3.0 compatibillity in Graph (#814)
* COMPAT: pandas 3.0 compatibillity in Graph * skip tests depending on EEA large rivers * properly skip * enable eea tests again
1 parent 18a14d0 commit 028e552

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

.github/workflows/unittests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ jobs:
6969
7070
geodatasets.fetch("nybb")
7171
geodatasets.fetch("geoda liquor_stores")
72-
geodatasets.fetch("eea large_rivers")
7372
geodatasets.fetch("geoda groceries")
7473
geodatasets.fetch("geoda guerry")
7574
libpysal.examples.fetch_all()

libpysal/graph/_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _neighbor_dict_to_edges(neighbors, weights=None):
143143
FutureWarning,
144144
)
145145
idxs = idxs.fillna(pd.Series(idxs.index, index=idxs.index)) # self-loops
146-
heads, tails = idxs.index.values, idxs.values
146+
heads, tails = idxs.index.to_numpy(), idxs.to_numpy()
147147
tails = tails.astype(heads.dtype)
148148
if weights is not None:
149149
with warnings.catch_warnings():

libpysal/graph/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,8 +1853,13 @@ def asymmetry(self, intrinsic=True):
18531853
zip(np.arange(self.unique_ids.shape[0]), self.unique_ids, strict=True)
18541854
)
18551855
focal, neighbor = np.nonzero(wd)
1856-
focal = focal.astype(self._adjacency.index.dtypes["focal"])
1857-
neighbor = neighbor.astype(self._adjacency.index.dtypes["focal"])
1856+
dtype = (
1857+
self._adjacency.index.dtypes["focal"]
1858+
if self._adjacency.index.dtypes["focal"] != "str"
1859+
else "object"
1860+
)
1861+
focal = focal.astype(dtype)
1862+
neighbor = neighbor.astype(dtype)
18581863
for i in i2id:
18591864
focal[focal == i] = i2id[i]
18601865
neighbor[neighbor == i] = i2id[i]

libpysal/graph/tests/test_base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ def setup_method(self):
5656
self.weight_dict_str_binary.values(),
5757
name="weight",
5858
index=pd.MultiIndex.from_arrays(
59-
[self.index_str, self.neighbor_dict_str.values()],
59+
# list() to allow pandas to coerce the data to its StringDtype
60+
[list(self.index_str), self.neighbor_dict_str.values()],
6061
names=["focal", "neighbor"],
6162
),
6263
)
@@ -457,7 +458,8 @@ def test_from_dicts(self):
457458
pd.testing.assert_series_equal(
458459
g._adjacency,
459460
self.adjacency_str_binary,
460-
check_dtype=False,
461+
check_dtype=True,
462+
check_index_type=False,
461463
)
462464

463465
@pytest.mark.parametrize("y", [3, 5])
@@ -617,7 +619,6 @@ def test_cardinalities(self):
617619
[3, 3, 2, 3, 4, 3, 2, 3, 2, 0],
618620
index=pd.Index(
619621
["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
620-
dtype="object",
621622
name="focal",
622623
),
623624
name="cardinalities",

0 commit comments

Comments
 (0)