-
Notifications
You must be signed in to change notification settings - Fork 79
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
Categorical spatial lag using the Graph #716
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #716 +/- ##
======================================
Coverage 85.0% 85.0%
======================================
Files 141 145 +4
Lines 15203 15462 +259
======================================
+ Hits 12924 13149 +225
- Misses 2279 2313 +34
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Three ruff
errors (2 linting & 1 formatting) need to to fixed locally and re-pushed.
ruff.....................................................................Failed
- hook id: ruff
- exit code: 1
libpysal/graph/tests/test_spatial_lag.py:1:1: I001 [*] Import block is un-sorted or un-formatted
libpysal/graph/tests/test_spatial_lag.py:62:13: F841 Local variable `yl` is assigned to but never used
Found 2 errors.
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
ruff-format..............................................................Failed
- hook id: ruff-format
- files were modified by this hook
2 files reformatted, 151 files left unchanged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be propagated to base.py
libpysal/libpysal/graph/base.py
Line 1618 in 5bda115
def lag(self, y): |
Detect categorical dtype Co-authored-by: Martin Fleischmann <martin@martinfleischmann.net>
spelling Co-authored-by: James Gaboardi <jgaboardi@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor suggestions in tests.
As mentioned before, this needs to propagate to
libpysal/libpysal/graph/base.py
Lines 1618 to 1635 in 5bda115
def lag(self, y): | |
"""Spatial lag operator | |
If weights are row standardized, returns the mean of each | |
observation's neighbors; if not, returns the weighted sum | |
of each observation's neighbors. | |
Parameters | |
---------- | |
y : array-like | |
array-like (N,) shape where N is equal to number of observations in self. | |
Returns | |
------- | |
numpy.ndarray | |
array of numeric values for the spatial lag | |
""" | |
return _lag_spatial(self, y) |
Co-authored-by: Martin Fleischmann <martin@martinfleischmann.net>
Co-authored-by: Martin Fleischmann <martin@martinfleischmann.net>
What would you think about dispatching to categorical lag if the type is categorical? I can appreciate that this might make the lag type implicit, but if someone has cast the variable to a categorical already, I think we can infer that they need the appropriate lag function? |
@ljwolf that is what we do on l. 87, no? |
Co-authored-by: Martin Fleischmann <martin@martinfleischmann.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just two minor nits on the docstring. Also, ruff complains at the moment. But once that is solved, happy to merge.
Co-authored-by: Martin Fleischmann <martin@martinfleischmann.net>
Co-authored-by: Martin Fleischmann <martin@martinfleischmann.net>
pre-commit.ci autofix |
This has two changes from the creation of categorical spatial lags using W
categorical
is now an option in_lag_spatial
, to unify treatment of the lag.categorical=True
,ties=raise
, and ties are encountered."Explicit is better than implicit."