diff --git a/tiledb/__init__.py b/tiledb/__init__.py index 6f60d10afb..ec61839fdb 100644 --- a/tiledb/__init__.py +++ b/tiledb/__init__.py @@ -76,7 +76,6 @@ FragmentsInfo, copy_fragments_to_existing_array, create_array_from_fragments, - delete_fragments, ) from .group import Group from .highlevel import ( diff --git a/tiledb/fragment.py b/tiledb/fragment.py index 4aa7540d1f..059ae7f026 100644 --- a/tiledb/fragment.py +++ b/tiledb/fragment.py @@ -341,28 +341,6 @@ def FragmentsInfo(array_uri, ctx=None): ) -def delete_fragments( - uri, timestamp_range, config=None, ctx=None, verbose=False, dry_run=False -): - """ - Delete fragments from an array located at uri that falls within a given - timestamp_range. - - :param str uri: URI for the TileDB array (any supported TileDB URI) - :param (int, int) timestamp_range: (default None) If not None, vacuum the - array using the given range (inclusive) - :param config: Override the context configuration. Defaults to ctx.config() - :param ctx: (optional) TileDB Ctx - :param verbose: (optional) Print fragments being deleted (default: False) - :param dry_run: (optional) Preview fragments to be deleted without - running (default: False) - """ - raise tiledb.TileDBError( - "tiledb.delete_fragments is deprecated; you must use Array.delete_fragments. " - "This message will be removed in 0.21.0." - ) - - def create_array_from_fragments( src_uri, dst_uri, diff --git a/tiledb/libtiledb.pyx b/tiledb/libtiledb.pyx index 585dc6cf5b..29a33de467 100644 --- a/tiledb/libtiledb.pyx +++ b/tiledb/libtiledb.pyx @@ -18,7 +18,7 @@ from json import loads as json_loads from ._generated_version import version_tuple as tiledbpy_version from .array_schema import ArraySchema from .enumeration import Enumeration -from .cc import TileDBError +from .cc import TileDBError from .ctx import Config, Ctx, default_ctx from .vfs import VFS @@ -1263,8 +1263,7 @@ cdef class Array(object): _raise_ctx_err(ctx_ptr, rc) return Enumeration.from_capsule(self.ctx, PyCapsule_New(enum_ptr, "enum", NULL)) - @staticmethod - def delete_fragments(uri, timestamp_start, timestamp_end, ctx=None): + def delete_fragments(self_or_uri, timestamp_start, timestamp_end, ctx=None): """ Delete a range of fragments from timestamp_start to timestamp_end. The array needs to be opened in 'm' mode as shown in the example below. @@ -1295,28 +1294,43 @@ cdef class Array(object): array([0., 0., 0., 0.]) """ - # If uri is an instance of Array (user calls the old instance method), issue a warning - if isinstance(uri, Array): + cdef tiledb_ctx_t* ctx_ptr + cdef tiledb_array_t* array_ptr + cdef tiledb_query_t* query_ptr + cdef bytes buri + cdef int rc = TILEDB_OK + + if isinstance(self_or_uri, str): + uri = self_or_uri + if not ctx: + ctx = default_ctx() + + ctx_ptr = safe_ctx_ptr(ctx) + buri = uri.encode('UTF-8') + + rc = tiledb_array_delete_fragments_v2( + ctx_ptr, + buri, + timestamp_start, + timestamp_end + ) + else: + array_instance = self_or_uri warnings.warn( "The `tiledb.Array.delete_fragments` instance method is deprecated. Use the static method with the same name instead.", DeprecationWarning, ) - uri = uri.uri - - if not ctx: - ctx = default_ctx() - - cdef tiledb_ctx_t* ctx_ptr = safe_ctx_ptr(ctx) - cdef bytes buri = uri.encode('UTF-8') + ctx_ptr = safe_ctx_ptr(array_instance.ctx) + array_ptr = array_instance.ptr + buri = array_instance.uri.encode('UTF-8') - cdef int rc = TILEDB_OK - - rc = tiledb_array_delete_fragments_v2( - ctx_ptr, - buri, - timestamp_start, - timestamp_end - ) + rc = tiledb_array_delete_fragments( + ctx_ptr, + array_ptr, + buri, + timestamp_start, + timestamp_end + ) if rc != TILEDB_OK: _raise_ctx_err(ctx_ptr, rc)