-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Refactor hexbin(). #21352
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
Refactor hexbin(). #21352
Conversation
Are you claiming the factor of two is expected? This PR doesn't seem to change anything.... |
I'm not claiming it is expected (my quick guess is that it isn't), I'm just saying that the current implementation has |
5441bf6
to
50d6db0
Compare
I find the names
|
tx/ty it is. |
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 only a partial review. There's possibly more, but I didn't have the time to dig into the algorithm yet.
- Avoid having to copy() `x` and `y`, by not overwriting the original `x` and `y` variables but instead storing the transformed values in `trfx`/`trfy`. - Directly construct lattice1 and lattice2 as flat arrays (they are flattened at the end anyways), which allows using flat indices: the `C is None` case, becomes a simple `bincount`, the `C is not None` case can use a list-of-lists instead of an object array. - Factor out the x/y marginals handling into a for-loop, which additionally allows inlining coarse_bin. - Make the factor of 2 between nx and ny clearer (in the `for zname...` loop setup). - Construct marginals `verts` in a vectorized fashion.
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.
I'm not sure we needed this refactor - I'd have preferred something that made the whole thing clearer, but...
x
andy
, by not overwriting the originalx
andy
variables but instead storing the transformed values intrfx
/trfy
.flattened at the end anyways), which allows using flat indices:
the
C is None
case, becomes a simplebincount
, theC is not None
case can use a list-of-lists instead of an object array.
additionally allows inlining coarse_bin.
for zname...
loop setup). (See also [Bug]: Hexbin gridsize interpreted differently for x and y #21349 (comment).)
verts
in a vectorized fashion.Even if we decide to ultimately deprecate
marginals
, this should help with converting them to a reusable examples entry.PR Summary
PR Checklist
pytest
passes).flake8
on changed files to check).flake8-docstrings
and runflake8 --docstring-convention=all
).doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).