Skip to content

Commit 3152c83

Browse files
committed
Update to pass the check
Signed-off-by: yangxuan <[email protected]>
1 parent caf99df commit 3152c83

File tree

4 files changed

+22
-49
lines changed

4 files changed

+22
-49
lines changed

pymilvus/_utils/validator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def validate_params(**params: Tuple[Any, Any, Optional[bool]]) -> None:
1919
ParamError: If any spec tuple is invalid or any parameter fails validation.
2020
2121
Examples:
22-
validate_params(
23-
ids=([1, 2, 3], List[int]),
24-
score=(score_value, float, True),
25-
)
22+
>>> validate_params(
23+
>>> ids=([1, 2, 3], List[int]),
24+
>>> score=(score_value, float, True),
25+
>>> )
2626
"""
2727
for name, spec in params.items():
2828
if not (2 <= len(spec) <= 3):

pymilvus/client/check.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import numpy as np
66

7-
from pymilvus._utils.validator import validate_params
87
from pymilvus.exceptions import ParamError
98
from pymilvus.grpc_gen import milvus_pb2 as milvus_types
109

pymilvus/client/grpc_handler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,9 @@ def list_partitions(self, collection_name: str, timeout: Optional[float] = None,
527527
def get_partition_stats(
528528
self, collection_name: str, partition_name: str, timeout: Optional[float] = None, **kwargs
529529
):
530-
check_pass_param(collection_name=collection_name, timeout=timeout)
530+
check_pass_param(
531+
collection_name=collection_name, partition_name=partition_name, timeout=timeout
532+
)
531533
req = Prepare.get_partition_stats_request(collection_name, partition_name)
532534
response = self._stub.GetPartitionStatistics(
533535
req, timeout=timeout, metadata=_api_level_md(**kwargs)

pymilvus/milvus_client/milvus_client.py

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
)
1818
from pymilvus.client.utils import get_params, is_vector_type
1919
from pymilvus.exceptions import (
20-
DataTypeNotMatchException,
2120
ErrorCode,
2221
MilvusException,
2322
ParamError,
@@ -235,16 +234,11 @@ def insert(
235234
Returns:
236235
Dict: Number of rows that were inserted and the inserted primary key list.
237236
"""
238-
# If no data provided, we cannot input anything
239237
if isinstance(data, Dict):
240238
data = [data]
239+
validate_params(insert_data=(data, List))
241240

242-
msg = "wrong type of argument 'data',"
243-
msg += f"expected 'Dict' or list of 'Dict', got '{type(data).__name__}'"
244-
245-
if not isinstance(data, List):
246-
raise TypeError(msg)
247-
241+
# If no data provided, we cannot input anything
248242
if len(data) == 0:
249243
return {"insert_count": 0, "ids": []}
250244

