Skip to content

Commit 3d36aa9

Browse files
committed
Added description of subtype 9 to bson.Binary docstring
1 parent 5877708 commit 3d36aa9

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

bson/binary.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,17 @@ class BinaryVector:
240240
class Binary(bytes):
241241
"""Representation of BSON binary data.
242242
243-
# TODO Add Vector subtype description
244-
245-
This is necessary because we want to represent Python strings as
246-
the BSON string type. We need to wrap binary data so we can tell
243+
We want to represent Python strings as the BSON string type.
244+
We need to wrap binary data so that we can tell
247245
the difference between what should be considered binary data and
248246
what should be considered a string when we encode to BSON.
249247
248+
Subtype 9 provides a space-efficient representation of 1-dimensional vector data.
249+
Its data is prepended with two bytes of metadata.
250+
The first (dtype) describes its data type, such as float32 or int8.
251+
The second (padding) prescribes the number of bits to ignore in the final byte.
252+
This is relevant when the element size of the dtype is not a multiple of 8.
253+
250254
Raises TypeError if subtype` is not an instance of :class:`int`.
251255
Raises ValueError if `subtype` is not in [0, 256).
252256
@@ -259,8 +263,9 @@ class Binary(bytes):
259263
<https://bsonspec.org/spec.html>`_
260264
to use
261265
262-
.. versionchanged:: 3.9
263-
Support any bytes-like type that implements the buffer protocol.
266+
.. versionchanged::
267+
3.9 Support any bytes-like type that implements the buffer protocol.
268+
4.9 Addition of vector subtype.
264269
"""
265270

266271
_type_marker = 5

0 commit comments

Comments
 (0)