Skip to content

Conversation

@NickCrews
Copy link
Contributor

@NickCrews NickCrews commented Oct 16, 2025

This removes the footgun where currently ibis.dtype("!int64", nullable=True) results in a non-nullable dtype. Besides that, this shouldn't affect users at all.

This also removes the slightly smaller footgun where ibis.dtype(existing_dtype) would always return a nullable version. I think it is preferable for this to be a no-op (return the original dtype unchanged), and only to adjust the nullability if it is explicitly provided.

This also sets us up to work with any future type systems that have an inherent sense of nullability. All the ones we currently support (numpy, pandas, arrow, and polars) do not keep track of nullability, so this doesn't do much there. This might not be much of a reason to do this. IF you want, we could limit the changes just to the top-level dtype() function, and not adjust the TypeMapper.to_ibis() signature, but I thought I might as well make everything consistent, its a tiny bit more code but not much.

Finally, this adds a lot more examples to the docstring for dtype() so that users get a taste of the string DSL.

This was inspired by #11607, and would help reduce the scope of that PR.

@github-actions github-actions bot added tests Issues or PRs related to tests datatypes Issues relating to ibis's datatypes (under `ibis.expr.datatypes`) labels Oct 16, 2025

@classmethod
def from_string(cls, text: str, nullable: bool = True) -> DataType:
def from_string(cls, text: str, nullable: bool | None = None) -> DataType:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The subclasses SqlglotType and PostgresType already use this signature. So this is more of a bugfix to bring this ABC into compliance with how we actually are using them.

@NickCrews NickCrews force-pushed the accept-nullable-none-in-dtype branch from 4d479aa to 331595c Compare October 16, 2025 22:14
nullable = True
if pa.types.is_null(typ):
return dt.null
return dt.null(nullable=nullable)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, I guess this is a tiny behavior change. Before, ibis.dtype(pa.null(), False) would still give dt.Null(nullable=True). Now it correctly gives dt.Null(nullable=False)

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

Labels

datatypes Issues relating to ibis's datatypes (under `ibis.expr.datatypes`) tests Issues or PRs related to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant