Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: include Graph.describe() to describe neighbourhood values #717

Merged
merged 10 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libpysal/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@
"""

if not isinstance(y, pd.Series):
y = pd.Series(y)
y = pd.Series(y, index=self.unique_ids)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this, we may want to check that the y.index matches self.unique_ids in case of a custom Series is passed. I suppose that non-matching index may break this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a check


if q is None:
grouper = y.take(self._adjacency.index.codes[1]).groupby(
Expand All @@ -2053,7 +2053,7 @@

stat_.index = self.unique_ids
if isinstance(stat_, pd.Series):
stat_.name = None

Check warning on line 2056 in libpysal/graph/base.py

View check run for this annotation

Codecov / codecov/patch

libpysal/graph/base.py#L2056

Added line #L2056 was not covered by tests
# NA isolates
stat_.loc[self.isolates] = np.nan
return stat_
Expand Down
14 changes: 14 additions & 0 deletions libpysal/graph/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,3 +1194,17 @@ def test_describe(self):
check_dtype=False,
check_names=False,
)

## test passing ndarray
stats1 = nybb_contig.describe(self.nybb.geometry.area, statistics=["sum"])[
"sum"
]
stats2 = nybb_contig.describe(
self.nybb.geometry.area.values, statistics=["sum"]
)["sum"]
pd.testing.assert_series_equal(
stats1,
stats2,
check_dtype=False,
check_names=False,
)
Loading