Repository navigation
fix(PythonClient): make byte-array helpers work on NumPy 2 and add offline tests - #50
Merged
donghaiwang merged 1 commit intoOct 31, 2026
Conversation
np.fromstring lost its binary mode in NumPy 2.0, so string_to_uint8_array() and string_to_float_array() raise ValueError on numpy>=2 and any caller decoding simGetImages / depth payloads fails. Parse with np.frombuffer and keep the writable-array behaviour. Also close the PFM file explicitly in write_pfm() and add offline unit tests for the client helpers (no simulator or OpenCV needed).
donghaiwang
approved these changes
Oct 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #29 — this adds offline unit tests for the Python client; the C++
AirLibUnitTestsCI item in #29 remains open.About
PythonClient/airsim/utils.pyparsed raw payloads withnp.fromstring(..., dtype). NumPy 2.0 removed the binary mode offromstring, so on numpy>=2 both public helpers raise immediately:Any script that decodes the byte payloads returned by
simGetImages/ depth data (image_data_uint8,image_data_float) through these helpers breaks on numpy>=2. The fix parses withnp.frombuffer(...).copy(), which keeps the returned array writable exactly like the oldfromstringresult, and keeps the same dtype and error behaviour for mis-sized buffers.While in the file,
write_pfm()no longer relies on garbage collection to close the file (on Windows the handle made the file unreadable until collected), andPythonClient/README.mdgains a short "Tests" section so the new suite is discoverable.How Has This Been Tested?
Windows 11, Python 3.12.14, numpy 2.3.5, msgpack-rpc-python 0.4.1. No Unreal Engine, no simulator and no OpenCV: the tests import
airsim.utilsonly.Coverage:
list_to_2d_float_array()andget_pfm_array()shapes and dtypes;to_quaternion->to_eularian_angles);write_pfm().Before the change the two helpers raise
ValueErrorexactly as shown above; after the change they return the expected arrays and all ten tests pass.Screenshots (if appropriate)
N/A — no visual output.