ibis: bug: Incomplete type hints
What happened?
While evaluating Ibis at work, I found some unexpected mypy errors:
import ibis
import ibis.selectors as s
from ibis import deferred as d_
table = ibis.table({"col1": "int"})
# error: Argument 1 to "order_by" of "Table" has incompatible type "Value"; expected "str | Column | tuple[str | Column, bool] | Sequence[str] | Sequence[Column] | Sequence[tuple[str | Column, bool]] | None" [arg-type]
table.order_by(ibis.desc("col1"))
# error: Argument 1 to "mutate" of "Table" has incompatible type "Across"; expected "Sequence[Expr] | None" [arg-type]
table.mutate(s.across(["col1"], d_.mean()))
# error: Argument "col1_again" to "mutate" of "Table" has incompatible type "Deferred"; expected "Value" [arg-type]
table.mutate(col1_again=d_["col1"])
I’ll keep adding to this issue in case I’d find more. Also, a big thank you for making Ibis a typed library! 😃
What version of ibis are you using?
Ibis 6.1 Mypy 1.4.0 Python 3.11
What backend(s) are you using, if any?
No response
Relevant log output
No response
Code of Conduct
- I agree to follow this project’s Code of Conduct
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 17 (17 by maintainers)
I can relate to that. It’s the same story for Vega-Altair where I’m currently in the process of typing at least the public API and it’s not easy…
I think the issue title I chose is misleading. Mypy allows for gradually typing existing codebases and so it’s fine if Ibis is not completely typed. Issues arise when the provided type hints are either wrong (e.g. specified types on function input arguments cannot be processed by function) or incomplete (e.g. a union of types does not cover all accepted types) where the later one seems to be the case for the 3 errors I mentioned above.
The process which we follow for Altair and what I’ve seen with other libraries is that
py.typedfile to tell type checkers such as mypy that the type hints can be used for type checking in other code bases.By introducing the
py.typedfile in #5304 without having mypy enabled, these errors now show up in other code bases but not yours and users will have to add# type: ignorecomments to get mypy to pass.Based on #2823 and the related PRs, I take it that it’s not easy to fix all existing mypy issues. For what it’s worth, I think you could either remove again the
py.typedfile so that other code bases are not affected, or introduce mypy for checking and get it to pass. You could remove type hints in the parts of the code which are tricky (or usetyping.Any) so that mypy does not check them.Running
mypy ibis --ignore-missing-importsafterpip install -e .gives me 130 individual errors but many of them have the same root causes.Hopefully this isn’t a blocker for you, but let us know!