Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] Re-introduce tiledb_ctx for SOMATileDBContext #3335

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

nguyenv
Copy link
Member

@nguyenv nguyenv commented Nov 18, 2024

Issue and/or context:

[sc-58711]

Changes:

  • Re-introduce the tiledb_ctx argument
  • Correct documentation
  • Update typing

Notes for Reviewer:

We are not reintroducing tiledb-py as a dependency. The tiledb_ctx is only usable when tiledb-py is installed.

@nguyenv nguyenv changed the title [python] Re-introduce tiledb_ctx for SOMATileDBContext [python] Re-introduce tiledb_ctx for SOMATileDBContext Nov 18, 2024
Copy link

codecov bot commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 68.08511% with 15 lines in your changes missing coverage. Please review.

Project coverage is 85.79%. Comparing base (67213c9) to head (257b94b).
Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3335      +/-   ##
==========================================
+ Coverage   85.66%   85.79%   +0.13%     
==========================================
  Files          57       55       -2     
  Lines        6180     6175       -5     
==========================================
+ Hits         5294     5298       +4     
+ Misses        886      877       -9     
Flag Coverage Δ
python 85.79% <68.08%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
python_api 85.79% <68.08%> (+0.13%) ⬆️
libtiledbsoma ∅ <ø> (∅)
---- 🚨 Try these New Features:

Copy link
Member

@bkmartinjr bkmartinjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of issues:

  1. The PR is missing the tiledb_ctx property that was present in the API. This is the first point mentioned in the bug report. Previously it was possible to do the following:
context = soma.SOMATileDBContext()
A = tiledb.open(uri, ctx=context.tiledb_ctx)

We did deprecate this property in 1.14.5, so removing it is fair game. I'm just unsure what decision @aaronwolen took - the bug report suggests that he wanted to add both back, but I may be misreading it.

Recommend checking with him to confirm removal.

  1. There are some minor style/pattern comments inline.

Comment on lines 73 to 83
tiledb_config: Dict[str, Union[str, float]] | None = None,
tiledb_ctx: "tiledb.Ctx" | None = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
tiledb_config: Dict[str, Union[str, float]] | None = None,
tiledb_ctx: "tiledb.Ctx" | None = None,
tiledb_config: Dict[str, Union[str, float]] | "tiledb.Ctx" | None = None,

I would slightly prefer this. Admittedly passing a context to the tiledb_config doesn't sound very good, but it eliminates the error case of passing both a context and a config. You could take a leap and say that a context is part of the "configuration".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did considering having tiledb_config also take in a tiledb.Ctx but decided to revert back to how we previously had it as separate arguments. But I'm open to further discussion about only having a tiledb_config argument now.

@nguyenv nguyenv force-pushed the viviannguyen/optionally-use-tiledb-ctx branch from c484029 to 17ce213 Compare November 20, 2024 23:15
# it should be impossible to enter into this block because
# we already check that in the constructor
assert tiledb is not None
cfg = self._tiledb_ctx().config().dict()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think _tiledb_ctx is a method, so I suspect this should drop the parens, e.g.,

cfg = self._tiledb_ctx.config().dict()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ps. assuming my comment is correct, does this imply a missing test case? (or my comment is wrong!)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right that there should not be parens.

The missing test case brings up a another issue though. We have removed all tiledb-py usage from the unit tests. But should we temporarily re-introduce it for testing with tiledb.Ctx()? We would xskip the test if tiledb is not installed locally. But then do we need to install tiledb for CI runs? (cc @johnkerl)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, tough one. I don't see any great solution - options?

The best I can come up with is:

  1. Code the tests to work both with and without the package installed:
    • if installed, test that it works as expected
    • if not installed, test that it generates the right error
  2. Have two CI's: one with it installed, one with it not installed

That at least mimics real-world conditions.

@@ -19,16 +19,30 @@
from .._types import OpenTimestamp
from .._util import ms_to_datetime, to_timestamp_ms

if TYPE_CHECKING:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not need this as all the type signatures are quoted.

Also, given that tiledb is no longer a dependency, shouldn't this fail in CI (I wonder why it did not fail?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually fails CI if this block is not included.

apis/python/src/tiledbsoma/options/_soma_tiledb_context.py:81: in __init__
    tiledb_ctx: "tiledb.Ctx" | None = None,
E   AttributeError: 'NoneType' object has no attribute 'Ctx'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had assumed if the modules included in TYPE_CHECKING are not found, then it treats the quoted types as string literals instead of types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It treats them as string literals for sure, but I don't think it has anything to do with whether the module is found. TYPE_CHECKING is a constant that mypy sets to true, and is false during actual "use" of the code.

Easiest solution is to probably just do: from tiledb import Ctx and use "Ctx" rather than "tiledb.Ctx".

Sorry this is such a PITA!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ended up being more complicated than expected, but I think I have something that works now.

Copy link
Member

@bkmartinjr bkmartinjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of minor suggestions/issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants