Skip to content
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

Implement promotion rules for CategoricalArray #384

Merged
merged 1 commit into from
Mar 13, 2022
Merged

Conversation

nalimilan
Copy link
Member

These are rarely needed, but an exception is when storing CategoricalArray objects within arrays, as the [a1, a2] syntax uses promotion to choose the element type of the result. This previously failed as it hit a fallback promote_result method defined for AbstractArray in Base in range.jl, which tried to convert CategoricalArrays to Array by calling nonexistent convert methods for CategoricalValue.

Fixes #383.

These are rarely needed, but an exception is when storing `CategoricalArray`
objects within arrays, as the `[a1, a2]` syntax uses promotion to choose
the element type of the result. This previously failed as it hit a fallback
`promote_result` method defined for `AbstractArray` in Base in range.jl,
which tried to convert `CategoricalArray`s to `Array` by calling nonexistent
`convert` methods for `CategoricalValue`.
@bkamins
Copy link
Member

bkamins commented Mar 11, 2022

Looks good, but some other tests now started to fail.

@nalimilan nalimilan merged commit 3f1e4bc into master Mar 13, 2022
@nalimilan nalimilan deleted the nl/promotion branch March 13, 2022 10:01
@nalimilan
Copy link
Member Author

nalimilan commented Mar 13, 2022

Failures are fixed by #385, though we'll probably need more promotion rules to handle better the combination of CategoricalArray and views thereof (#386). In the meantime I've tagged a new release: JuliaRegistries/General#56513

@bkamins
Copy link
Member

bkamins commented Mar 13, 2022

Thank you!

nalimilan added a commit that referenced this pull request Mar 16, 2022
PR #384 added promotion rules that recursively promote the
eltype and reftype, but this has the drawback that the resulting
type is often not a supertype of the input types, forcing a conversion
to a `CategoricalArray` which may have a `Union` type.
Instead, do the same as `Array` and `AbstractArray` fallbacks, which
simply call `promote_typejoin` if eltypes do not match.
nalimilan added a commit that referenced this pull request Mar 17, 2022
PR #384 added promotion rules that recursively promote the
eltype and reftype, but this has the drawback that the resulting
type is often not a supertype of the input types, forcing a conversion
to a `CategoricalArray` which may have a `Union` type.
Instead, do the same as `Array` and `AbstractArray` fallbacks, which
simply call `promote_typejoin` if eltypes do not match.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conversion issue on nightly
2 participants