Repository navigation
docs(surfarray): document float array rounding in blit_array/make_surface - #3844
oddbookworm merged 3 commits into
Conversation
…face Both functions silently accept NumPy float arrays, round them to the nearest integer, and copy into a new uint32 array before proceeding -- even though the docstrings claimed only integer/ASCII/record arrays are accepted. This extra copy also defeats the performance benefit these functions are meant to provide, which was surprising enough to tank someone's perf debugging (see the linked issue). No behavior change; docs only. Fixes pygame-community#3683
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughClarifies that ChangesSurfarray documentation
Estimated code review effort: 1 (Trivial) | ~2 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/reST/ref/surfarray.rst`:
- Around line 270-271: Update the blit_array documentation to explicitly state
that only NumPy float32, float64, and optionally float96 arrays are rounded and
copied; revise the preceding accepted-dtype statement so it no longer
contradicts float support. Apply the same correction to both referenced
documentation passages.
In `@src_py/surfarray.py`:
- Around line 105-108: Update the docstrings for blit_array and the related
array-copy function to explicitly list only float32, float64, and optional
float96 as supported NumPy float dtypes. Remove the broad “all NumPy float
arrays” wording and revise the preceding acceptance description so it includes
these supported float types alongside integer, ASCII character, and record
arrays without claiming unsupported dtypes are accepted.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fe028c86-dbe4-4424-90f7-5ec44dfc6ad9
📒 Files selected for processing (2)
docs/reST/ref/surfarray.rstsrc_py/surfarray.py
CodeRabbit review on pygame-community#3844 flagged two issues: - "NumPy float arrays" overstated the scope; only float32, float64, and (where available) float96 are actually rounded and accepted (per the numpy_floats list), so name them explicitly instead. - blit_array's docstring said "Only integer, ASCII character and record arrays are accepted" immediately before also accepting floats -- reworded to avoid the contradiction.
Starbuck5
left a comment
There was a problem hiding this comment.
Thanks for taking a look at this, I'm good to go with it.
However, I don't think it fully resolves #3683, just makes it better. Since it doesn't do a warning or decisively figure we don't need a warning. But that could make it more complicated, this is good.
I put a comment on the parent issue as well about going to "any numpy float array" instead of certain hardcoded values.
… vs float performance difference and no longer imply that passing a float array is as slow as a naive python version
oddbookworm
left a comment
There was a problem hiding this comment.
LGTM with that quick fix in! 🎉
Fixes
Fixes #3683
Problem
surfarray.blit_arrayandsurfarray.make_surfaceboth silently accept NumPy float arrays:...even though both docstrings/reference docs state only integer, ASCII character, or record arrays are accepted. This is undocumented anywhere, and as the issue reporter found, it's a silent perf trap: passing a float array by mistake causes an implicit rounding-and-copy pass, defeating the whole point of these being the "fast path" functions.
Confirmed the current (2.5.7) behavior directly:
Fix
Doc-only change, no behavior change:
blit_arrayandmake_surfacedocstrings insrc_py/surfarray.pyto state that float arrays are accepted, rounded, and copied -- and that this defeats the performance benefit ofblit_array.docs/reST/ref/surfarray.rst.Test plan
.rstwithdocutilsto confirm no new syntax errors were introduced (pre-existing Sphinx-only directives like.. function::/:sl:/:mod:predictably show as "unknown" under bare docutils across the whole file, not just the edited sections -- this is expected without a full Sphinx build).ast.parse()on the editedsurfarray.pyto confirm valid Python syntax.dev.py docs --full; this change doesn't touch any C code or runtime behavior.