Skip to content

PYTHON-5121 - Use canonical Extended JSON for BSON binary vector spec… #2215

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

Merged
merged 3 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/bson_binary_vector/float32.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{
"description": "Infinity Vector FLOAT32",
"valid": true,
"vector": ["-inf", 0.0, "inf"],
"vector": [{"$numberDouble": "-Infinity"}, 0.0, {"$numberDouble": "Infinity"} ],
"dtype_hex": "0x27",
"dtype_alias": "FLOAT32",
"padding": 0,
Expand Down
8 changes: 2 additions & 6 deletions test/test_bson_binary_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

import binascii
import codecs
import json
import struct
from pathlib import Path
from test import unittest

from bson import decode, encode
from bson import decode, encode, json_util
from bson.binary import Binary, BinaryVectorDtype

_TEST_PATH = Path(__file__).parent / "bson_binary_vector"
Expand Down Expand Up @@ -62,9 +61,6 @@ def run_test(self):
cB_exp = binascii.unhexlify(canonical_bson_exp.encode("utf8"))
decoded_doc = decode(cB_exp)
binary_obs = decoded_doc[test_key]
# Handle special float cases like '-inf'
if dtype_exp in [BinaryVectorDtype.FLOAT32]:
vector_exp = [float(x) for x in vector_exp]

# Test round-tripping canonical bson.
self.assertEqual(encode(decoded_doc), cB_exp, description)
Expand Down Expand Up @@ -104,7 +100,7 @@ def run_test(self):
def create_tests():
for filename in _TEST_PATH.glob("*.json"):
with codecs.open(str(filename), encoding="utf-8") as test_file:
test_method = create_test(json.load(test_file))
test_method = create_test(json_util.loads(test_file.read()))
setattr(TestBSONBinaryVector, "test_" + filename.stem, test_method)


Expand Down
Loading