diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 5ac24eb20..c56bb5055 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -69,7 +69,6 @@ jobs: geodatasets.fetch("nybb") geodatasets.fetch("geoda liquor_stores") - geodatasets.fetch("eea large_rivers") geodatasets.fetch("geoda groceries") geodatasets.fetch("geoda guerry") libpysal.examples.fetch_all() diff --git a/libpysal/graph/_utils.py b/libpysal/graph/_utils.py index 411779479..bed5ed368 100644 --- a/libpysal/graph/_utils.py +++ b/libpysal/graph/_utils.py @@ -143,7 +143,7 @@ def _neighbor_dict_to_edges(neighbors, weights=None): FutureWarning, ) idxs = idxs.fillna(pd.Series(idxs.index, index=idxs.index)) # self-loops - heads, tails = idxs.index.values, idxs.values + heads, tails = idxs.index.to_numpy(), idxs.to_numpy() tails = tails.astype(heads.dtype) if weights is not None: with warnings.catch_warnings(): diff --git a/libpysal/graph/base.py b/libpysal/graph/base.py index dce9ef605..d9e7bb588 100644 --- a/libpysal/graph/base.py +++ b/libpysal/graph/base.py @@ -1853,8 +1853,13 @@ def asymmetry(self, intrinsic=True): zip(np.arange(self.unique_ids.shape[0]), self.unique_ids, strict=True) ) focal, neighbor = np.nonzero(wd) - focal = focal.astype(self._adjacency.index.dtypes["focal"]) - neighbor = neighbor.astype(self._adjacency.index.dtypes["focal"]) + dtype = ( + self._adjacency.index.dtypes["focal"] + if self._adjacency.index.dtypes["focal"] != "str" + else "object" + ) + focal = focal.astype(dtype) + neighbor = neighbor.astype(dtype) for i in i2id: focal[focal == i] = i2id[i] neighbor[neighbor == i] = i2id[i] diff --git a/libpysal/graph/tests/test_base.py b/libpysal/graph/tests/test_base.py index 3b3ff3392..92cd36026 100644 --- a/libpysal/graph/tests/test_base.py +++ b/libpysal/graph/tests/test_base.py @@ -56,7 +56,8 @@ def setup_method(self): self.weight_dict_str_binary.values(), name="weight", index=pd.MultiIndex.from_arrays( - [self.index_str, self.neighbor_dict_str.values()], + # list() to allow pandas to coerce the data to its StringDtype + [list(self.index_str), self.neighbor_dict_str.values()], names=["focal", "neighbor"], ), ) @@ -457,7 +458,8 @@ def test_from_dicts(self): pd.testing.assert_series_equal( g._adjacency, self.adjacency_str_binary, - check_dtype=False, + check_dtype=True, + check_index_type=False, ) @pytest.mark.parametrize("y", [3, 5]) @@ -617,7 +619,6 @@ def test_cardinalities(self): [3, 3, 2, 3, 4, 3, 2, 3, 2, 0], index=pd.Index( ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"], - dtype="object", name="focal", ), name="cardinalities",