@@ -287,21 +281,16 @@ def upsert(
287281
Returns:
288282
Dict: Number of rows that were upserted.
289283
"""
290-
# If no data provided, we cannot input anything
291284
if isinstance(data, Dict):
292285
data = [data]
293286

294-
msg = "wrong type of argument 'data',"
295-
msg += f"expected 'Dict' or list of 'Dict', got '{type(data).__name__}'"
296-
297-
if not isinstance(data, List):
298-
raise TypeError(msg)
287+
validate_params(upsert_data=(data, List))
299288

289+
# If no data provided, we cannot input anything
300290
if len(data) == 0:
301291
return {"upsert_count": 0}
302292

303293
conn = self._get_connection()
304-
# Upsert into the collection.
305294
try:
306295
res = conn.upsert_rows(
307296
collection_name, data, partition_name=partition_name, timeout=timeout, **kwargs
@@ -468,17 +457,15 @@ def query(
468457
Returns:
469458
List[dict]: A list of result dicts, vectors are not included.
470459
"""
471-
if filter and not isinstance(filter, str):
472-
raise DataTypeNotMatchException(message=ExceptionsMessage.ExprType % type(filter))
460+
validate_params(filter=(filter, str, True))
473461

474-
if filter and ids is not None:
462+
if filter and ids:
475463
raise ParamError(message=ExceptionsMessage.AmbiguousQueryFilterParam)
476464

477465
if isinstance(ids, (int, str)):
478466
ids = [ids]
479467

480468
conn = self._get_connection()
481-
482469
if ids:
483470
try:
484471
schema_dict = conn.describe_collection(collection_name, timeout=timeout, **kwargs)
@@ -517,8 +504,7 @@ def query_iterator(
517504
timeout: Optional[float] = None,
518505
**kwargs,
519506
):
520-
if filter is not None and not isinstance(filter, str):
521-
raise DataTypeNotMatchException(message=ExceptionsMessage.ExprType % type(filter))
507+
validate_params(filter=(filter, str, True))
522508

523509
conn = self._get_connection()
524510
# set up schema for iterator
@@ -624,8 +610,7 @@ def search_iterator(
624610
raise ex from ex
625611

626612
# following is the old code for search_iterator V1
627-
if filter is not None and not isinstance(filter, str):
628-
raise DataTypeNotMatchException(message=ExceptionsMessage.ExprType % type(filter))
613+
validate_params(filter=(filter, str, True))
629614

630615
# set up schema for iterator
631616
try:
@@ -755,7 +740,7 @@ def get(
755740
def delete(
756741
self,
757742
collection_name: str,
758-
ids: Optional[Union[list, str, int]] = None,
743+
ids: Optional[Union[List, str, int]] = None,
759744
timeout: Optional[float] = None,
760745
filter: Optional[str] = None,
761746
partition_name: Optional[str] = None,
@@ -785,28 +770,20 @@ def delete(
785770
Dict: with key 'deleted_count' and value number of rows that were deleted.
786771
"""
787772
pks = kwargs.get("pks", [])
773+
validate_params(pks=(pks, int, str, List[int|str]))
788774
if isinstance(pks, (int, str)):
789775
pks = [pks]
790776

791-
for pk in pks:
792-
if not isinstance(pk, (int, str)):
793-
msg = f"wrong type of argument pks, expect list, int or str, got '{type(pk).__name__}'"
794-
raise TypeError(msg)
795-
796-
if ids is not None:
777+
validate_params(ids=(ids, int, str, List[int|str], True))
778+
if ids:
797779
if isinstance(ids, (int, str)):
798780
pks.append(ids)
799-
elif isinstance(ids, list):
800-
for id in ids:
801-
if not isinstance(id, (int, str)):
802-
msg = f"wrong type of argument ids, expect list, int or str, got '{type(id).__name__}'"
803-
raise TypeError(msg)
781+
elif isinstance(ids, List):
782+
validate_params(ids=(ids, List[int|str]))
804783
pks.extend(ids)
805-
else:
806-
msg = f"wrong type of argument ids, expect list, int or str, got '{type(ids).__name__}'"
807-
raise TypeError(msg)
808784

809785
# validate ambiguous delete filter param before describe collection rpc
786+
validate_params(filter=(filter, str, True))
810787
if filter and len(pks) > 0:
811788
raise ParamError(message=ExceptionsMessage.AmbiguousDeleteFilterParam)
812789

@@ -822,8 +799,6 @@ def delete(
822799
raise ex from ex
823800
expr = self._pack_pks_expr(schema_dict, pks)
824801
else:
825-
if not isinstance(filter, str):
826-
raise DataTypeNotMatchException(message=ExceptionsMessage.ExprType % type(filter))
827802
expr = filter
828803

829804
ret_pks = []
@@ -1240,9 +1215,6 @@ def get_partition_stats(
12401215
self, collection_name: str, partition_name: str, timeout: Optional[float] = None, **kwargs
12411216
) -> Dict:
12421217
conn = self._get_connection()
1243-
if not isinstance(partition_name, str):
1244-
msg = f"wrong type of argument 'partition_name', str expected, got '{type(partition_name).__name__}'"
1245-
raise TypeError(msg)
12461218
ret = conn.get_partition_stats(collection_name, partition_name, timeout=timeout, **kwargs)
12471219
result = {stat.key: stat.value for stat in ret}
12481220
if "row_count" in result:

0 commit comments

Comments
 (0)