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

Fix and simplify filter_adjlist. #244

Merged
merged 1 commit into from Feb 17, 2020
Merged

Conversation

QuLogic
Copy link
Contributor

@QuLogic QuLogic commented Feb 9, 2020

  1. You have run tests on this submission, either by using Travis Continuous Integration testing testing or running nosetests on your changes?
  2. This pull request is directed to the pysal/master branch.
  3. This pull introduces new functionality covered by docstrings and unittests?
  4. [N/A] You have assigned a reviewer and added relevant labels <- not possible
  5. The justification for this PR is: The docs say filter_adjust should remove elements in insertion order, but it doesn't do that because set is unordered. It is dependent on the order Python decides, which does in fact change between versions, and the related test breaks on 3.8.
    The test itself is also wrong because it removed elements in a 'nice' manner, not insertion order.

The docs say it should remove elements in insertion order, but it
doesn't because `set` is unordered. It is dependent on the order Python
decides, which does in fact change between versions, and the related
test breaks on 3.8.

The test itself is also wrong because removed elements in a 'nice'
manner, not insertion order.
to_drop_mask = ((adjlist[focal_col] == tupe[0])
& (adjlist[neighbor_col] == tupe[-1]))
to_drop = adjlist[to_drop_mask]
elif (tuple(reversed(tupe)) in undirected):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This condition was redundant with https://github.com/pysal/libpysal/pull/244/files#diff-ab25b3d21ac8613bd5cb0998c1f9f2a7L197 which added the reverse to the set.

else:
undirected.update((tupe,))
undirected.update((tuple(reversed(tupe),)))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

But there was a bug here as the comma was within the tuple call, so it really added the two elements to the set, not a reversed tuple.

@@ -34,8 +34,8 @@ def test_filter(self):
badgrid = weights.W.from_adjlist(alist)
np.testing.assert_allclose(badgrid.sparse.toarray(),
grid.sparse.toarray())
assert set(alist.focal.unique().tolist()) == set(list(range(4)))
Copy link
Contributor Author

@QuLogic QuLogic Feb 9, 2020

Choose a reason for hiding this comment

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

The adjacency list as created in the top of this test is:

   focal  neighbor  weight
0      0         2     1.0  *
1      0         1     1.0  *
2      1         0     1.0
3      1         3     1.0  *
4      2         0     1.0
5      2         3     1.0  *
6      3         1     1.0
7      3         2     1.0

I have marked the unique edges in order with*. As you can see, the documented behaviour could not have produced {0, 1, 2, 3} for either focal or neighbor.

Possibly this part of the test should be dropped entirely, because the next bits test what is actually true, that the edges are unique (not necessarily the vertices).

Copy link
Member

Choose a reason for hiding this comment

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

Sure. This test is ok to drop. The main point was to test the edges.

Copy link
Member

@ljwolf ljwolf left a comment

Choose a reason for hiding this comment

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

Looks great, thank you for the contribution!

It's ok to merge as is, or with the extra test dropped.

@@ -34,8 +34,8 @@ def test_filter(self):
badgrid = weights.W.from_adjlist(alist)
np.testing.assert_allclose(badgrid.sparse.toarray(),
grid.sparse.toarray())
assert set(alist.focal.unique().tolist()) == set(list(range(4)))
Copy link
Member

Choose a reason for hiding this comment

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

Sure. This test is ok to drop. The main point was to test the edges.

@sjsrey sjsrey merged commit 342ca3d into pysal:master Feb 17, 2020
@QuLogic QuLogic deleted the fix-filter-adjlist branch February 17, 2020 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants