Skip to content

Commit 997b328

Browse files
authored
Fix compatibility fix for delete_fragments (#1966)
1 parent 19bc046 commit 997b328

File tree

3 files changed

+34
-43
lines changed

3 files changed

+34
-43
lines changed

tiledb/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
FragmentsInfo,
7777
copy_fragments_to_existing_array,
7878
create_array_from_fragments,
79-
delete_fragments,
8079
)
8180
from .group import Group
8281
from .highlevel import (

tiledb/fragment.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -341,28 +341,6 @@ def FragmentsInfo(array_uri, ctx=None):
341341
)
342342

343343

344-
def delete_fragments(
345-
uri, timestamp_range, config=None, ctx=None, verbose=False, dry_run=False
346-
):
347-
"""
348-
Delete fragments from an array located at uri that falls within a given
349-
timestamp_range.
350-
351-
:param str uri: URI for the TileDB array (any supported TileDB URI)
352-
:param (int, int) timestamp_range: (default None) If not None, vacuum the
353-
array using the given range (inclusive)
354-
:param config: Override the context configuration. Defaults to ctx.config()
355-
:param ctx: (optional) TileDB Ctx
356-
:param verbose: (optional) Print fragments being deleted (default: False)
357-
:param dry_run: (optional) Preview fragments to be deleted without
358-
running (default: False)
359-
"""
360-
raise tiledb.TileDBError(
361-
"tiledb.delete_fragments is deprecated; you must use Array.delete_fragments. "
362-
"This message will be removed in 0.21.0."
363-
)
364-
365-
366344
def create_array_from_fragments(
367345
src_uri,
368346
dst_uri,

tiledb/libtiledb.pyx

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ from json import loads as json_loads
1818
from ._generated_version import version_tuple as tiledbpy_version
1919
from .array_schema import ArraySchema
2020
from .enumeration import Enumeration
21-
from .cc import TileDBError
21+
from .cc import TileDBError
2222
from .ctx import Config, Ctx, default_ctx
2323
from .vfs import VFS
2424

@@ -1263,8 +1263,7 @@ cdef class Array(object):
12631263
_raise_ctx_err(ctx_ptr, rc)
12641264
return Enumeration.from_capsule(self.ctx, PyCapsule_New(enum_ptr, "enum", NULL))
12651265

1266-
@staticmethod
1267-
def delete_fragments(uri, timestamp_start, timestamp_end, ctx=None):
1266+
def delete_fragments(self_or_uri, timestamp_start, timestamp_end, ctx=None):
12681267
"""
12691268
Delete a range of fragments from timestamp_start to timestamp_end.
12701269
The array needs to be opened in 'm' mode as shown in the example below.
@@ -1295,28 +1294,43 @@ cdef class Array(object):
12951294
array([0., 0., 0., 0.])
12961295
12971296
"""
1298-
# If uri is an instance of Array (user calls the old instance method), issue a warning
1299-
if isinstance(uri, Array):
1297+
cdef tiledb_ctx_t* ctx_ptr
1298+
cdef tiledb_array_t* array_ptr
1299+
cdef tiledb_query_t* query_ptr
1300+
cdef bytes buri
1301+
cdef int rc = TILEDB_OK
1302+
1303+
if isinstance(self_or_uri, str):
1304+
uri = self_or_uri
1305+
if not ctx:
1306+
ctx = default_ctx()
1307+
1308+
ctx_ptr = safe_ctx_ptr(ctx)
1309+
buri = uri.encode('UTF-8')
1310+
1311+
rc = tiledb_array_delete_fragments_v2(
1312+
ctx_ptr,
1313+
buri,
1314+
timestamp_start,
1315+
timestamp_end
1316+
)
1317+
else:
1318+
array_instance = self_or_uri
13001319
warnings.warn(
13011320
"The `tiledb.Array.delete_fragments` instance method is deprecated. Use the static method with the same name instead.",
13021321
DeprecationWarning,
13031322
)
1304-
uri = uri.uri
1305-
1306-
if not ctx:
1307-
ctx = default_ctx()
1308-
1309-
cdef tiledb_ctx_t* ctx_ptr = safe_ctx_ptr(ctx)
1310-
cdef bytes buri = uri.encode('UTF-8')
1323+
ctx_ptr = safe_ctx_ptr(array_instance.ctx)
1324+
array_ptr = <tiledb_array_t*>array_instance.ptr
1325+
buri = array_instance.uri.encode('UTF-8')
13111326

1312-
cdef int rc = TILEDB_OK
1313-
1314-
rc = tiledb_array_delete_fragments_v2(
1315-
ctx_ptr,
1316-
buri,
1317-
timestamp_start,
1318-
timestamp_end
1319-
)
1327+
rc = tiledb_array_delete_fragments(
1328+
ctx_ptr,
1329+
array_ptr,
1330+
buri,
1331+
timestamp_start,
1332+
timestamp_end
1333+
)
13201334
if rc != TILEDB_OK:
13211335
_raise_ctx_err(ctx_ptr, rc)
13221336

0 commit comments

Comments
 (0)