Skip to content

Commit 4ab5159

Browse files
committed
Add warnings when removing existing arrays.
1 parent 3b8a5a5 commit 4ab5159

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/modelarrayio/storage/tiledb_storage.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def create_scalar_matrix_array(
177177
tile_shape,
178178
)
179179
if tiledb.object_type(uri):
180+
logger.warning('Removing existing array %s', uri)
180181
tiledb.remove(uri)
181182
tiledb.Array.create(uri, schema)
182183

@@ -268,6 +269,7 @@ def create_empty_scalar_matrix_array(
268269
tile_shape,
269270
)
270271
if tiledb.object_type(uri):
272+
logger.warning('Removing existing array %s', uri)
271273
tiledb.remove(uri)
272274
tiledb.Array.create(uri, schema)
273275

@@ -350,6 +352,7 @@ def write_parcel_names(base_uri: str, array_path: str, names: Sequence[str]):
350352
schema = tiledb.ArraySchema(domain=dom, attrs=[attr_values], sparse=False)
351353

352354
if tiledb.object_type(uri):
355+
logger.warning('Removing existing array %s', uri)
353356
tiledb.remove(uri)
354357
tiledb.Array.create(uri, schema)
355358

@@ -382,6 +385,7 @@ def write_column_names(base_uri: str, scalar: str, sources: Sequence[str]):
382385
schema = tiledb.ArraySchema(domain=dom, attrs=[attr_values], sparse=False)
383386

384387
if tiledb.object_type(uri):
388+
logger.warning('Removing existing array %s', uri)
385389
tiledb.remove(uri)
386390
tiledb.Array.create(uri, schema)
387391

test/test_voxels_cli.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,15 @@ def _build_nifti_cohort(tmp_path):
321321
return group_mask_file, cohort_csv
322322

323323

324-
def test_nifti_tiledb_fails_when_output_already_exists(tmp_path, monkeypatch):
324+
def test_nifti_tiledb_fails_when_output_already_exists(tmp_path, monkeypatch, caplog):
325325
"""Regression test for https://github.com/PennLINC/ModelArrayIO/issues/39.
326326
327-
The TileDB backend should raise an error when the output directory already
328-
contains arrays from a previous run (tiledb.Array.create fails if the URI
329-
already exists).
327+
The TileDB backend should succeed when the output directory already contains
328+
arrays from a previous run, removing and recreating them, and should emit a
329+
warning for each removed array.
330330
"""
331+
import logging
332+
331333
group_mask_file, cohort_csv = _build_nifti_cohort(tmp_path)
332334
out_tdb = tmp_path / 'out.tdb'
333335
monkeypatch.chdir(tmp_path)
@@ -346,11 +348,16 @@ def test_nifti_tiledb_fails_when_output_already_exists(tmp_path, monkeypatch):
346348
'gzip',
347349
]
348350

349-
# First run should succeed
350-
assert modelarrayio_main(cli_args) == 0
351+
# First run should succeed without any "Removing existing array" warnings.
352+
with caplog.at_level(logging.WARNING, logger='modelarrayio.storage.tiledb_storage'):
353+
assert modelarrayio_main(cli_args) == 0
351354
assert out_tdb.exists()
352355
assert tiledb.object_type(str(out_tdb / 'scalars' / 'FA' / 'values')) is not None
353-
354-
# Second run to the same output directory should succeed now that existing
355-
# arrays are removed before re-creation (regression for issue #39).
356-
assert modelarrayio_main(cli_args) == 0
356+
assert not any('Removing existing array' in r.message for r in caplog.records)
357+
358+
# Second run to the same output directory should succeed (regression for
359+
# issue #39) and emit a warning for the pre-existing array that was removed.
360+
caplog.clear()
361+
with caplog.at_level(logging.WARNING, logger='modelarrayio.storage.tiledb_storage'):
362+
assert modelarrayio_main(cli_args) == 0
363+
assert any('Removing existing array' in r.message for r in caplog.records)

0 commit comments

Comments
 (0)