Skip to content

Commit 93a2c2d

Browse files
committed
new: convert nan and inf in local mode to none (#603)
* tests: update nan payload tests with pydantic 2.7 * fix: update local mode to mimic pydantic>=2.7.0 * fix: fix mypy * fix: do not convert bytes * fix: allow nan values in payload in local mode
1 parent 1983900 commit 93a2c2d

File tree

2 files changed

+14
-58
lines changed

2 files changed

+14
-58
lines changed

qdrant_client/local/local_collection.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import json
22
import uuid
33
from collections import OrderedDict, defaultdict
4-
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union, get_args
4+
from typing import (
5+
Any,
6+
Callable,
7+
Dict,
8+
Iterable,
9+
List,
10+
Optional,
11+
Sequence,
12+
Tuple,
13+
Union,
14+
get_args,
15+
)
516

617
import numpy as np
718
from pydantic.version import VERSION as PYDANTIC_VERSION
@@ -67,10 +78,10 @@ def _to_jsonable_python(x: Any) -> Any:
6778

6879
def to_jsonable_python(x: Any) -> Any:
6980
try:
70-
json.dumps(x, allow_nan=False)
81+
json.dumps(x, allow_nan=True)
7182
return x
7283
except Exception:
73-
return json.loads(json.dumps(x, allow_nan=False, default=_to_jsonable_python))
84+
return json.loads(json.dumps(x, allow_nan=True, default=_to_jsonable_python))
7485

7586

7687
class LocalCollection:

tests/congruence_tests/test_updates.py

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -258,61 +258,6 @@ def test_upload_collection_dict_np_arrays(local_client, remote_client):
258258
compare_collections(local_client, remote_client, UPLOAD_NUM_VECTORS)
259259

260260

261-
def test_upload_payload_contain_nan_values():
262-
# usual case when payload is extracted from pandas dataframe
263-
264-
local_client = init_local()
265-
remote_client = init_remote()
266-
267-
vector_size = 2
268-
nans_collection = "nans_collection"
269-
local_client.recreate_collection(
270-
collection_name=nans_collection,
271-
vectors_config=models.VectorParams(size=vector_size, distance=models.Distance.DOT),
272-
)
273-
remote_client.recreate_collection(
274-
collection_name=nans_collection,
275-
vectors_config=models.VectorParams(size=vector_size, distance=models.Distance.DOT),
276-
)
277-
points = generate_points(
278-
num_points=UPLOAD_NUM_VECTORS,
279-
vector_sizes=2,
280-
with_payload=False,
281-
)
282-
ids, vectors, payload = [], [], []
283-
for i in range(len(points)):
284-
points[i].payload = {"surprise": math.nan}
285-
286-
for point in points:
287-
ids.append(point.id)
288-
vectors.append(point.vector)
289-
payload.append(point.payload)
290-
291-
with pytest.raises(ValueError):
292-
local_client.upload_collection(nans_collection, vectors, payload)
293-
with pytest.raises(qdrant_client.http.exceptions.UnexpectedResponse):
294-
remote_client.upload_collection(nans_collection, vectors, payload)
295-
296-
with pytest.raises(ValueError):
297-
local_client.upload_points(nans_collection, points)
298-
with pytest.raises(qdrant_client.http.exceptions.UnexpectedResponse):
299-
remote_client.upload_points(nans_collection, points)
300-
301-
points_batch = models.Batch(
302-
ids=ids,
303-
vectors=vectors,
304-
payloads=payload,
305-
)
306-
307-
with pytest.raises(ValueError):
308-
local_client.upsert(nans_collection, points=points_batch)
309-
with pytest.raises(qdrant_client.http.exceptions.UnexpectedResponse):
310-
remote_client.upsert(nans_collection, points=points_batch)
311-
312-
local_client.delete_collection(nans_collection)
313-
remote_client.delete_collection(nans_collection)
314-
315-
316261
def test_upload_wrong_vectors():
317262
local_client = init_local()
318263
remote_client = init_remote()

0 commit comments

Comments
 (0)