-
Notifications
You must be signed in to change notification settings - Fork 33
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
replace
does not respect target type
#352
Comments
I was thinking about it when I answered on SO and concluded that the design of
Which implies that the container type of returned value should be the same as if we did a copy (optionally doing type promotion). I think that the crucial point of The operation requested on SO assumes we are doing mapping of all values. I think it is a valid use case but intuitively I would expect a different function for it (that would in particular check that a full mapping specification is provided). But maybe it would be not that useful. Not sure. Maybe it would be enough to add a kwarg to |
The part of the docstring (which I wrote IIRC!) that I was worried about is:
Clearly we don't respect this currently. But it's not easy to respect.
That wouldn't fix the inconsistency with the docstring, but yeah that could be useful. In particular that would allow the reverse choice, i.e. request a |
I agree that meeting the contract is hard, that is why I thought of adding a kwarg that would allow to choose from one of possible intentions of the user. Also having a kwarg will make it easier for users to notice that there is a choice (and an issue, as I think many users could overlook the problem). |
Currently
replace
callsrecode
and always returns aCategoricalArray
, even if the target values are notCategoricalValue
s. This is OK forrecode
as it's specific to CategoricalArrays, but ideallyreplace
should respect the target type. Unfortunately, the behavior ofreplace
on arrays is to callpromote_type
on the source element type and on target values' types. This would give weird arrays such asArray{Union{CategoricalValue{String,UInt32}, Int}}
. We could use a different approach which would choose the element type based on the actual values, likebroadcast
. But that would trade an inconsistency with Base for another inconsistency.For example, the following should ideally return a
Vector{Int}
(see this thread):Cc: @bkamins
The text was updated successfully, but these errors were encountered: