Define non-throwing type conversion behavior for invalid values
Open
@zaleslaw is already working on this.
Since Mar 26, 2026.
API
question
- Dominant language
- Kotlin
- Stars
- 1.1k
- Forks
- 83
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 30
Description
Hi,
when trying to convert values like String to Double and there is an invalid value, an error is thrown. Maybe change this behaviour to convert invalid values to NA or null, or add functions that have different behaviours like toDoubleOrNull() or toDoubleOrNa().
Thanks!
Problem
Current type conversion throws when encountering invalid values (e.g. String → Double).
In real datasets, invalid values are common, and users often need to:
- convert valid values
- handle invalid ones gracefully (e.g. as
null)
Design question
What should be the standard non-throwing behavior for conversions?
Options:
- provide
toXOrNull()style APIs - provide configurable conversion mode (throw vs null/NA)
- keep only explicit APIs without changing defaults
Expected
Define a consistent approach for non-throwing conversions.
Acceptance criteria
- Decision made on API design for non-throwing conversions
- Chosen approach is:
- implemented, or
- explicitly rejected and documented
- Behavior for invalid values is clearly defined
- Documentation explains available conversion modes
Motivation
Type conversion is a core data-cleaning operation.
Without a defined approach, users must implement custom parsing logic, leading to inconsistent usage.
This behavior should be clearly defined before 1.0 API stabilization.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.