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: describe as a replacement of AverageCharacter #570

Merged
merged 11 commits into from
Apr 24, 2024

Conversation

martinfleis
Copy link
Member

I started refactoring AverageCharacter and changed my mind a couple of times on what to do about it. In the end, decided to generalise it into momepy.describe which computes "mean", "median", "std", "min", "max", "sum" and optionally "mode" of values within the neighborhood, possibly after cutting the extremes off. We still have the full functionality of the original AverageCharacter folded in though.

I am still uncertain whether this is the right API, so I'd appreciate some input @jGaboardi and @u3ks.

Also, this may be more fitting in libpysal.graph but it may be wise to keep the API there a bit leaner.

Tests are missing as of now but will add them tomorrow.

Copy link

codecov bot commented Apr 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.8%. Comparing base (4037c70) to head (7c04fa0).
Report is 15 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main    #570     +/-   ##
=======================================
+ Coverage   97.4%   97.8%   +0.4%     
=======================================
  Files         26      35      +9     
  Lines       4328    5078    +750     
=======================================
+ Hits        4214    4964    +750     
  Misses       114     114             
Files Coverage Δ
momepy/__init__.py 100.0% <100.0%> (ø)
momepy/dimension.py 98.7% <100.0%> (ø)
momepy/diversity.py 98.4% <100.0%> (ø)
momepy/functional/_diversity.py 100.0% <100.0%> (ø)
momepy/functional/tests/_testing.py 100.0% <100.0%> (ø)
momepy/functional/tests/test_distribution.py 100.0% <100.0%> (ø)
momepy/functional/tests/test_diversity.py 100.0% <100.0%> (ø)
momepy/functional/tests/test_shape.py 100.0% <100.0%> (ø)
momepy/tests/test_utils.py 99.2% <100.0%> (ø)
momepy/utils.py 98.8% <100.0%> (-<0.1%) ⬇️

Copy link
Member

@jGaboardi jGaboardi left a comment

Choose a reason for hiding this comment

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

Other than the potential swapping of values and graph I think this looks pretty nice and lean.

momepy/tests/test_utils.py Show resolved Hide resolved
momepy/functional/_distribution.py Outdated Show resolved Hide resolved
momepy/functional/_distribution.py Outdated Show resolved Hide resolved
momepy/functional/_distribution.py Outdated Show resolved Hide resolved
momepy/functional/_distribution.py Outdated Show resolved Hide resolved
momepy/functional/_distribution.py Outdated Show resolved Hide resolved
@martinfleis martinfleis marked this pull request as ready for review April 24, 2024 07:57
@martinfleis
Copy link
Member Author

Some timings:

no mode, no quantiles
# new: 141 ms ± 626 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
# old: Wall time: 12.7 s

with mode, no quantiles
# new Wall time: 15.1 s
# old Wall time: 30.2 s

no mode, quantiles
# new Wall time: 8.54 s
# old Wall time: 14.4 s

with mode and quantiles
# new Wall time: 23.6 s
# old Wall time: 30.8 s

So we're faster in all cases. How much depends on the use case.

@martinfleis martinfleis requested a review from u3ks April 24, 2024 13:15
@martinfleis
Copy link
Member Author

Merging but have numba version of the same in works. Will do follow-up.

@martinfleis martinfleis merged commit cef9290 into pysal:main Apr 24, 2024
11 checks passed
@martinfleis martinfleis deleted the spatial-average branch April 24, 2024 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants