Skip to content
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

new: convert nan and inf in local mode to none #603

Merged
merged 5 commits into from
Apr 19, 2024
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
17 changes: 14 additions & 3 deletions qdrant_client/local/local_collection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import json
import uuid
from collections import OrderedDict, defaultdict
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union, get_args
from typing import (
Any,
Callable,
Dict,
Iterable,
List,
Optional,
Sequence,
Tuple,
Union,
get_args,
)

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

def to_jsonable_python(x: Any) -> Any:
try:
json.dumps(x, allow_nan=False)
json.dumps(x, allow_nan=True)
return x
except Exception:
return json.loads(json.dumps(x, allow_nan=False, default=_to_jsonable_python))
return json.loads(json.dumps(x, allow_nan=True, default=_to_jsonable_python))


class LocalCollection:
Expand Down
55 changes: 0 additions & 55 deletions tests/congruence_tests/test_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,61 +258,6 @@ def test_upload_collection_dict_np_arrays(local_client, remote_client):
compare_collections(local_client, remote_client, UPLOAD_NUM_VECTORS)


def test_upload_payload_contain_nan_values():
# usual case when payload is extracted from pandas dataframe

local_client = init_local()
remote_client = init_remote()

vector_size = 2
nans_collection = "nans_collection"
local_client.recreate_collection(
collection_name=nans_collection,
vectors_config=models.VectorParams(size=vector_size, distance=models.Distance.DOT),
)
remote_client.recreate_collection(
collection_name=nans_collection,
vectors_config=models.VectorParams(size=vector_size, distance=models.Distance.DOT),
)
points = generate_points(
num_points=UPLOAD_NUM_VECTORS,
vector_sizes=2,
with_payload=False,
)
ids, vectors, payload = [], [], []
for i in range(len(points)):
points[i].payload = {"surprise": math.nan}

for point in points:
ids.append(point.id)
vectors.append(point.vector)
payload.append(point.payload)

with pytest.raises(ValueError):
local_client.upload_collection(nans_collection, vectors, payload)
with pytest.raises(qdrant_client.http.exceptions.UnexpectedResponse):
remote_client.upload_collection(nans_collection, vectors, payload)

with pytest.raises(ValueError):
local_client.upload_points(nans_collection, points)
with pytest.raises(qdrant_client.http.exceptions.UnexpectedResponse):
remote_client.upload_points(nans_collection, points)

points_batch = models.Batch(
ids=ids,
vectors=vectors,
payloads=payload,
)

with pytest.raises(ValueError):
local_client.upsert(nans_collection, points=points_batch)
with pytest.raises(qdrant_client.http.exceptions.UnexpectedResponse):
remote_client.upsert(nans_collection, points=points_batch)

local_client.delete_collection(nans_collection)
remote_client.delete_collection(nans_collection)


def test_upload_wrong_vectors():
local_client = init_local()
remote_client = init_remote()
Expand Down
Loading