feat(datatypes): support ibis.dtype(nullable=None) #11694
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.