-
Notifications
You must be signed in to change notification settings - Fork 41
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
TryFrom<Robj> for Int, Logical, Real #258
TryFrom<Robj> for Int, Logical, Real #258
Conversation
Not sure how this relates to #251 after most recent conversations. We need to figure out some coherent approach to handling numeric vectors that does appropriate type conversions and checking, like we are doing with scalars. |
Do you mean #252, which this closes? Or is the suggestion that the NA handling issue should be addressed before this one?
Agreed. I see this PR as plugging a hole for now as with #247, using the behavior of similar implementations. But of course it should be changed as part of a move to better conversions in general. |
I meant #251, and specifically, I meant we need to have a coherent framework of how these things should work before continuing to implement. @Ilia-Kosenkov suggested we should write a whitepaper outlining our data conversion model. This suggestion is on discord. I'll file an issue now here. |
See #259. |
Yeah, I thought the same at the time of adding "good first issue" label. Sorry for the confusion... |
How about something like the following. Instead of this conversion: robj.as_integer_iter()
.ok_or_else(|| Error::ExpectedInteger(robj)) could we implement something like this: if let Ok(v) = robj.as_integer_iter() {
Ok(v)
} else {
let rreal = robj.as_real_iter().ok_or_else(|| Error::ExpectedReal(robj))
let rint = Int::from_real(rreal);
Ok(rint)
} where |
We could implement a "Cow" for numeric types. A So So |
I may re-work Int, Logical and Real to be just Robj wrappers and pull We can implement GET_REGION for ALTREP objects which |
But essentially, the logic will be the same. |
I'm happy to approve this for now if @clauswilke is ok so that @brendanrbrown gets a contribution. We can either implement |
Before merging, can we at least stub out an alternative path for now so we have a marker in the code that this isn't completed? Something like so maybe? if let Ok(v) = robj.as_integer_iter() {
Ok(v)
} else {
// TODO: check if robj is another type (e.g. Real) that can be converted
// into integer, and do the conversion
Error::ExpectedInteger(robj)
} Also, @andy-thomason, I'd suggest we wait with reworking how |
I added the todo comment for possible merging, should that be what makes sense here.
Yes, this seems reasonable, would not be difficult, and would be a step closer to being consistent (probably) with whatever future coherent conversion scheme, based on the conversation. If having it would make this hole-patching PR a better fit, I would be glad to add it.
@andy-thomason: thanks for the thoughtfulness. |
Don't understand the CI failure here. Since the most recent passing tests I only moved text, but the isn't cargo-fmt related. Someone who knows more able to shed some light? |
It may be a probabilistic failure (i.e., works most of the time but breaks sometimes, randomly). I'll restart the tests to see if that fixes it. |
If you don't mind I'd appreciate it. We could also break it into two separate PRs though. I have a few more documentation requests, though:
Thanks! |
@clauswilke My preference would be to address the additional conversions, e.g. using an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Any idea why the one test is failing?
It was the same failure as the previous case, in one of the windows builds, which appears inconsistently. I'm not quite sure what to make of it. |
Thanks! |
Closes #252