Skip to content

Commit 1796a60

Browse files
committed
Fix NDArray.size to return the number of elements, not size in bytes
1 parent 971dfe2 commit 1796a60

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

RELEASE_NOTES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
## Changes from 3.11.0 to 3.11.1
44

5-
XXX version-specific blurb XXX
5+
* Change the `NDArray.size` to return the number of elements in array,
6+
instead of the size of the array in bytes. This follows the array
7+
API, so it is considered a fix, and takes precedence over a possible
8+
backward incompatibility.
69

710
## Changes from 3.10.2 to 3.11.0
811

src/blosc2/blosc2_ext.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ cdef class NDArray:
23872387

23882388
@property
23892389
def size(self):
2390-
return self.array.nitems * self.array.sc.typesize
2390+
return self.array.nitems
23912391

23922392
@property
23932393
def chunksize(self):
@@ -2556,7 +2556,7 @@ cdef class NDArray:
25562556
return self
25572557

25582558
def tobytes(self):
2559-
buffersize = self.size
2559+
buffersize = self.size * self.array.sc.typesize
25602560
buffer = bytes(buffersize)
25612561
_check_rc(b2nd_to_cbuffer(self.array, <void *> <char *> buffer, buffersize),
25622562
"Error while filling the buffer")

0 commit comments

Comments
 (0)