-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Try coerce ordered in vec_rbind0()
#5139
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
Conversation
R/utilities.r
Outdated
I(msg), | ||
details = desc | ||
) | ||
if (inherits(cnd, "vctrs_error_ptype2")) { |
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.
Can you explain about the reasoning for this guard? Why is it suddenly necessary?
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.
This was more out of practicality than necessity. Without this, combining two ordered factors would throw 2 warnings, once during vec_ptype2()
and once during vec_cast()
. I don't know if there is a situation where vec_cast()
should warn whereas vec_ptype2()
shouldn't. See also here: #5109 (comment)
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.
hmm... maybe keep track of whether the input is two ordered vectors and only in that case have the guard...
Maybe it is overdoing it but since I can't figure out the repercussions I'd rather be on the safe side
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.
I too feel uncomfortable about this guard, so I'm glad you're thinking along. I think the order of events is as follows:
vec_ptype2(x, y)
searches for a common, finalised class to coercex
andy
to. Let's call that finalised classw
.vec_cast(x, w)
coercesx
tow
.vec_cast(y, w)
coercesy
tow
So if x
and y
are ordered factors, w
will be a factor. The case where we only have two ordered factors is step (1). So, step (2) and (3) will still emit a warning about converting ordered to factors. The ideal situation would be to emit a warning at (1) and then silence (2) and (3). However, the 'track whether x and y are both ordered factors'-rule can't be applied in (2) and (3) because w
is a regular factor.
I'll puzzle around a bit more to see what might be done, but it'll probably become more complicated than just tracking ordered factors.
Alright, should be safer now, though it has become a little bit more complex than I'd hoped for. |
hmm... I must admit I'm now closer to just accepting a double warning rather than complicating the restart handler in this way - it feels like dangerous over-engineering for a situation that arrises so infrequently. Thoughts? |
Yeah I agree with you that this might be over-complicated for little practical purposes other than displaying a slightly more comprehensible set of warnings. Also, these are lifecycle warnings, so they're only displayed once every 8 hours under default settings. The important bit is turning the original error into a warning so that the plot in #5109 at least renders (which is an easy fix). If the warnings become a pertinent problem, which seems unlikely, we could always decide to fix these at some later point. |
Agreed - let's roll back to simply avoiding the error |
Alright, I've reverted everything but the error avoidance |
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.
LGTM
But please add a unit test and NEWS bullet |
This PR aims to fix #5109
Briefly, it tries to cast two ordered factors to plain factors (which can be combined in vctrs). This used to throw an error when in facetted plots, you set two ordered factors as facetting variables. This now becomes a warning.
I'd really appreciate a second pair of eyes here, as I'm still somewhat confused about the order of events in trying to restart upon errors. The thing that makes me a bit uncomfortable, is that with this PR, we're only throwing warnings on
vec_ptype2()
errors, and no longer onvec_cast()
errors (this should just throw the usual vctrs error, I think). I don't know if we're missing an important case when the warning should be thrown invec_cast()
.To quickly recap, you weren't allowed to combine two ordered factors with incompatible levels, even though we should be able to. You also aren't allowed to combine factors and dates, which should be the case.
With this PR, you no longer get an error by combining two incompatible ordered factors, but you do get a warning and the correct result. Combining dates and factors is still prohibited.
Created on 2023-01-07 with reprex v2.0.2