-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Array tags are immutable views, not editable ndarrays #152
Comments
Speaking of arrays, any particular reason for |
After a couple hours reading the official docs on sub-classing
Both approaches would have to be carefully studied for eventual gotchas and corner cases, and there might have other (or better) approaches |
Hey! Thanks a lot for being so active lately! I'm busy with school stuff atm but I'm looking forward to dive into all this, hopefully next week or the week after. In the meantime keep'em coming :D |
No problem, take your time... I'll keep sending PRs and issues As for this issue, take a look at the workaround currently needed to set items in an def apply_pixels(target: Map, pixels: t.Iterable[MapPixel]) -> None:
arr = target.data['colors']
# NBT Arrays might be implemented by the NBT backend as read-only ndarray views
# If so, set the pixels in a (writeable) copy, then write back preserving original type
cls = None
if isinstance(arr, np.ndarray) and not arr.flags.writeable:
cls = arr.__class__
arr = arr.copy()
for pixel in pixels:
arr[pixel[0]] = pixel[1]
if cls:
target.data['colors'] = cls(arr) (actual code from my map-deduper project) |
Yeah I remember looking into how to subclass |
Good idea. If you go this route, use the Python's native And maybe a simple Struct on bytearrays could also efficiently cover the case for Int and Long Arrays |
Originally byte array tags used the builtin |
Btw, I'm perfectly fine with
Wait... no. Being fixed length might change everything. They lack |
i did some searching. and i found this. it use |
Any particular reason for creating them as read-only views? This forces clients to write the whole array to change a single value.
The conversion from
ndarray
t itsview
is done in this line and the following one.The text was updated successfully, but these errors were encountered: