Skip to content
Open
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
9 changes: 8 additions & 1 deletion pymilvus/client/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
import grpc
from grpc._cython import cygrpc

from pymilvus.decorators import ignore_unimplemented, retry_on_rpc_failure, upgrade_reminder
from pymilvus.decorators import (
deprecated_func,
ignore_unimplemented,
retry_on_rpc_failure,
upgrade_reminder,
)
from pymilvus.exceptions import (
AmbiguousIndexName,
DataNotMatchException,
Expand Down Expand Up @@ -1861,6 +1866,7 @@ def get_compaction_plans(
return cp

@retry_on_rpc_failure()
@deprecated_func(reason="Will be removed in 3.0, Use describe_replica instead")
def get_replicas(
self, collection_name: str, timeout: Optional[float] = None, **kwargs
) -> Replica:
Expand Down Expand Up @@ -1919,6 +1925,7 @@ def describe_replica(
return groups

@retry_on_rpc_failure()
@deprecated_func(reason="Will be removed in 3.0, Use bulk_writer.bulk_import instead")
def do_bulk_insert(
self,
collection_name: str,
Expand Down
38 changes: 28 additions & 10 deletions pymilvus/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import functools
import logging
import time
import warnings
from typing import Any, Callable, Optional

import grpc
Expand All @@ -14,18 +15,35 @@
WARNING_COLOR = "\033[93m{}\033[0m"


def deprecated(func: Any):
@functools.wraps(func)
def inner(*args, **kwargs):
LOGGER.warning(
WARNING_COLOR.format(
"[WARNING] PyMilvus: ",
"class Milvus will be deprecated soon, please use Collection/utility instead",
def deprecated_func(reason: str=""):
def decorator(func: Any):
@functools.wraps(func)
def wrapper(*args, **kwargs):
warnings.warn(
f"{func.__name__} is deprecated. {reason}",
category=DeprecationWarning,
stacklevel=2,
)
return func(*args, **kwargs)
return wrapper
return decorator

def deprecated_cls(reason: str=""):
def decorator(cls: Any):
original_init = cls.__init__

@functools.wraps(original_init)
def new_init(*args, **kwargs):
warnings.warn(
f"{cls.__name__} is deprecated. {reason}",
category=DeprecationWarning,
stacklevel=2,
)
)
return func(*args, **kwargs)
return original_init(*args, **kwargs)

return inner
cls.__init__ = new_init
return cls
return decorator


# Reference: https://grpc.github.io/grpc/python/grpc.html#grpc-status-code
Expand Down
39 changes: 20 additions & 19 deletions pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
from typing import Dict, List, Optional, Union

from pymilvus .decorators import deprecated_func

from pymilvus.client.abstract import AnnSearchRequest, BaseRanker
from pymilvus.client.constants import DEFAULT_CONSISTENCY_LEVEL
from pymilvus.client.embedding_list import EmbeddingList
Expand Down Expand Up @@ -799,16 +801,15 @@ def describe_collection(self, collection_name: str, timeout: Optional[float] = N

return result

def has_collection(self, collection_name: str, timeout: Optional[float] = None, **kwargs):
def has_collection(self, collection_name: str, timeout: Optional[float] = None, **kwargs) -> bool:
conn = self._get_connection()
return conn.has_collection(collection_name, timeout=timeout, **kwargs)

def list_collections(self, **kwargs):
def list_collections(self, **kwargs) -> List[str]:
conn = self._get_connection()
return conn.list_collections(**kwargs)

def drop_collection(self, collection_name: str, timeout: Optional[float] = None, **kwargs):
"""Delete the collection stored in this object"""
conn = self._get_connection()
conn.drop_collection(collection_name, timeout=timeout, **kwargs)

Expand Down Expand Up @@ -950,14 +951,13 @@ def list_indexes(self, collection_name: str, field_name: Optional[str] = "", **k
return all the indexes of this collection, otherwise this interface will return
all indexes on this field of the collection.

:param collection_name: The name of collection.
:type collection_name: str

:param field_name: The name of field. If no field name is specified, all indexes
of this collection will be returned.
Args:
collection_name (str): The name of collection.
field_name (str, Optional): The name of field. If no field name is specified,
all indexes of this collection will be returned.

:return: The name list of all indexes.
:rtype: str list
Returns:
List(str): The name list of all indexes.
"""
conn = self._get_connection()
indexes = conn.list_indexes(collection_name, **kwargs)
Expand Down Expand Up @@ -1009,7 +1009,7 @@ def drop_index_properties(

def alter_collection_properties(
self, collection_name: str, properties: dict, timeout: Optional[float] = None, **kwargs
):
) -> None:
conn = self._get_connection()
conn.alter_collection_properties(
collection_name,
Expand Down Expand Up @@ -1059,16 +1059,17 @@ def add_collection_field(
"""Add a new field to the collection.

Args:
collection_name(``string``): The name of collection.
name (str): The name of the field.
dtype (DataType): The data type of the field.
desc (str): The description of the field.
timeout (``float``, optional): A duration of time in seconds to allow for the RPC.
collection_name(string): The name of collection.
field_name (str): The name of the field.
data_type (DataType): The data type of the field.
desc (str, Optional): The description of the field.
timeout (float, Optional): A duration of time in seconds to allow for the RPC.
If timeout is set to None, the client keeps waiting until the server
responds or an error occurs.
**kwargs (``dict``): Optional field params
nullable: bool, indicates field is nullable or not, shall be ``True`` for now
default_value: default val for added field

* nullable (bool), indicates field is nullable or not, shall be ``True`` for now
* default_value (Any): default val for added field

Raises:
MilvusException: If anything goes wrong
Expand Down Expand Up @@ -1348,7 +1349,7 @@ def list_aliases(
conn = self._get_connection()
return conn.list_aliases(collection_name, timeout=timeout, **kwargs)

# deprecated same to use_database
@deprecated_func(reason="Will be removed in 3.0, Use use_database instead")
def using_database(self, db_name: str, **kwargs):
self.use_database(db_name, **kwargs)

Expand Down
Loading