single-cell-data / TileDB-SOMA

Python and R SOMA APIs using TileDB’s cloud-native format. Ideal for single-cell data at any scale.
MIT License
82 stars 23 forks source link

[python/r] Add `reopen` convenience method to `TileDBObject` #921

Closed atolopko-czi closed 3 weeks ago

atolopko-czi commented 1 year ago

Is your feature request related to a problem? Please describe. As syntactic sugar, add a common method for re-opening a TileDBObject in order to obtain a new read or write handle without using a class-level method.

Describe the solution you'd like Instead of having to do:

with tiledbsoma.Collection.create() as coll:
    # do some writes with `coll`

    tiledbsoma.Collection.open(coll.uri, 'r' context=coll.context) as coll_r:
        # do some reads with `coll_r`

allow for:

with tiledbsoma.Collection.create() as coll:
    # do some writes with `coll`

    with coll.reopen('r') as coll_r:
        # do some reads with `coll_r`

Describe alternatives you've considered None.

Additional context Since TileDBObjects can only be used for read xor writes, the above usage pattern is likely common. It may also be useful for repeated reads, when the client code doesn't want to keep the reader open (for some reason), but still maintains the read handle to the object.

thetorpedodog commented 1 year ago

This is implied by both the text and the code sample, but to spell it out explicitly: the proposal is that reopen return a new object, and that the current object remain unchanged—not closed, nor its open mode changed.

johnkerl commented 4 months ago

@mojaveazure is doing this for R on #2372

I've asked him to attempt this for Python as well -- as a hopefully quick cross-pollination issue -- with the understanding that if it's harder than I thought, I'm happy to finish it off.

johnkerl commented 3 weeks ago

Re-opening for tracking clarity until #2820 is done

johnkerl commented 3 weeks ago

2820 is done